-1

Here is my code, when I press start everything work perfect but when I try to update something from my table I get an error Notice: Undefined index: id in .. on line 4. How I can identifi the id from my table so I can update the row ?

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';
}
aleo
  • 43
  • 5

1 Answers1

1

you are not properly using the variable, should be as follows:

$update = mysql_query("UPDATE `orar` SET `stop`='$stop'  WHERE `id` = '$id'");

however your code is widely open to sql injection. you should never directly use variables sent from the client in your queries. do some research in order to make your code more secure.

and as a side note, mysql_ methods are deprecated in favor of mysqli_ methods.

taxicala
  • 21,408
  • 7
  • 37
  • 66