mysql problem
#1
Posted 25 July 2008 - 12:51 AM
#2
Posted 25 July 2008 - 12:59 AM
Ive tested this on almost all php and mysql versions, and when i try to update my news in the database it goes through like it worked, but the news wont be updated! Its got me confused to no end. Ive checked over my code so much my eyes burn and I cant find any error! I can post news, but when it comes to editing and deleting forget it!
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
#8
Posted 25 July 2008 - 01:29 AM
everything is secured with my secure function, and all the other code is working. i just need it to update, ive never had this problem before!
OK. well then copy and paste the mysql stuff I provided...
#9
Posted 25 July 2008 - 01:36 AM
#10
Posted 25 July 2008 - 01:40 AM
tried it and still its not updating the mysql database
bummer well idk.
mysql_query("UPDATE `news` SET `title` = ".$title." , `body` = ".$body." WHERE `id` = ".$id." LIMIT 1") or die(mysql_error());
try that...
#11
Posted 25 July 2008 - 01:44 AM
#12
Posted 25 July 2008 - 01:49 AM
sad to say, that isnt working either lol, i might have to recode this from the beginning and maybe i might catch something
get ahold of me via email or msn.. maybe I can help you out some way... my msn detail is on my profile.
#13
Posted 25 July 2008 - 12:16 PM
Storing the result of the query isn't the problem. It doesn't hurt to do so, but in this case i would agree that it is a waste of space.I see what your problem is.... Get rid of the $edit_news = and just use the mysql_query() copy & paste my code:
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.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users