update sql not updating

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post by jonnyfortis »

Celauran wrote:
jonnyfortis wrote:
Celauran wrote:

Code: Select all

$result=mysql_query($query);
or die(mysql_error());
You needed the ; after mysql_query() when the next line was commented out. Now you need to put it back.
like this??
No. You're getting the error because

Code: Select all

or die(mysql_error());
is not a valid statement. You need

Code: Select all

$result=mysql_query($query) or die(mysql_error());
brilliant. that done it, thanks for your help. i see what i done, thanks again
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post by jonnyfortis »

i have just noticed something. even though this works, should my query not include a reference to the database connection

Code: Select all

$result=mysql_query($UpdateQuery) or die(mysql_error());
should be

Code: Select all

$result=mysql_query($UpdateQuery, $wiz) or die(mysql_error());
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post by Celauran »

As per the manual, it's optional. http://php.net/manual/en/function.mysql-query.php

Your code shouldn't be using mysql_query, and definitely shouldn't have die statements in it.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post by jonnyfortis »

Celauran wrote:As per the manual, it's optional. http://php.net/manual/en/function.mysql-query.php

Your code shouldn't be using mysql_query, and definitely shouldn't have die statements in it.
sorry bit confused, this is for another UPDATE statement to update stock, this is working but i wanted to know if it needed to included the database, as you say its optional.

Code: Select all

if ($row_rsUpdateStock['TransactResult'] == 'Completed')  {  
// UPDATE THE DATABASE      

$oldStock = $row_rsUpdateStock['Stock'];
$stockSold = $row_rsUpdateStock['Quantity'];
$newStock = $row_rsUpdateStock['Stock'] - $row_rsUpdateStock['Quantity'];
$SKU = $row_rsUpdateStock['SKU'];

$UpdateQuery="UPDATE wiz_Stock SET Stock = '$newStock' WHERE wiz_Stock.SKU = '$SKU'";

$result=mysql_query($UpdateQuery);
$result=mysql_query($UpdateQuery) or die(mysql_error());

}
Post Reply