davidL Posted August 18, 2008 Share Posted August 18, 2008 Hey guys, I'm trying to set up a form to allow me to check a number of products and then have them changed to sold... Im working to set it up so I can choose a product by id with a check box then have all the products selected have "sold" (or whatever) inserted into a VArCHar 'sold' field for that product. The code basically just tables all of the products a pic and there id that part seems to be working and the id variable should be working (I am actually recycling a code I am using to delete the inventory) I'm not sure about my mysql syntax.. So the problem is more than likely here ------------ $sql = "INSERT INTO inventory (sold) WHERE id='$del_id'". "VALUES ('$sold')"; ----------- the table is inventory and the field is sold.. I defined the $sold variable somewhere in there ANY HELP?? Here is my full code.. <table width="600" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="600" border="0" cellpadding="3" cellspacing="1"> <tr> <td></td> <td colspan="4"><span class="style1"> <h2> Select The RV That Sold </h2> </span> </td> </tr> <tr> <td align="center">#</td> <td align="center"><strong>id</strong></td> <td align="center">Vehicle</td> <td align="center"> </td> </tr> <? $query = "SELECT * FROM inventory ORDER BY `id` DESC"; $result = mysql_query($query) or die('Choose a Gallery'); if(mysql_num_rows($result) == 0) { echo (" <br/> <h1> There are no vehicles uploaded at this time </h1> "); } else { while(list($id, $year, $make, $model) = mysql_fetch_array($result)) { ?> <tr> <td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo ($id) ?>"></td> <td><? echo ($id) ?></td> <td><? echo "$year $make $model" ?></td> <td><img src="inventory/inventory1.php?id=<?=$id;?>" width="155" alt="The Diesel Connection" /></td> </tr> <?php } } ?> <tr> <td colspan="5" align="center"><input name="delete" type="submit" id="delete" value="Sold!"></td> </tr> <? $sold = "sold"; if($_POST['delete']){ $checkbox = $_POST['checkbox']; for($i=0;$i<count($checkbox);$i++){ $del_id = $checkbox[$i]; $sql = "INSERT INTO inventory (sold) WHERE id='$del_id'". "VALUES ('$sold')"; $result = mysql_query($sql) or die('Sold Failed');; } if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=soldinventory.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
fenway Posted August 20, 2008 Share Posted August 20, 2008 You can INSERT... WHERE anything. What are you trying to do? Quote Link to comment Share on other sites More sharing options...
davidL Posted August 20, 2008 Author Share Posted August 20, 2008 haha, Ok my goal is to have it so I can have items (RVs) actually changed from for sale to sold... I added a Varchar to the database that I wanna simple insert "sold" into and I am just using an if statement that detects if the Varchar is empty or has "sold" in it or not... So basically I need this code to select the item by id (with the checkbox) and insert 'sold' into the sold field of the database for that particular item... I dunno maybe this is a hard way to it... Quote Link to comment Share on other sites More sharing options...
fenway Posted August 20, 2008 Share Posted August 20, 2008 So you want an UPDATE statement with a WHERE clause that matches the ID of the record. Quote Link to comment Share on other sites More sharing options...
davidL Posted August 20, 2008 Author Share Posted August 20, 2008 Haha do I have to use and UPDATE statement? Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 20, 2008 Share Posted August 20, 2008 Haha do I have to use and UPDATE statement? out of curiosity, is there any reason not to? it's a simply syntax switch: UPDATE table SET field='value' WHERE field='this' Quote Link to comment 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.