ataloss Posted November 16, 2013 Share Posted November 16, 2013 Hi fellows. I'm trying mysqli for the first time and failing miserably. I'm trying to select a value from a dropdown and update a field (taxrate) in a database (numbersdb)..The nessage I get is "update_taxrate' was not set, so no update attempted".Thanks for any help. <?php ini_set('display_errors', true); error_reporting(E_ALL); $dbconnect = mysqli_connect('localhost','root',''); if($dbconnect == false) { throw new Exception("Connect failed: ".mysqli_connect_error()); } if(mysqli_select_db($dbconnect, 'numbersdb') == false) { throw new Exception("Select DB failed: ".mysqli_error($dbconnect)); } $taxrate = (isset($_POST['submit'])) ? mysqli_real_escape_string($dbconnect, $_POST['taxrate']) : ''; $id = (isset($_POST['id'])) ? mysqli_real_escape_string($dbconnect, $_POST['id']) : ''; $result = mysqli_query($dbconnect, "SELECT * FROM numbdata"); if (!empty($_POST['update_taxrate'])) { // $id=$_POST['id']; $sql = "UPDATE numbdata SET taxrate = '$taxrate' WHERE id ='$id'"; $update = mysqli_query($dbconnect, $sql); if($update == false) { throw new Exception("Update query failed: ".mysqli_error($dbconnect).PHP_EOL.$sql); } echo "Taxrate set for ".mysqli_affected_rows($dbconnect)." row(s)."; } else { echo "'update_taxrate' was not set, so no update attempted."; } ?> <!DOCTYPE html> <html> <head> <title>Select taxrate</title> <style type="text/css"> body { background: #cff; } form { text-align: center; } </style> </head> <body> <form name="taxset" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <p><label>Select state/rate</label><p> <select name="taxrate"> <option value="0.04000" selected>4% Alabama</option> <option value="0.05600">5.6% Arkansas</option> </select> </p> <!--<p><label>Update taxrate</label> <input type="text" name="update_taxrate">--> <p><input type="submit" name="submit" value="update"></p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/283959-help-wmysqli/ Share on other sites More sharing options...
oaass Posted November 16, 2013 Share Posted November 16, 2013 You have commented out the input field for update_taxrate, this will result in that $_POST['update_taxrate'] does not exist Link to comment https://forums.phpfreaks.com/topic/283959-help-wmysqli/#findComment-1458524 Share on other sites More sharing options...
Barand Posted November 16, 2013 Share Posted November 16, 2013 The dropdown name is "taxrate". You also refer to $_POST['id'] but I don't see anything with the name "id" in the form either Link to comment https://forums.phpfreaks.com/topic/283959-help-wmysqli/#findComment-1458585 Share on other sites More sharing options...
ataloss Posted November 16, 2013 Author Share Posted November 16, 2013 thanks guys for your observations. firstly, the "id" is there, I just don't know where to put it. the input field..please do corrrect me where I'm wrong, I'm thinking that input code was for entering arguments and wouldn't that defeat the purpose of the dropdown menu? I haven't quite caught on to this yet. thanks for further help. Link to comment https://forums.phpfreaks.com/topic/283959-help-wmysqli/#findComment-1458612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.