Jump to content


Photo

PHP Form Issue to MYSQL

#php #mysql #form

  • Please log in to reply
1 reply to this topic

#1 shadowblad3rz

shadowblad3rz

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 22 June 2013 - 06:55 PM

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);
}

?>


#2 ginerjm

ginerjm

    Advanced Member

  • Members
  • PipPipPip
  • 1,865 posts
  • LocationVoorheesville NY

Posted 23 June 2013 - 12:51 PM

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.

JG

PS - If you're posting here you should be using:
        error_reporting(E_ALL | E_NOTICE);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com