无法使用php中的过程更新表

时间:2014-10-07 19:29:51

标签: php mysql sql

我从php表单中获取值并使用它来更新usr表中的行。问题是如果没有给出某些值,则更新查询不起作用。但是,如果给出了表单中的所有变量,则完成更新。

    <?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;
    }
    }
    ?>

程序

    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

0 个答案:

没有答案