Jump to content

[SOLVED] Php MSQL INSERT by checkbox selection!!


davidL

Recommended Posts

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>

Link to comment
Share on other sites

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...

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.