Jump to content

PHP MySQL basic stuff not working PLEASE HELP


Paldo

Recommended Posts

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...  ;D

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.

 

???

Link to comment
Share on other sites

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

 

 

 

 

 

 

Link to comment
Share on other sites


$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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.