no DB update

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 660
  • Loc: Conroe, Texas

Post 3+ Months Ago

okay Aparently I am doing something wrong and I cannot figure it out. ("Feeling like a noob right now")
its able to pull into from the DB and show in the option box but when trying to change the info from "Hot" To "Cold" its just going to "next" and basically saying its done. but it dont update the DB.

Its now coming up with saying this "Error: Duplicate entry '1' for key 'hot'" but the status that is in the DB is cold (0) and i am trying to update it to Hot (1)

Admin.php
PHP Code: [ Select ]
<? include("database.php"); ?>
<form action="adminprocess.php" method="post" enctype="multipart/form-data" name="form1">
  <select name="serial" >
    <? $q  =  "SELECT  * FROM ".TBL_ORDER." ORDER BY serial ASC";
                $stored_orders =  mysql_query($q)  or  die(mysql_error()."There was a problem...".$q);
                     
                            if(mysql_num_rows($stored_orders) >= 1){
                        echo  "<table width='100%'  border=0 cellpadding='1' cellspacing='1'>";
                        while($d  =  mysql_fetch_array($stored_orders))
                        {
echo "<option value='".$d['serial']."'>".$d['serial']."</option>";
      }} else { echo "No Files";}
     
?>
  </select>
  <select name="status" id="select">
    <option value="1">Hot</option>
    <option value="0">Cold</option>
  </select>
<input type="hidden" name="subhot" value="1" />
  <input type="submit" name="submit" id="submit" value="Submit">
</form>
 
  1. <? include("database.php"); ?>
  2. <form action="adminprocess.php" method="post" enctype="multipart/form-data" name="form1">
  3.   <select name="serial" >
  4.     <? $q  =  "SELECT  * FROM ".TBL_ORDER." ORDER BY serial ASC";
  5.                 $stored_orders =  mysql_query($q)  or  die(mysql_error()."There was a problem...".$q);
  6.                      
  7.                             if(mysql_num_rows($stored_orders) >= 1){
  8.                         echo  "<table width='100%'  border=0 cellpadding='1' cellspacing='1'>";
  9.                         while($d  =  mysql_fetch_array($stored_orders))
  10.                         {
  11. echo "<option value='".$d['serial']."'>".$d['serial']."</option>";
  12.       }} else { echo "No Files";}
  13.      
  14. ?>
  15.   </select>
  16.   <select name="status" id="select">
  17.     <option value="1">Hot</option>
  18.     <option value="0">Cold</option>
  19.   </select>
  20. <input type="hidden" name="subhot" value="1" />
  21.   <input type="submit" name="submit" id="submit" value="Submit">
  22. </form>
  23.  


adminprocess.php
PHP Code: [ Select ]
<?]
 
 
   $con=mysqli_connect("localhost","user","pass","DB");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
   
   
      /*update Product hotness*/
     if(isset($_POST['subhot'])){
      $serial = $_POST['serial'];
      $status = $_POST['status'];
         $q = "UPDATE users SET hot = '$status' WHERE serial = '$serial'";
         if (!mysqli_query($con,$q)) {  die('Error: ' . mysqli_error($con));  }
      echo "1 record added ";
        /* header("Location: admin.php");*/
      echo "<a href='admin.php'>next</a>";
     }
 
?>
  1. <?]
  2.  
  3.  
  4.    $con=mysqli_connect("localhost","user","pass","DB");
  5. // Check connection
  6. if (mysqli_connect_errno())
  7.   {
  8.   echo "Failed to connect to MySQL: " . mysqli_connect_error();
  9.   }
  10.    
  11.    
  12.       /*update Product hotness*/
  13.      if(isset($_POST['subhot'])){
  14.       $serial = $_POST['serial'];
  15.       $status = $_POST['status'];
  16.          $q = "UPDATE users SET hot = '$status' WHERE serial = '$serial'";
  17.          if (!mysqli_query($con,$q)) {  die('Error: ' . mysqli_error($con));  }
  18.       echo "1 record added ";
  19.         /* header("Location: admin.php");*/
  20.       echo "<a href='admin.php'>next</a>";
  21.      }
  22.  
  23. ?>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 446

Post 3+ Months Ago

What do the output code look like for the admin.php ... I ask because this throws me off echo "<table width='100%' border=0 cellpadding='1' cellspacing='1'>";

Also echo out the would be MySQL update statement to see what the actual statement is.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Not sure on how much help I'll be what I notice (besides that table that ScottG mentioned) is that in admin you are retrieving stuff from TBL_ORDER while in the adminprocess you are updating the table 'users'. Maybe that's correct, I don't know your database scheme.

Also, is the field 'status' set as primary_key or anything else special asides from regular fields?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 660
  • Loc: Conroe, Texas

Post 3+ Months Ago

I am not sure what ya are talking about I do NOT see a table. The .TBL_ORDERS. and users are correct

Refresh your page. :wha:


Edit: I see what you are talking about. ("Note to self don't look at code half awake")
I will test it here in a second.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 112 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.