Jump to content

Update table


kostastoump

Recommended Posts

<html>

<head>

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "users";

 

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

 

// Check connection

if ($conn->connect_error) {

   die("Connection failed: " . $conn->connect_error);

}  

 

if(isset ($_Post['update'])){ 

  $value= $_Post['temp'];

  $sql = "UPDATE user SET Temperature=$value WHERE id=1";
  if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
  } else {
    echo "Error updating record: " . $conn->error;
  }
  

}



$conn->close();

 

?>

 

</head>

<body>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

     <input type="text" name="temp" placeholder="Temperature"><br><br>

<div>

   <input type="submit" name="update" value="Apply">

</div>  

  </form>

</form>

</body>

</html>

i try to update the value in my database but when i press the submit button the value doesn't. Please help me. 

Link to comment
Share on other sites

As previous coder suggested, make an attention at lowercase and uppercase letters at $_POST because PHP treats them differently. You can try this code to see how it works:

 

$var1="a";
$Var1="b";
$VAR1="c";


echo "$var1<br>$Var1<br>$VAR1";
 
Also, be sure to harden your security with MySQL. If you don't want to use PDO, use MySQLi prepared statements at least.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.