Forum Moderators: coopster
<?php
$connect = mysql_connect("***********************") or die ("Couldn't connect");
mysql_select_db("********************") or die ("Couldn't Find DB");
$id = $_GET['id'];
if ($id)
$edits = mysql_query("SELECT * FROM ads WHERE id='$id'");
while($row = mysql_fetch_assoc($edits))
{
$title = $row['title'];
$category = $row['category'];
$ads = $row['ads'];
$location = $row['location'];
$body = $row['body'];
$contact = $row['contact'];
$email = $row['email'];
$telephone = $row['telephone'];
$date = $row['date'];
$author = $row['author'];
}
?>
<?php
If ($_POST['post'])
{
$title = $_POST['title'];
$category = $_POST['category'];
$ads = $_POST['ads'];
$location = $_POST['location'];
$body = $_POST['body'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$end = date("Y-m-d", mktime(0,0,0,$month,$day,2009));
$date = $_POST['date'];
$day = $_POST['day'];
$month = $_POST['month'];
$author = $_POST['author'];
if ($title&&$category&&$ads&&$location&&$body&&$contact&&$email&&$end)
{
mysql_connect("**********************") or die (mysql_error());
mysql_select_db("**************") or die (mysql_error());
$date = date("Y-m-d");
$end = date("Y-m-d", mktime(0,0,0,$month,$day,2009));
$day = $_POST['day'];
$month = $_POST['month'];
$author = $_SESSION['username'];
$id = $_GET['id'];
$insertedit = mysql_query("UPDATE INTO ads SET WHERE `id`='$id' ('', '$title','$category','$ads','$location','$body','$contact','$email','$telephone','$end','$date','$author')") or die(mysql_error());
die("WOW! Wasn't that Easy!");
}
else
echo "Please complete all fields<p>";
}
?>
My form is underneath here and within it i am echoing out the original post back into the various fields (such as title,body etc) so they can be edited. As i said this was working fine, until i tried to post the edited version back to my DB. But now i get a T_LOGICAL_OR error at line 66 which is my while($row = mysql_fetch_assoc($edits))statement.
Thank you
mysql_blah_blah(...) or die (...);
It's common to get a "syntax error, unexpected T_LOGICAL_OR" if you have a semi-colon before the "or die" part, e.g.:
mysql_blah_blah(...); or die (...);
There might also be some strange hex character that's invisible in your text editor. So check your code 1-2 lines up and down from the line number in the error message.
If you still can't find anything, post the full text of the error message, it'll make it easier to analyze the problem.
Hope this helps. [a moderator will soon be along to welcome you to this board :-)]
<?php
/* make sure there is an ID set */
if(!isset($_GET['id']))
{
echo 'You need specify an ID to view this page.';
exit;
} else {
$id = (int)$_GET['id'];
}
/* only need to connect once, here */
$connect = mysql_connect("***********************") or die ("Couldn't connect");
mysql_select_db("********************") or die ("Couldn't Find DB");
/*
* If we need to show the edit form
* example URL: http:www.example.com/edit.php?op=edit&id=123
*/
if(isset($_GET['op']) && $_GET['op'] == 'edit')
{
$edits = mysql_query("SELECT * FROM ads WHERE id='$id'");/* This takes the array index and makes it a variable ie ($row['example'] --> $example) */
extract(mysql_fetch_assoc($edits), EXTR_OVERWRITE);
}
else if(isset($_POST['submit_edit']))
{
/* the fields you want to check */
$check_fields = array(
'title',
'category',
'ads',
'location',
'body',
'contact',
'email',
'telephone',
'date',
'day',
'month',
'author'
);
$missing_fields = array();
foreach($check_fields AS $field)
{
if(isset($_POST[$field]))
{
if(empty($_POST[$field]))
{
$missing_fields[] = $field;
}
} else {
$missing_fields[] = $field;
}
}
/* if there are missing fields, print them */
if(count($missing_fields) > 0)
{
echo 'Missing the following fields: ' . implode(',', $missing_fields);
}
/* otherwise update the database table */
else
{
$title = $_POST['title'];
$category = $_POST['category'];
$ads = $_POST['ads'];
$location = $_POST['location'];
$body = $_POST['body'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$date = $_POST['date'];
$day = $_POST['day'];
$month = $_POST['month'];
$author = $_POST['author'];
$end = date("Y-m-d", mktime(0, 0, 0, $month, $day, 2009));
$author = $_SESSION['username'];
$query = "
UPDATE ads
SET
`title` = '$title',
`category` = '$category',
`ads` = '$ads',
`location` = '$location',
`body` = '$body',
`contact` = '$contact',
`email` = '$email',
`telephone` = '$telephone',
`end` = '$end',
`date` = '$date',
`author` = '$author'
WHERE `id` = '$id'
";
/* make update */
$insertedit = mysql_query($query) or die(mysql_error());
/* see if it worked */
if($insertedit)
{
echo 'Update was successful.';
} else {
echo 'Update failed.';
}
}
?>
I hope that gets you further into your learning process. Make sure to look up any functions you don't understand at [php.net...] and let us know if you are still having issues with this new script. I have no actually tested it so try it out and see where it brings you.
So Welcome to WebmasterWorld and good luck! :)