Jump to content


Photo

Update query appears fine but doesn't work


  • Please log in to reply
5 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 04 October 2006 - 06:50 PM

The problem I'm having is it isn't updating the database, I echod the SQL and it looks fine, yet it isn't working.

Here is the code:

<?php
$userid = $_GET['user'];
$page_id = $_GET['page_id'];

require_once("sec_con.php");

if(isset($userid)){
$title = $_POST['title'];
$row['page_id'] = $_POST['page_id'];
$row['description'] = $_POST['description'];
$row['content'] = $_POST['content'];

mysql_select_db("style");

$sql = "UPDATE pages
 SET title='$title',
  page_id='$page_id',
   description='$description',
    content='$content',
	   WHERE user_id = '".$userid."', page_id = '".$page_id."' LIMIT 1";
mysql_query($sql);
echo $sql;
  echo "The selected information was updated! ";
  echo "<a href='secure/style.php?user=$userid'>Click here</a> to continue editing, or <a href='./index.php?user=$userid'>click here</a> to go back to your website.";
}
?>

~ Mutley.

#2 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 04 October 2006 - 07:07 PM

I ran the query in phpmyadmin, it said theirs an error in my SQL syntax on/near this line:
   WHERE user_id = '".$userid."', page_id = '".$page_id."' LIMIT 1";

~ Mutley.

#3 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 04 October 2006 - 07:08 PM

This line...

   WHERE user_id = '".$userid."', page_id = '".$page_id."' LIMIT 1";
----------------------------------------^

remove the * , *!

   WHERE user_id = '".$userid."' AND page_id = '".$page_id."' LIMIT 1";




me!

#4 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 04 October 2006 - 07:20 PM

That hasn't worked, still get same syntax error on same line.
~ Mutley.

#5 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 04 October 2006 - 08:16 PM

change the query to this....


$sql = "UPDATE pages SET title = '" . $title . "', page_id = '" . $page_id . "', description = '" . $description . "', content = '" . $content . "' WHERE user_id = '" . $userid . "' AND page_id = '" . $page_id . "' LIMIT 1";


me!



#6 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 12:54 AM

whouldn't it be where user_id = '$user_id' and ...

you need and instead of ,




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users