FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


mySQL Query Problem





jeremyyak
This is starting to bug the crap out of me Embarassed

Why won't this work?
Code:
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name) or die("Cannot connect to database");
mysql_query("UPDATE `affs` SET `inn`= '$in' WHERE `id`=$id LIMIT 1");
mysql_close($db);


All the variabels are set properly, its not giving me an error or anything.
Any ideas?
~Jeremy~
hexkid
As far as I can tell there is no reason for it not to work.
Maybe you only think All the variabels are set properly, its not giving me an error or anything, but in fact that is not true Wink

Try upping the error reporting of PHP and check the return value of every function you call.

Code:
error_reporting(E_ALL);
ini_set('display_errors', '1');

$db = mysql_connect($db_host,$db_user,$db_pass);

###
if (!$db) exit('Unable to connect. The error was: ' . mysql_error());

mysql_select_db($db_name) or die("Cannot connect to database");

###
$sql = "UPDATE `affs` SET `inn`= '$in' WHERE `id`=$id LIMIT 1";
if (!mysql_query($sql)) {
  exit('Error in query [<b>' . $sql . '</b>]. The error was: ' . mysql_error());
}
mysql_close($db) or die('Unable to close database connection.');
rohan2kool
as hexkid says, rev up the error reporting and try to output the latest, mysql_error() and mysql_errno()

if there aren't any errors, try removing the LIMIT thingy out there Very Happy
check for the $id if it exists or not in ur database (i mean the same id's at both the places)
kv
Here is one thing I broke my head sometime back to figure out. If sql UPDATE statement where clause does not match any rows in the table, it just returns. No updates, no errors. And it is a valid behaviour.
hexkid
kv wrote:
Here is one thing I broke my head sometime back to figure out. If sql UPDATE statement where clause does not match any rows in the table, it just returns. No updates, no errors. And it is a valid behaviour.


How very right, thank you for reminding us of that Smile

So, after an UPDATE command, instead of the tests above you can do
Code:
$num = mysql_affected_rows();
if ($num < 0) {
  ### error in query, for simplicity sake we exit with the error
  exit('Error in UPDATE command: ' . mysql_error());
} else {
  echo 'The UPDATE command changed ', $num, 'record(s).';
}
rohan2kool
hexkid wrote:
kv wrote:
Here is one thing I broke my head sometime back to figure out. If sql UPDATE statement where clause does not match any rows in the table, it just returns. No updates, no errors. And it is a valid behaviour.


How very right, thank you for reminding us of that Smile

So, after an UPDATE command, instead of the tests above you can do
Code:
$num = mysql_affected_rows();
if ($num < 0) {
  ### error in query, for simplicity sake we exit with the error
  exit('Error in UPDATE command: ' . mysql_error());
} else {
  echo 'The UPDATE command changed ', $num, 'record(s).';
}


now why didn't i think of that
hexkid
rohan2kool wrote:
now why didn't i think of that

Well ... I'm guessing it was because of the same reason I didn't Smile
Related topics
Mysql database problem
Help with mysql query
insert data to mySQL database problem
Delete data from MySQL database problem!!
What is wrong with this MySQL query?
[Edit] mySQL Count
mysql syntax problem
Mysql wont connect Hmmm
Found the Problem, this topic can be closed... thanks =)
whats wrong with this mysql query?
Looping through multiple mysql results
MySQL Query Cache
mysql query based on 2 fields using 3 different tables
PHP and Javascript Issue handling data from a mysql query
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.