mysql problem
#1
Posted 25 July 2008 - 12:51 AM
#2
Posted 25 July 2008 - 12:59 AM
GhostWX, on Jul 25 2008, 01:51 AM, said:
Can you post your update code???
here is an example of an update code which could help:
<?php
/* add your variables here */
mysql_query("UPDATE `news` SET `article` = '$article' WHERE `art_id` = '$id'") or die(mysql_error());
/* always use or die(mysql_error()); */
?>
as for deleteing make sure you delete by the ID of the article, nothing else...
<?php
/* add your variables here */
mysql_query("DELETE FROM `news` WHERE `art_id` = '$id'") or die(mysql_error());
/* always use or die(mysql_error()); */
?>
hopefully that helped some..
As always, I refer to php.net for a list of mysql functions click php.net/mysql
#3
Posted 25 July 2008 - 01:02 AM
// Secure the input
$title = secure($_POST['new_title']);
$body = secure($_POST['new_body']);
// Make sure no fields aren't left blank!
if(!$title | !$body){
echo("<p>You must fill in all the forms!</p>");
} else {
// Edit news in the database
$edit_news = mysql_query("UPDATE news SET title='$title', body='$body' WHERE id='$id' LIMIT 1") or die(mysql_error());
header("Location: $site_url/admin_news.php");
} thats what i have, when i put single qoutes around everything like your example it gives an error!
#4
Posted 25 July 2008 - 01:10 AM
mysql_query("UPDATE `news` SET `title`= '$title' , `body` = '$body' WHERE `id` = '$id'") or die(mysql_error());
/* redirect goes here */
of course what I mean by this is paste this in the apropriate place lol
Edited by bigdfbc2008, 25 July 2008 - 01:12 AM.
#5
Posted 25 July 2008 - 01:18 AM
#6
Posted 25 July 2008 - 01:22 AM
<?php
if (isset($_POST['title'])) {
if (empty($_POST['title'])) {
echo "Title is empty";
exit;
}
if (empty($_POST['body'])) {
echo "Body is empty";
exit;
}
$title = trim($_POST['title']);
$body = trim($_POST['body']);
$id = htmlspecialchars($_GET['id']);
$query = "UPDATE `news` SET `title` = '$title' , `body` = '$body' WHERE `id` = '$id'";
mysql_query($query) or die(mysql_error());
}else{
/* form here */
}
?>
Try that, hopefully that'll work...
#7
Posted 25 July 2008 - 01:27 AM
#9
Posted 25 July 2008 - 01:36 AM
#11
Posted 25 July 2008 - 01:44 AM
#13
Posted 25 July 2008 - 12:16 PM
bigdfbc2008, on Jul 25 2008, 12:10 AM, said:
mysql_query("UPDATE `news` SET `title`= '$title' , `body` = '$body' WHERE `id` = '$id'") or die(mysql_error());
/* redirect goes here */The fact is, everything is working as it should. Nothing is being updated.
WHERE `id` = '$id'"The problem is right there. You never set $id anywhere. I am assuming you previously relied on register_globals to be on and have recently switch to a server in which it was turned off.
#14
Posted 25 July 2008 - 12:20 PM
#15
Posted 25 July 2008 - 12:23 PM
Edited by rc69, 25 July 2008 - 12:23 PM.
#16
Posted 25 July 2008 - 12:26 PM
#17
Posted 25 July 2008 - 12:28 PM
You had $_GET['id'] whereas he is using $_POST for everything else. It makes sense that the id could be in $_POST as well. Where he put it though is something we can't know, he didn't give us enough code to work with.
#18
Posted 25 July 2008 - 10:18 PM
yea it wasnt defined, just one of those little things you over look lol
Edited by GhostWX, 25 July 2008 - 10:23 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
