Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
BIG question need help, PHP news script
Old 08-13-2009, 03:16 AM BIG question need help, PHP news script
k3exige's Avatar
Average Talker

Posts: 17
Trades: 0
First off, this is a big question, second off, if you recommend using a different script, please enlighten me. Otherwise, help me out.

Alright, so what's wrong with this edit.php? I don't know any PHP really so ending this string seems to be a big issue. Once I get this fixed I'll post it in my tutorials section. All help greatly appreciated. The error's at line 86, basically one of the last lines, where it seems the code is just cut off.

Code:
<?php
//The following PHP script allows you to edit the
//contents of your MySQL table.
//Connecting to the MySQL database
require('dbconnect.php');

//Should we show a single item or a list?
if($_POST['edit']) {
//Simplifying the variables.

$id = $_POST['id'];
$title = $_POST['title'];
$author = $_POST['author'];
$date = $_POST['date'];
//trim() strips white space from the beginning and end of a line.
$date = trim($date);

$content = $_POST['content'];

//Checks for empty fields or invalid date.
if((empty($title)) OR (empty($author)) OR (empty($date)) OR (empty($content))) {
echo "<center><strong>Please fill in all fields!</strong></center>
";

} else {
//explode() separates the date by the '/' character and outputs it to an array.
$explode_date = explode('/', $date);
//checkdate() returns FALSE if the date is invalid.
$check_date = checkdate($explode_date[0], $explode_date[1], $explode_date[2]);
if($check_date == false) {

echo "<center><strong>Invalid date entered!</strong></center>
";
} else {
//htmlspecialchars() converts special characters into HTML entities.
$title = htmlspecialchars($title);
$author = htmlspecialchars($author);


//The MySQL query which will update the content in the table.
$query = "UPDATE news SET title = '$title', author = '$author', date = '$date', content = '$content' WHERE ID = '$id'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "<center><strong>News item modified!</strong></center>";

}
}
} elseif($_GET['action'] == "edit") {
//Display a single result.
$id = $_GET['id'];
//The MySQL query. Select all from the table news where the ID equals the id sent in URL.

$query = "SELECT * FROM news WHERE ID='$id'";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
?>
<form method="post" action="edit.php">
<div id="newsform">
<div id="newsedit">Title: <input type="text" size="34" name="title" value="<?php echo "$title"; ?>" maxlength="250" /></div>
<div id="newsedit">Author: <input type="text" size="34" name="author" value="<?php echo "$author"; ?>" maxlength="250" /></div>
<div id="newsedit">Date: <input type="text" size="34" name="date" value="<?php echo "$date"; ?>" maxlength="10" /></div>
<div id="newsedit">Content: <textarea name="content" cols="26" rows="10"><?php echo "$content"; ?></textarea></div>

<div id="newsedit"><input type="hidden" name="id" value="<?php echo "$ID"; ?>" /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" /></div>
</div>
</form>
<?
}
} else {
//Since we're not displaying a single result,
//we're going to display a list of results.

//The MySQl query. Selects all from the table news.
$query = "SELECT * FROM news ORDER BY ID DESC";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
echo "<table><tr><td><strong><a href="edit.php?action=edit&id=$ID">$title</a></strong></td></tr>
<tr><td><small>Written by $author on $date</small></td></tr>

<div id="newsedit"><a href="delete.php?id=$ID">DELETE</a></div>"
k3exige is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-13-2009, 03:20 AM Re: BIG question need help, PHP news script
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Can you mark which line is line 86? it looks like the last line is missing a semicolon. What error message are you getting?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 08-13-2009 at 03:21 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-13-2009, 04:17 AM Re: BIG question need help, PHP news script
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
The last line, as Matt pointed out, is missing a semicolon but also escapes of the quotes. You echo a string like so

echo "your string here";

When you are using quotes withing the string (as in id="newsedit" or href="edit.php") you need to escape them, or it will be interpreted as the end of the string.

So, change any occurance of quotes as in id="newsedit" into id=\"newsedit\", and add that semicolon at the end of the row.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-13-2009, 04:26 AM Re: BIG question need help, PHP news script
Junior Talker

Posts: 2
Name: Lenovo
Trades: 0
I was having this same problem until today. I thought that was the issue, then I found this post - sure enough it works now.
comparatif simulation taux credit auto - Taux crédit auto. Comparatif des offres! Les meilleurs taux crédit auto sont sur le net !comparatif simulation taux credit auto
Lenovo is offline
Reply With Quote
View Public Profile
 
Old 08-13-2009, 11:15 AM Re: BIG question need help, PHP news script
k3exige's Avatar
Average Talker

Posts: 17
Trades: 0
Oh alright I understand that now, thanks. It stil says:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/exige/public_html/extempus/admin/edit.php on line 87

When I include edit.php. 87 is the last line. I changed those final lines to:
Code:
echo "<h2><span class=\"title2\"><strong><a href=\"edit.php?action=edit&id=$ID\">$title</a></strong></span>
<span class="date">Written by $author on $date</span></h2>

<div id=\"newsedit2\"><a href=\"delete.php?id=$ID\">DELETE</a></div>";
Again I don't really know PHP but from what you've told me I must be missing something. Thanks.
k3exige is offline
Reply With Quote
View Public Profile
 
Old 08-13-2009, 11:17 AM Re: BIG question need help, PHP news script
k3exige's Avatar
Average Talker

Posts: 17
Trades: 0
Nevermind, ha found it thanks, span class date. The simple things... but it still says parse error unexpected $end line 89.
k3exige is offline
Reply With Quote
View Public Profile
 
Old 08-13-2009, 12:25 PM Re: BIG question need help, PHP news script
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Then would you please show us that line aswell? :P
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-13-2009, 02:11 PM Re: BIG question need help, PHP news script
k3exige's Avatar
Average Talker

Posts: 17
Trades: 0
Oh, it's up there, sorry forgot to mention. That's 89 at the very end.
k3exige is offline
Reply With Quote
View Public Profile
 
Old 08-13-2009, 02:31 PM Re: BIG question need help, PHP news script
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Unexpected $end means that it reached the end of the file before it expected to. You still have a while loop that hasn't ended and possibly an if.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-13-2009, 03:13 PM Re: BIG question need help, PHP news script
k3exige's Avatar
Average Talker

Posts: 17
Trades: 0
oh alright. I'll figure out how to end those. I got this script from here if you'd like to check it out for yourself. But I'm to exercise to I'll be back to check around 6 pm EST
k3exige is offline
Reply With Quote
View Public Profile
 
Old 08-13-2009, 04:46 PM Re: BIG question need help, PHP news script
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by k3exige View Post
oh alright. I'll figure out how to end those. I got this script from here if you'd like to check it out for yourself. But I'm to exercise to I'll be back to check around 6 pm EST
It looks to me like you didn't copy the entire script.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-14-2009, 12:03 AM Re: BIG question need help, PHP news script
k3exige's Avatar
Average Talker

Posts: 17
Trades: 0
I did. Edit.php on that site still doesn't have those closing brackets you mentioned. A PHP friend of mine fixed it for me after work and it works well and thanks for all the help. Here's the final script if you wanted to compare, somethings changed around by him.

Code:
<?php
require('dbconnect.php');


if($_POST['edit']) {

  $id = $_POST['id'];
  $title = $_POST['title'];
  $author = $_POST['author'];
  $date = $_POST['date'];

  $date = trim($date);

  $content = $_POST['content'];

  if((empty($title)) OR (empty($author)) OR (empty($date)) OR (empty($content))) {
    echo "<center><strong>Please fill in all fields!</strong></center>";
  } else {
    $explode_date = explode('/', $date);
    $check_date = checkdate($explode_date[0], $explode_date[1], $explode_date[2]);
    if($check_date == false) {
      echo "<center><strong>Invalid date entered!</strong></center>";
    }else{
      $title = htmlspecialchars($title);
      $author = htmlspecialchars($author);
      $query = "UPDATE news SET title = '$title', author = '$author', date = '$date', content = '$content' WHERE ID = '$id'";
      $result = mysql_query($query) or die(mysql_error());
      echo "<center><strong>News item modified!</strong></center>";
    }
  }
} elseif($_GET['action'] == "edit") {
  $id = $_GET['id'];

  $query = "SELECT * FROM news WHERE ID='$id'";
  $result = mysql_query($query) or die(mysql_error());
  while ($row = mysql_fetch_array($result)) {
    extract($row);
    ?>
    <div id="newsform">
    <form method="post" action="edit.php">
    Title: <input type="text" size="34" name="title" value="<?php echo "$title"; ?>" maxlength="250" />
    Author: <input type="text" size="34" name="author" value="<?php echo "$author"; ?>" maxlength="250" />
    Date: <input type="text" size="34" name="date" value="<?php echo "$date"; ?>" maxlength="10" />
    Content: <textarea name="content" cols="26" rows="10"><?php echo "$content"; ?></textarea>
    <input type="hidden" name="id" value="<?php echo "$id"; ?>" /><input type="submit" name="edit" value="Modify" />
      <input type="reset" name="reset" value="Reset" />
    </form>
 <?
  }
} else {

  $query = "SELECT * FROM news ORDER BY ID DESC";
  $result = mysql_query($query) or die(mysql_error());
  while ($row = mysql_fetch_array($result)) {

  extract($row);
  echo "<h2><span class=\"title2\"><strong><a href=\"edit.php?action=edit&id=$ID\">$title</a></strong></span>
  <span class=\"date\">Written by $author on $date</span></h2>

  <div id=\"newsedit2\"><a href=\"delete.php?id=$ID\">DELETE</a></div>";
  }
}
?>
k3exige is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to BIG question need help, PHP news script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45304 seconds with 12 queries