问题描述:

I am taking values from php form and using that to update a row in the usr table.The problem is that if some values are not given update query doesnt work. However if all the variables in form are given the update is done.

 <?php

$mysqli=mysqli_connect('localhost','root','mysql','package');

if(mysqli_connect_errno())

{

echo "cant connect to database".mysqli_connect_error();

}

SESSION_start();

if(!isset($_SESSION['usermail'])){

header('Location: http://localhost/twitter/php/login.php');

}

else{

$email = $_SESSION['usermail'];

if(empty($_POST['username']))

$username = NULL;

else

$username = $_POST['username'];

if(empty($_POST['dob']))

$dob = NULL;

else

$dob = $_POST['dob'];

if(empty($_POST['city']))

$city = NULL;

else

$city = $_POST['city'];

if(empty($_POST['school']))

$school = NULL;

else

$school = $_POST['school'];

if(empty($_POST['college']))

$college = NULL;

else

$college = $_POST['college'];

if(empty($_POST['rstatus']))

$rstatus = NULL;

else

$rstatus = $_POST['rstatus'];

if(empty($_POST['work']))

$work = NULL;

else

$work = $_POST['work'];

if(empty($_POST['tagline']))

$tagline = NULL;

else

$tagline = $_POST['tagline'];

if(!$mysqli->query("call update_usr('$email','$username','$dob','$city','$school','$college','$rstatus','$work','$tagline')")) {

echo "call failed:(".$mysqli->errno.")".$mysqli->error;

}

}

?>

The procedure is

 create procedure update_usr(mail varchar(40),username2 varchar(20),dob2 date,city2 varchar(20),school2 varchar(50),coll2 varchar(50),relationship varchar(10),work2 varchar(50),tagline2 varchar(140))

begin

update usr set usrname=username2,dob=dob2,city=city2,school=school2,coll=coll2,rel=relationship,work=work2,tagline=tagline2 where email=mail;

end

相关阅读:
Top