BIG question need help, PHP news script
08-13-2009, 03:16 AM
|
BIG question need help, PHP news script
|
Posts: 17
|
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>"
|
|
|
|
08-13-2009, 03:20 AM
|
Re: BIG question need help, PHP news script
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Can you mark which line is line 86? it looks like the last line is missing a semicolon. What error message are you getting?
Last edited by NullPointer; 08-13-2009 at 03:21 AM..
|
|
|
|
08-13-2009, 04:17 AM
|
Re: BIG question need help, PHP news script
|
Posts: 807
Name: Mattias Nordahl
Location: Sweden
|
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.
|
|
|
|
08-13-2009, 04:26 AM
|
Re: BIG question need help, PHP news script
|
Posts: 2
Name: Lenovo
|
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
|
|
|
|
08-13-2009, 11:15 AM
|
Re: BIG question need help, PHP news script
|
Posts: 17
|
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.
|
|
|
|
08-13-2009, 11:17 AM
|
Re: BIG question need help, PHP news script
|
Posts: 17
|
Nevermind, ha found it thanks, span class date. The simple things... but it still says parse error unexpected $end line 89.
|
|
|
|
08-13-2009, 12:25 PM
|
Re: BIG question need help, PHP news script
|
Posts: 807
Name: Mattias Nordahl
Location: Sweden
|
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.
|
|
|
|
08-13-2009, 02:11 PM
|
Re: BIG question need help, PHP news script
|
Posts: 17
|
Oh, it's up there, sorry forgot to mention. That's 89 at the very end.
|
|
|
|
08-13-2009, 02:31 PM
|
Re: BIG question need help, PHP news script
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
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.
|
|
|
|
08-13-2009, 03:13 PM
|
Re: BIG question need help, PHP news script
|
Posts: 17
|
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
|
|
|
|
08-13-2009, 04:46 PM
|
Re: BIG question need help, PHP news script
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Quote:
Originally Posted by k3exige
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.
|
|
|
|
08-14-2009, 12:03 AM
|
Re: BIG question need help, PHP news script
|
Posts: 17
|
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>";
}
}
?>
|
|
|
|
|
« Reply to BIG question need help, PHP news script
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|