kostastoump Posted October 24, 2017 Share Posted October 24, 2017 <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. Quote Link to comment https://forums.phpfreaks.com/topic/305442-update-table/ Share on other sites More sharing options...
benanamen Posted October 24, 2017 Share Posted October 24, 2017 (edited) $_POST not $_Post Whatever tutorial you are using, throw it away. There is pretty much everything wrong with this code. Use PDO. https://phpdelusions.net/pdo Edited October 24, 2017 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/305442-update-table/#findComment-1552999 Share on other sites More sharing options...
phpmillion Posted October 26, 2017 Share Posted October 26, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/305442-update-table/#findComment-1553045 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.