Paldo Posted May 17, 2009 Share Posted May 17, 2009 Hi! I originaly wanted to use form post metod to update integer value in my database. I tried to use $sql=(" UPDATE Customers SET balance= balance + $trasfer WHERE userID = $usID "); but it's was not workin. Later on with no succses of solving this I reduced formulation of query just to try it to : $sql=(" UPDATE Customers SET balance= 200 WHERE balance = 500 "); and guess what - NOT WORKING. when I test this query in phpMyAdmin it's working. The problem is only when I try to use it in PHP. I was able to use stuff like INSER or SELECT in PHP with no problem but with this one I'm realy despred. Please help.... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/ Share on other sites More sharing options...
trq Posted May 17, 2009 Share Posted May 17, 2009 Without code we cannot help. Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835790 Share on other sites More sharing options...
Paldo Posted May 17, 2009 Author Share Posted May 17, 2009 Without code we cannot help. <html> <body> <?php <?php $con = mysql_connect("mysql.webzdarma.cz","parobek","adnddnd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(("parobek", $con); $sql=(" UPDATE Customers SET balance= balance + $transfer WHERE cisuctu= $accountID "); mysql_close($con); ?> </body> </html> // $transfer and $acountID are variables posted from a form from previous page... Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835794 Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 Of course it doesn't work. You aren't executing the query... You are just defining a variable containing the query. Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835796 Share on other sites More sharing options...
Paldo Posted May 17, 2009 Author Share Posted May 17, 2009 What it does is it adds a new record to database containing only accountID that is even the same as one already existing (the one that the transfer should go to ) and zero balance. If I'm not executing query what should I use to do this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835801 Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835802 Share on other sites More sharing options...
Paldo Posted May 17, 2009 Author Share Posted May 17, 2009 Ok lads I solved the problem with adding nonsens to database, it was my mistake couse I wrote incorect site name in form soruce site... I'm still in trouble though. Now it does nothing. I checked the link you posted. Thak you but maybe becouse of me it didn't help me much. Could you be please more specific about executing query. Im still not getting it. Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835819 Share on other sites More sharing options...
Paldo Posted May 17, 2009 Author Share Posted May 17, 2009 Ok so I chnged it to this: <html> <body> <?php $con = mysql_connect("mysql.webzdarma.cz","parobek","adnddnd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("parobek", $con); mysql_query(" UPDATE 'Customers' SET balance= balance + $_POST[transfer] WHERE acountNumber= $_POST[acountID] "); mysql_close($con); ?> </body> </html> // But still not working ... Somebody could help me pls? Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835821 Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 How doesn't it work? It just doesn't update or do you get any errors of any sort? Maybe try to echo the query to see that it's generated correctly. Also, for future posts, could you please put or [php] tags around the code you are posting? Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835830 Share on other sites More sharing options...
Imad Posted May 17, 2009 Share Posted May 17, 2009 Change the query to: mysql_query(" UPDATE 'Customers' SET balance= balance + $_POST[transfer] WHERE acountNumber= $_POST[acountID] ") or die(mysql_error()); And see what it returns. Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835838 Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 or die() is bad practice. At the very least use trigger_error instead of die(). In that way you can still control the error reporting. Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835842 Share on other sites More sharing options...
Paldo Posted May 17, 2009 Author Share Posted May 17, 2009 ok I added the or die(mysql_error()); now it says: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Zakaznici' SET balance= balance + 800 WHERE accountNumber= 1001' at line 1 So it can take numbers (800 and 1001 ) that is what I submited on previous page. ??? Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835851 Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 Remove the quotation marks around the table name. Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835860 Share on other sites More sharing options...
Paldo Posted May 17, 2009 Author Share Posted May 17, 2009 Yeah I just did it and it works thank you all. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-835862 Share on other sites More sharing options...
kam16 Posted May 18, 2009 Share Posted May 18, 2009 Change the query to: mysql_query(" UPDATE 'Customers' SET balance= balance + $_POST[transfer] WHERE acountNumber= $_POST[acountID] ") or die(mysql_error()); And see what it returns. If your Using this Code Ur missing a Few quotes mysql_query(" UPDATE 'Customers' SET balance= balance + $_POST['transfer'] WHERE acountNumber= $_POST['acountID'] ") or die(mysql_error()); Or U can do it $transfer = $_POST['transfer']; $accountID = $_POST['accountID']; $sql = " UPDATE 'Customers' SET balance= balance + $transfer WHERE acountNumber= $accountID "; $update = mysql_query($sql) or die(mysql_error()); :] hope this works for you Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-836074 Share on other sites More sharing options...
Ken2k7 Posted May 18, 2009 Share Posted May 18, 2009 $transfer = $_POST['transfer']; $accountID = $_POST['accountID']; $sql = " UPDATE Customers SET balance= balance + $transfer WHERE acountNumber= $accountID "; $update = mysql_query($sql) or die(mysql_error()); The point Daniel0 made was that you had single quotes around the table name so MySQL treated it as a string rather than as a table name. Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-836077 Share on other sites More sharing options...
luca200 Posted May 19, 2009 Share Posted May 19, 2009 If your Using this Code Ur missing a Few quotes mysql_query(" UPDATE 'Customers' SET balance= balance + $_POST['transfer'] WHERE acountNumber= $_POST['acountID'] ") or die(mysql_error()); :] hope this works for you Not at all! He wasn't missing anything (apart from using bad quotes around table name), this code is totally wrong Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-837071 Share on other sites More sharing options...
upgrader Posted May 19, 2009 Share Posted May 19, 2009 You might want to remove your mysql host, username and password from the post with the code... Quote Link to comment https://forums.phpfreaks.com/topic/158477-php-mysql-basic-stuff-not-working-please-help/#findComment-837155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.