Php 代码不';直到按钮被触发才执行

Php 代码不';直到按钮被触发才执行,php,mysql,Php,Mysql,我需要你的帮助。所以问题是,我已经做了一些编码,但我不知道为什么它在页面加载时不起作用。但当我触发任何按钮(保存信息修改或取消信息修改)时,它都会工作 php代码: if(isset($_POST['nametb']) && isset($_POST['usernametb']) && isset($_POST['emailtb']) && isset($_POST['confirmtb']) && isset($_POST['ab

我需要你的帮助。所以问题是,我已经做了一些编码,但我不知道为什么它在页面加载时不起作用。但当我触发任何按钮(保存信息修改或取消信息修改)时,它都会工作

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'])){

            $select_info = "SELECT * from user_info WHERE id='$user_id'";

            if($select_info_run = @mysql_query($select_info)){

                $namedb = mysql_result($select_info_run, 0, 'name');
                $usernamedb = mysql_result($select_info_run, 0, 'username');
                $emaildb = mysql_result($select_info_run, 0, 'email');
                $confirmdb = mysql_result($select_info_run, 0, 'email');
                $aboutdb = mysql_result($select_info_run, 0, 'about');
                $interestdb = mysql_result($select_info_run, 0, 'interest');
                $dreamdb = mysql_result($select_info_run, 0, 'dream');
                $likedb = mysql_result($select_info_run, 0, 'like');
                $schooldb = mysql_result($select_info_run, 0, 'school');
                $schoolyrdb = mysql_result($select_info_run, 0, 'schoolyr');
                $occupationdb = mysql_result($select_info_run, 0, 'occupation');
                $occupationyrdb = mysql_result($select_info_run, 0, 'occupationyr');

            }
            else{
                echo 'Server down :(';
            }


        }
            else{
                echo server down :(';
            }        
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>

是否要显示表单?然后,去掉最后一个“else”中的回声。然后将显示该表单。当用户单击submit按钮时,表单会将该信息发布到页面

另外,您的第二个“else{echo server down:(';})”在“server down:(')之前缺少一个引号


问题的关键是我称之为“隔离”:您需要隔离导致问题的原因。我建议使用“注释代码并刷新页面”如果您的时间紧迫,请使用此技术。但最好分析和解释您的代码,并理解它为什么没有按您的要求运行。

当您单击按钮时,它会运行,因为:


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'])){

if语句在执行任何操作之前检查POST数组中是否设置了任何内容。 当您单击submit按钮(似乎是任意一个按钮)时,表单会发送此消息


如果您试图填充页面加载上的字段,则需要将SELECT语句移动到If语句之外的相关代码中。由于您似乎要使用此表单更新数据库数据,因此应将INSERT/update语句放在If语句中,以便在单击“提交”按钮之前不会运行这些语句(等待其他逻辑操作,以考虑按下了哪个按钮。)

因为代码中的所有内容都在
if($\u POST…
条件内。当然,在您发布某个内容之前,它不会运行。或者我缺少了某个内容?您的第二个“else{echo server down:(';}”在“服务器关闭:(”)之前缺少一个引号;很抱歉,我键入了一个引号,即使它不起作用。加载时,它将检查该值是否存在,是否为NULL,是否存在于页面的标题或主体部分。加载php页面时,它可以检查“加载”如果在页面请求中也发送了值,那么就可以使用谷歌搜索。@Krishnarswat:这里有一个例子说明了isset和empty之间的区别:非常感谢你们两位,现在这一次它在我的脑海中得到了修复……再次感谢你们。。。。