Jump to content

Recommended Posts

Hey guys i have got some PHP Code that i use its for an order page. When i place an order on my form it gets the Customer Information. But when i try to put an order in for the checkbox items it only gets the 1st item that is clicked in the checkbox and does not get the quantity.

 

Is there anything that i am doing wrong in my code?

form action="localhost" method="post">

<tr>
<th>Shirts</th>
<th>Quantity</th>
</tr>

<tr>

<td>
        <br />
        <input type="checkbox" name="items" value="SH01" /><label for="rd1">Obey T-Shirt: $9.99</label></div> <br />
        <input type="checkbox" name="items" value="SH02" /><label for="rd1">Obey Professor: $9.99</label></div> <br />
        <input type="checkbox" name="items" value="SH03" /><label for="rd1">Hustle T-Shirt: $9.99</label></div> <br />
        <input type="checkbox" name="items" value="SH04" /><label for="rd1">Hip-Hop Support: $9.99</label></div> <br />
        <input type="checkbox" name="items" value="SH05" /><label for="rd1">90's Shirt: $9.99</label></div> <br />
        <input type="checkbox" name="items" value="SH06" /><label for="rd1">DOPE Shirt: $9.99</label></div> <br />
        <br />
</td>

<td>
        <br />
        <input type="text" name="qty[SH01]" size ="2"/><br/>
        <input type="text" name="qty[SH02]" size="2"/><br/>
        <input type="text" name="qty[SH03]" size="2"/><br/>
        <input type="text" name="qty[SH04]" size="2"/><br/>
        <input type="text" name="qty[SH05]" size="2"/><br/>
        <input type="text" name="qty[SH06]" size="2"/><br/>
        <br />

</td>

</tr>
        
<tr>

    <td>
        <br />
        <input type="checkbox" name="items" value="SO1" /><label for="rd1">Shoe - Red Lace: $19.99</label></div><br />
        <input type="checkbox" name="items" value="SO2" /><label for="rd1">Shoe - Red High Top: $19.99</label></div><br />
        <input type="checkbox" name="items" value="SO3" /><label for="rd1">Shoe - White: $19.99</label></div><br />
        <input type="checkbox" name="items" value="SO4" /><label for="rd1">Shoe - Black: $19.99</label></div><br />
        <input type="checkbox" name="items" value="SO5" /><label for="rd1">Shoe - Black High Top: $19.99</label></div><br />
        <input type="checkbox" name="items" value="SO6" /> <label for="rd1">Red Basketball: $19.99</label></div><br />
        <br />
    </td>
    
    <td>
        <br />
        <input type="text" name="qty[SO1]" size ="2"/><br/>
        <input type="text" name="qty[SO2]" size="2"/><br/>
        <input type="text" name="qty[SO3]" size="2"/><br/>
        <input type="text" name="qty[SO4]" size="2"/><br/>
        <input type="text" name="qty[SO5]" size="2"/><br/>
        <input type="text" name="qty[SO6]" size="2"/><br/>
        <br />

</td>
</tr>

<tr>
    <td>
        <br />
        <input type="checkbox" name="items" value="SN1" /> <label for="rd1">Snapback Bullets: $29.99</label></div><br />
        <input type="checkbox" name="items" value="SN2" /><label for="rd1">Snapback Grey: $29.99</label></div><br />
        <input type="checkbox" name="items" value="SN3" /><label for="rd1">Snapback Bulls: $29.99</label></div><br />
        <input type="checkbox" name="items" value="SN4" /><label for="rd1">Snapback Miami: $29.99</label></div><br />
        <input type="checkbox" name="items" value="SN5" /><label for="rd1">Snapback Nets: $29.99</label></div><br />
        <input type="checkbox" name="items" value="SN6" /><label for="rd1">Snapback Obey: $29.99</label></div><br />
        <br />
    </td>
<td>
        <br />
        <input type="text" name="qty[SN1]" size ="2"/><br/>
        <input type="text" name="qty[SN2]" size="2"/><br/>
        <input type="text" name="qty[SN3]" size="2"/><br/>
        <input type="text" name="qty[SN4]" size="2"/><br/>
        <input type="text" name="qty[SN5]" size="2"/><br/>
        <input type="text" name="qty[SN6]" size="2"/><br/>
        <br />

</td>    
</tr>

</tr>
</table>
<br />


<h3 class="c4">Please Enter Customer Details</h3>


    <p class="normal">
        <label><input type = "text"  name = "custName" />Name (last name, first name, middle initial)</label><br />
        <label><input type = "text"  name = "phone" />Phone number (ddd-ddd-dddd)</label><br />
        <label><input type = "text" name = "custEmail" />Insert E-Mail Address<br /></label>
    </p>
    
       <script type="text/javascript" src="validatorr.js"></script>
       
       <input type="submit" name="submit">
</form>       

<?php

if (isset($_POST['submit']))
{
$con = mysql_connect('localhost','username','password');
if (!$con)
{
die("Could Not Connect: " . mysql_error());
}

mysql_select_db("$$", $con);

$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,'$_POST[items]','$_POST[qty]')";
mysql_query($sql,$con);

$sql = "INSERT INTO Customer_Information(Cust_ID,Cust_Name,Cust_Phone,Cust_Email) VALUES (null, '$_POST[custName]','$_POST[phone]','$_POST[custEmail]')";
mysql_query($sql,$con);


mysql_close($con);
}

?>
Link to comment
https://forums.phpfreaks.com/topic/279470-php-form-issue-to-mysql/
Share on other sites

Has this ever worked for you? The html appears seriously flawed to me. What's with all the closing </div> tags, but no starting ones? And the <label> tags all pointing at the same id?

 

Anyway, to receive the values from multiple checkboxes with the same group, you need to assign your name= attribute to an array. Try:

 

name='items[]'

 

instead. Then process $_POST['item'] as an array of values.

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.