Jump to content

Recommended Posts

Hello all im new to this been playing with it for a week but i play with c# making games so it's not to different. im having a problem with updating a value in a column in my database. i can get it to work if i use

 

$result1= mysqli_query($con,"UPDATE Customers SET NextExpectedCut = 222 WHERE Name = 'ruth'");

 

but i entered all the databases information into an array ($rows).. so there for i tested already by doing:

 

echo $rows[0][0];

 

and i get the first customers name on the browser so why cant i get this to work? am i formatting it wrong or is there a different way to do this?

 

thanks Tommy :)

 

if(isset($_GET['test']) && $_GET['test'] =="1")
{
   $result = mysqli_query($con,"SELECT * FROM Customers");
   
   while($row = mysqli_fetch_array($result))
   {
      $rows[]=$row;
      
   }

echo $rows[0][0] ." is finished";

$result1= mysqli_query($con,"UPDATE Customers SET NextExpectedCut = 222 WHERE Name = $rows[0][0]");

presumably your names are strings. you must enclose string data by single-quotes inside the query statement so that is treated as a string instead of a mysql keyword or column name.  if you had error checking logic in your code, it would be reporting an undefined column name that is the same as the first name's value.

 

in your hard-coded query - Name = 'ruth'" you have single-quotes around the string value. the query syntax you build where the value comes from a php variable must have the same query syntax.

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.