Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中定义$var id来更新数据库_Php_Mysql - Fatal编程技术网

如何在php中定义$var id来更新数据库

如何在php中定义$var id来更新数据库,php,mysql,Php,Mysql,这是我的代码,当我按下start everything work perfect时,但当我尝试从我的表中更新某些内容时,我得到一个错误通知:Undefined index:id in。。第4行。如何从表中标识id以便更新行 if(logged_in() === true){ if(isset($_GET['stop']) ){ $id = $_GET['id']; $date = mysql_query("SELECT * FROM `orar` WHERE `id`='id'"); $row

这是我的代码,当我按下start everything work perfect时,但当我尝试从我的表中更新某些内容时,我得到一个错误通知:Undefined index:id in。。第4行。如何从表中标识id以便更新行

if(logged_in() === true){

if(isset($_GET['stop']) ){
$id = $_GET['id'];
$date = mysql_query("SELECT * FROM `orar` WHERE `id`='id'");
$row = mysql_fetch_row($date);
$stop = date('Y/m/d').' '.date('h:i:s');
$update = mysql_query("UPDATE `orar` SET `stop`='$stop'  WHERE `id` = 'id'");

}else{}

if(isset($_POST['start'])){

$user = $user_data['username'];
$start = date('Y/m/d').' '.date('h:i:s');
$add = mysql_query("INSERT INTO `orar` (`id`, `username`, `start`) VALUES ('NULL','$user', '$start')");

echo "<h2>Home</h2><br>
<form method='get' action=''>
<input type='submit' name='stop' class='start_stop_tura-style' value='Stop Tura' />
</form>
";
echo 'Tura start on: '.date('d/m/Y').' at:'.date('h:i:s');

}else{
echo "<h2>Home</h2><br>
<form method='post' action=''>
<input type='submit' name='start' class='start_stop_tura-style' value='Start Tura'/>
</form>";

}

 }else {
 echo '<h2>Home</h2>';
echo 'Login First';
}
if(已登录()==true){
如果(isset($_GET['stop'])){
$id=$_GET['id'];
$date=mysql\u查询(“从'orar'中选择*其中'id`='id'”);
$row=mysql\u fetch\u row($date);
$stop=日期('Y/m/d')。'date('h:i:s');
$update=mysql\u查询(“update`orar`SET`stop`='$stop',其中`id`='id');
}else{}
如果(isset($_POST['start'])){
$user=$user_数据['username'];
$start=日期('Y/m/d')。'date('h:i:s');
$add=mysql\u查询(“插入到`orar`(`id`、`username`、`start`)值中('NULL','$user','$start');
回声“主页
"; 回音“Tura开始日期:”.date('d/m/Y')。“at:”.date('h:i:s'); }否则{ 回声“主页
"; } }否则{ 回声“家”; 回显“先登录”; }
您没有正确使用变量,应如下所示:

$update = mysql_query("UPDATE `orar` SET `stop`='$stop'  WHERE `id` = '$id'");
但是,您的代码对sql注入非常开放。在查询中不应直接使用从客户端发送的变量。做一些研究,使你的代码更安全


作为补充说明,
mysql\uuu
方法被弃用,取而代之的是
mysqli\uu
方法

这无助于我的代码工作。我的错误在这一行:$id=$\u GET['id'];