php代码没有成功执行

时间:2011-12-03 13:12:33

标签: php mysql

我在下面的代码中遇到了一个问题,当我尝试更新这些字段时,由于喜欢,学校,校园字段,我的查询不起作用& else部分执行,但当我从查询中删除这3它工作正常。请帮助我,thx提前和PHP& html代码如下: -

php: -

if(isset($_POST['nametb']) && isset($_POST['usernametb']) && isset($_POST['emailtb']) && isset($_POST['confirmtb']) && isset($_POST['abouttb']) && isset($_POST['interesttb']) && isset($_POST['dreamtb']) && isset($_POST['liketb']) && isset($_POST['schooltb']) && isset($_POST['schoolyrtb']) && isset($_POST['occupationtb']) && isset($_POST['occupationyrtb']) && isset($_POST['passwordstb']))
            {

                $nametb = $_POST['nametb'];
                $usernametb = $_POST['usernametb'];
                $emailtb = $_POST['emailtb'];
                $confirmtb = $_POST['confirmtb'];
                $abouttb = $_POST['abouttb'];
                $interesttb = $_POST['interesttb'];
                $dreamtb = $_POST['dreamtb'];
                $liketb = $_POST['liketb'];
                $schooltb = $_POST['schooltb'];
                $schoolyrtb = $_POST['schoolyrtb'];
                $occupationtb = $_POST['occupationtb'];
                $occupationyrtb = $_POST['occupationyrtb'];
                $passwordtb = $_POST['passwordstb'];
                $passwordstb = md5($passwordtb);            

                if(!empty($nametb) && !empty($usernametb)){

                    if(!empty($passwordtb)){

                        $password_get = "SELECT id from user_login WHERE password='$passwordstb'";

                        if($password_get_run = @mysql_query($password_get)){

                            if(mysql_num_rows($password_get_run) > 0){          

                                if(($emailtb != '' && $confirmtb != '-') || ($emailtb != '-' && $confirmtb != '-')){

                                    if($emailtb == $confirmtb){

                                        if(preg_match("/^[A-Z0-9._%-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i", $emailtb)){

                                            $query = "UPDATE user_info SET `name`='$nametb', `username`='$usernametb', `email`='$emailtb', `about`='$abouttb', `interest`='$interesttb', `dream`='$dreamtb', `like`='$liketb', `school`='$schooltb', `schoolyr`='$schoolyrtb', `occupation`='$occupationtb', `occupationyr`='$occupationyrtb' WHERE id='$user_id'";

                                            if($query_run = @mysql_query($query)){

                                                echo 'info successfully updated';
                                            }
                                            else{

                                                echo 'Failiure in updating info';
                                            }

html: -

<form action="<?php if(isset($current_file)){ echo $current_file; } ?>" method="POST">

<fieldset id="fieldset1">

<legend style="font-family: Ubuntu; font-size:20px;">Info</legend>

<label id="name" title="Name" for="textbox1">Name :</label>

<label id="username" title="UserName" for="textbox2">UserName :</label>

<label id="email" title="Email" for="textbox3">Email :</label>

<label id="confirm" title="Confirm Email" for="textbox4">Confirm :</label>

<br />

<input type="text" id="textbox1" name="nametb" value="<?php if(isset($namedb)){ echo $namedb; } ?>" />

<input type="text" id="textbox2" name="usernametb" value="<?php if(isset($usernamedb)){ echo $usernamedb; } ?>" />

<input type="text" id="textbox3" name="emailtb" value="<?php if(isset($emaildb)){ echo $emaildb; } ?>" />

<input type="text" id="textbox4" name="confirmtb" value="<?php if(isset($confirmdb)){ echo $confirmdb; } ?>" />

<br /><br />

<div id="hrln"><hr /></div>

<label id="about" title="About you" for="textarea1">About :</label>

<label id="interest" title="You are interested in?" for="textarea2">Interested in :</label>

<br />

<textarea id="textarea1" name="abouttb"><?php if(isset($aboutdb)){ echo $aboutdb; } ?></textarea>

<textarea id="textarea2" name="interesttb"><?php if(isset($interestdb)){ echo $interestdb; } ?></textarea>

<br /><br /><br /><br /><br /><hr />

<label id="dream" title="Your Dream?" for="textarea3">Dream :</label>

<label id="like" title="What do you like?" for="textarea4">You like :</label>

<br />

<textarea id="textarea3" name="dreamtb"><?php if(isset($dreamdb)){ echo $dreamdb; } ?></textarea>

<textarea id="textarea4" name="liketb"><?php if(isset($likedb)){ echo $likedb; } ?></textarea>

<br /><br /><br /><br /><br /><hr />

<label id="education" title="Your school" for="textbox5">School | University :</label>

<label id="educationyr" title="Year" for="textbox6">Year :</label>

<br />

<input type="text" name="schooltb" id="textbox5" value="<?php if(isset($schooldb)){ echo $schooldb; } ?>" />

<input type="text" name="schoolyrtb" id="textbox6" value="<?php if(isset($schoolyrdb)){ echo $schoolyrdb; } ?>" />

<br /><br /><hr />

<label id="occupation" title="Occupation" for="textbox7">Occupation :</label>

<label id="occupationyr" title="Year" for="textbox6">Year :</label>

<br />

<input type="text" id="textbox7" name="occupationtb" value="<?php if(isset($occupationdb)){ echo $occupationdb; } ?>" />

<input type="text" id="textbox8" name="occupationyrtb" value="<?php if(isset($occupationyrdb)){ echo $occupationyrdb; } ?>" />

<br /><br /><hr />

<label id="passwords" title="For Security Purpose" for="textbox9">Password :</label>

<input type="password" id="textbox9" name="passwordstb" />

<input type="submit" value="Save Info Modification" name="save" id="button1" />

<input type="submit" value="Cancel Info Modification" name="cancel" id="button2" />

</fieldset>

</form>

2 个答案:

答案 0 :(得分:3)

  

您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在附近使用正确的语法 ='嘿那里',school =' - ',schoolyr =' - ',占用='Chitchat CEO' ,占领'第1行

然后您的第二个SQL错误是您使用保留的SQL关键字作为列名。你需要用反引号引用这个:

 SELECT ...   `like` = '$var'

再次注意反击。

如果您不知道哪些列名可能是特殊名称,那么引用它们是最安全的。 (不是一般性建议,但对于新手。)

答案 1 :(得分:2)

你错过了'$ schoolyrtb'和职业之间的逗号:  , schoolyr='$schoolyrtb' occupation='$occupationtb'

但您也可以使用

找到这些错误
    else{
       echo 'Failiure in updating info, error: ' . mysql_error();
    }
相关问题