php update MySql record -


i trying use php simple api update column in record in database. however, stuck missing parameters error whenever try http://localhost/set_is_open.php?open=0&shop_id=2

here api:

<?php     header('content-type: application/json');     require_once 'db.php';      if(!isset($_get["open"]) || empty(trim($_get["open"])) || !isset($_get["shop_id"]) || empty(trim($_get["shop_id"])))         die(json_encode(array("error" => "missing request paramters.")));      $isopen = trim($_get["open"]);     $shop_id = trim($_get["shop_id"]);      if(! $conn ) {         die('could not connect: ' . mysql_error());     }      $sql = 'update shops                     set is_open = isopen                     shop_id = shop_id';      mysql_select_db('shops');     $retval = mysql_query( $sql, $conn );     if(! $retval ) {         die('could not update data: ' . mysql_error());     }     echo "updated data successfully\n";     mysql_close($conn); ?> 

i doubt there wrong doing maybe in syntax, couldn't figure out. followed tutorial here

problem in if condition.

with empty() , following things considered empty:

  • "" (an empty string)
  • 0 (0 integer)
  • 0.0 (0 float)
  • "0" (0 string)
  • null
  • false
  • array() (an empty array)
  • var $var; (a variable declared, without value in class)

and inserting open=0&shop_id=2 argument here, open variable assumed empty.

you use,

if(!isset($_get["open"]) || trim($_get["open"]) == '' ||     !isset($_get["shop_id"]) || trim($_get["shop_id"] == ''))     die(json_encode(array("error" => "missing request paramters."))); 

other point mysql functions deprecated. use mysqli_ or pdo best. use prepared statements security.

read : why shouldn't use mysql_* functions in php?


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -