Jump to content


Photo

Problems updating the database


  • Please log in to reply
4 replies to this topic

#1 niza

niza
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 14 April 2006 - 07:04 PM

$connection = mysql_connect($host, $user,$password) 
or die ("Couldn't connect to server."); 
$db = mysql_select_db($database, $connection) 
or die ("Couldn't select database."); 
$sql = "UPDATE ad SET adName='$adName', adInfo='$adInfo', adPrice='$adPrice' WHERE adID='21'"; 
$result = mysql_query($sql) or die("Couldn't modify database."); 
mysql_close($connection);

This is the error I get: Couldn't modify database. Anyone knows what is happening and why I cannot update the database?

I checked all tables in the database for spelling mistakes and the variables. But I found no mistakes.


#2 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 14 April 2006 - 07:23 PM

Use this, the error then may be a bit more helpful than what you currently have.
$result = mysql_query($sql) or die(mysql_error());

Personal site: NewEnigma  |  Java and JSF Discussion

#3 niza

niza
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 14 April 2006 - 07:34 PM

I found the problem and I've fixed it. Now it updates the database but with nothing. I have no values in the database, only empty fields.

#4 niza

niza
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 14 April 2006 - 08:17 PM

Never mind. The variables were not being passes. I used this to get the variables:

$adName = $_POST['adName'];
$adInfo = $_POST['adInfo'];

And now it works.

Is there any way I can get the variables through a loop or something rather then manually give each variable a value?


#5 jcbarr

jcbarr
  • Members
  • PipPipPip
  • Advanced Member
  • 219 posts

Posted 14 April 2006 - 08:44 PM

The variables have to be passed to the page somehow.

Where are they coming from? If we can get a better understanding of this then we can help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users