<?php
$connection = mysqli_connect( "localhost", "gari" , "gari" , "onlinemarket" );
$call = "SELECT * FROM products WHERE id ='". 4 ."'";
$result = mysqli_query( $connection , $call );
while ( $row = mysqli_fetch_array( $result ) ) {
$call = "UPDATE products SET stock = '". 666 ."' WHERE id ='". 4 ."'";
$result = mysqli_query( $connection , $call );
}
mysqli_close( $connection );
?>
The real problem is in $row = mysqli_fetch_array( $result )
, I receive this:
mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\tiendaonline\php\prueba.php on line 12 i dont know how to use mysqli_error() to get the error.
Thank You.
答案 0 :(得分:0)
Try this one,
<?php
$connection = mysqli_connect( "localhost", "gari" , "gari" , "onlinemarket" );
$call = "SELECT * FROM products WHERE id ='4'";
$result = mysqli_query( $connection , $call );
while ( $row = mysqli_fetch_array( $result ) )
{
$call1 = "UPDATE products SET stock = '666' WHERE id ='4'";
$result1 = mysqli_query( $connection , $call1 );
}
mysqli_close( $connection );
?>
Hope this helps.
答案 1 :(得分:0)
Looks like inner loop replaces $result
, Also while loop makes no sense if you are not using $row
inside loop. Try following code
<?php
$connection = mysqli_connect( "localhost", "gari" , "gari" , "onlinemarket" );
$call = "SELECT * FROM products WHERE id ='". 4 ."'";
$result = mysqli_query( $connection , $call );
while ( $row = mysqli_fetch_array( $result ) )
{
$call = "UPDATE products SET stock = '". 666 ."' WHERE id ='". 4 ."'";
$resultUpdate = mysqli_query( $connection , $call );
}
mysqli_close( $connection );
?>
If you just need to update record no need for select query then use following code.
$call = "UPDATE products SET stock = '". 666 ."' WHERE id ='". 4 ."'";
$resultUpdate = mysqli_query( $connection , $call );
mysqli_close( $connection );
答案 2 :(得分:0)
Try like this,
$resultUpdate = mysqli_query($connection, $call)
or die("Error: " . mysqli_error($connection));
答案 3 :(得分:0)
Inside the while loop, you are resetting the $result and Since Inside the loop you are doing an Update query to the DB, the output will be either true or false. And in the next iteration of the loop, mysqli_fetch_array cannot find anything to iterate over. Try something like this:
.
.
.
$result_select = mysqli_query( $connection , $call );
while ( $row = mysqli_fetch_array( $result ) )
{
$call = "UPDATE products SET stock = '". 666 ."' WHERE id ='". 4 ."'";
$result_update = mysqli_query( $connection , $call );
}