Jump to content

help w/mysqli


ataloss

Recommended Posts

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

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

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.