我为我的办公室建了一些东西,PHP CODE
当我在我的APACHE上构建它时工作正常,当我将它上传到服务器时我得到了POD或MYSQLI错误,我修复了它(通过使用“error_reporting(E_ALL ^ E_DEPRECATED);”在顶部,它起作用了)
我现在唯一的问题是我无法像在APACHE上那样更新数据库,它只是不更新。它给我OK信息,但它不会更新任何内容。
这是我的代码:
<?php
mysqli_connect('localhost','USERNAME','PASSWORD','TABLE');
if(isset($_POST["register"]))
{
$status=$_POST["status"];
mysqli_query("update login set status='$status' WHERE username='".$_SESSION['name_of_user']."'");
echo "<font face=tahoma size=3 color=red>Thank you, the office has been updated.</br></font>";
}
mysqli_close($con);
?>
<form method="post" action=" ">
<font face=tahoma size=3><b>
<label >Update Status:</label>
</br>
<select name="status">
<option value="In a Meeting">In a Meeting</option>
<option value="Waiting for a Meeting">Waiting for Meeting</option>
<option value="In a Referral">In a Referral</option>
<option value="Off Work">Off Work</option>
</select>
<button type="submit" class="btn btn-info" name="register" >Send</button>
</br>
</font>
</form>
答案 0 :(得分:3)
好像你忘了在你的页面中开始会话
<?php
session_start();
,您的mysqli_connect('localhost','USERNAME','PASSWORD','TABLE');
应为mysqli_connect('localhost','USERNAME','PASSWORD','your_database_name');
$con =mysqli_connect('localhost','USERNAME','PASSWORD','your_database_name');
mysqli_query($con,"update login set status='$status' WHERE username='".$_SESSION['name_of_user']."'");
答案 1 :(得分:0)
mysqli_query
似乎缺少应该是第一个参数的$con
变量。 $ con不会在任何地方设置,应来自mysqli_connect
请参阅the docs for connect和query
<?php
$con = mysqli_connect('localhost','USERNAME','PASSWORD','TABLE');
if(isset($_POST["register"]))
{
$status=$_POST["status"];
mysqli_query($con, "update login set status='$status' WHERE username='".$_SESSION['name_of_user']."'");
echo "<font face=tahoma size=3 color=red>Thank you, the office has been updated.</br></font>";
}
mysqli_close($con);
?>
答案 2 :(得分:0)
你忘了开始会议
session_start()
你必须在使用前声明$con
变量
使用此查询
mysqli_query($con,"update login set status='".$status."' WHERE username='".$_SESSION['name_of_user']."'");