Jump to content


Photo

mysql problem


  • Please log in to reply
17 replies to this topic

#1 GhostWX

GhostWX

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 25 July 2008 - 12:51 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!

#2 derek.sullivan

derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 343 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

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 GhostWX

GhostWX

    Young Padawan

  • Members
  • Pip
  • 7 posts

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 derek.sullivan

derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 343 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 25 July 2008 - 01:10 AM

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 */

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 GhostWX

GhostWX

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 25 July 2008 - 01:18 AM

i did that and still the same thing, itll go through with no errors but still doesnt update the data

#6 derek.sullivan

derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 343 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

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 GhostWX

GhostWX

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 25 July 2008 - 01:27 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!

#8 derek.sullivan

derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 343 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

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 GhostWX

GhostWX

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 25 July 2008 - 01:36 AM

tried it and still its not updating the mysql database

#10 derek.sullivan

derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 343 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

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 GhostWX

GhostWX

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 25 July 2008 - 01:44 AM

sad to say, that isnt working either lol, i might have to recode this from the beginning and maybe i might catch something

#12 derek.sullivan

derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 343 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

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 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 25 July 2008 - 12:16 PM

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 */

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.

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 derek.sullivan

derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 343 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 25 July 2008 - 12:20 PM

And in my defense I assumed he had the $id predefined.

#15 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 25 July 2008 - 12:23 PM

Never assume :D

Edited by rc69, 25 July 2008 - 12:23 PM.


#16 derek.sullivan

derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 343 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 25 July 2008 - 12:26 PM

Okay so in conclusion make sure you have your ID selected, as a matter of fact, in one of my previous post under your topic, i added the $id = htmlspecialchars($_GET['id']); so to say this wont work, may be on your part because I did say to copy that lol. but hopefully you'll get this figured out GhostWX

#17 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 25 July 2008 - 12:28 PM

Again, never assume.

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 GhostWX

GhostWX

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 25 July 2008 - 10:18 PM

you know let me double check that, i might not have defined it, its a hidden input.

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