0

I'm 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?

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]");

1 Answer 1

1

You will need to denote your array with brackets and quote your input:

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

or concatenate your string

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

You may wish to use a prepared statement instead of a generated query instead: http://php.net/manual/en/mysqli.prepare.php. Prepared statements are generally safer than generated queries.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.