there are already values inside the texboxes which i filtered inside the table(score) but i wanna update it by changing the values inside on it and click update.
Can anyone help with my code..i wanna update the values inside the (texboxes) but my code wont work can anyone help me locate the code that messing with the program?
php code:
<?php
if(isset($_POST['update'])){
//1
$u1id = $_POST['id1'];
$u1name = $_POST['name1'];
$u1score1 = $_POST['optA1'];
$u1score2 = $_POST['optB1'];
$u1other_qual = $_POST['other_qual1'];
$u1interview = $_POST['interview1'];
$u1total = $_POST['total1'];
//2
$u2id = $_POST['id2'];
$u2name = $_POST['name2'];
$u2score1 = $_POST['optA2'];
$u2score2 = $_POST['optB2'];
$u2other_qual = $_POST['other_qual2'];
$u2interview = $_POST['interview2'];
$u2total = $_POST['total2'];
//1
mysql_query("UPDATE score SET score1='$u1score1', score2='$u1score2', total='$u1total' WHERE id='$u2id'");
//2
mysql_query("UPDATE score SET score1='$u2score1', score2='$u2score2', total='$u2total' WHERE id='$u2id'");
}
?>
html code:
<form method="post" id="frm" name="frm" action="" />
<table>
<tr>
<td>
ID: <br />
<input type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>
<td>
Name: <br />
<input type="text" name="name1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" readonly /> <br />
<input type="text" name="name2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" readonly /> <br />
</td>
<td>
Score 1: <br />
<input type="text" name="optA1" value="<?php if(empty($score1[0])){$score1[0] = array(NULL);}else{echo $score1[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optA2" value="<?php if(empty($score1[1])){$score1[1] = array(NULL);}else{echo $score1[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Score 2: <br />
<input type="text" name="optB1" value="<?php if(empty($score2[0])){$score2[0] = array(NULL);}else{echo $score2[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optB2" value="<?php if(empty($score2[1])){$score2[1] = array(NULL);}else{echo $score2[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Other Qualification: <br />
<input type="text" name="other_qual1" value="<?php if(empty($other_qual[0])){$other_qual[0] = array(NULL);}else{echo $other_qual[0];} ?>" readonly /> <br />
<input type="text" name="other_qual2" value="<?php if(empty($other_qual[1])){$other_qual[1] = array(NULL);}else{echo $other_qual[1];} ?>" readonly /> <br />
</td>
<td>
Interview: <br />
<input type="text" name="interview1" value="<?php if(empty($interview[0])){$interview[0] = array(NULL);}else{echo $interview[0];} ?>" readonly /> <br />
<input type="text" name="interview2" value="<?php if(empty($interview[1])){$interview[1] = array(NULL);}else{echo $interview[1];} ?>" readonly /> <br />
</td>
<td>
Total: <br />
<input type="text" name="total1" value="<?php if(empty($total[0])){$total[0] = array(NULL);}else{echo $total[0];} ?>" readonly onKeyUp="optTotal1()" /> <br />
<input type="text" name="total2" value="<?php if(empty($total[1])){$total[1] = array(NULL);}else{echo $total[1];} ?>" readonly onKeyUp="optTotal2()" /> <br />
</td>
</tr>
</table>
<input type="submit" value="update" />
</form>
It's in your submit button:
<input type="submit" value="update" />
You have given it a value, but not a name. If you change it to:
<input type="submit" name="update" value="yespleasedososir" />
it will end up in your post var
A few thoughts: 1. Have you echoed out your sql statements to see what you are getting? 2. Try add the tilde symbol before and after each column name...like score1 = 'whatever'. 3. You should really be using the mysqli statemnts.
Related
I wish every time I reload or refresh the page. The disabled textbox still disabled. Because my purpose is to modify the textbox once time and then it will be disabled forever. Is this possible?
Below is my code
<tr>
<td><?php echo $lang_txt['leader_id'][$lang]; ?></td>
<td>:</td>
<td><?php if($_POST['txtLeaderID'] == ""){?><input type="text" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="<?php echo $merchant['LeaderID']; ?>" maxlength="20" /><?php }
else
{
?>
<input type="text" disabled="disabled" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="<?php echo $merchant['LeaderID']; ?>" maxlength="20" /><?php
}
?>
</td>
</tr>
Your variant will be worked with
if(!$_POST['txtLeaderID']){echo('<input type="text" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="'.$merchant['LeaderID'].'" maxlength="20" />')} else {echo('<input type="text" disabled="disabled" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="'.$merchant['LeaderID'].'" maxlength="20" />')}
For example:
<?php
if (!$_POST['username']){
echo('
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
Name: <input type="text" name="username" /><br />
Email : <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Send POST!" />
</form>
');}
else{
echo('
<form>
Name: <input type="text" name="username" disabled="disabled"/><br />
Email : <input type="text" name="email" disabled="disabled"/><br />
</form>
');}
?>
But it didn't work, if we open it in a new tab. You must save this propery anywhere (session, cookie, sql)and check the stored values. it will be work in a new tab.
For example with session:
<?php
session_start();
if (!isset($_SESSION['data'])) {
$_SESSION['data'] = true;
echo('
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
Name: <input type="text" name="username" /><br />
Email : <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Send POST!" />
</form>
');}
else{
echo('
<form>
Name: <input type="text" name="username" disabled="disabled"/><br />
Email : <input type="text" name="email" disabled="disabled"/><br />
</form>
');}
?>
can anyone help me find the code thats causing my code not to work? my code wont update... ive been debuging this code for 3hours already stil cant fix it :(...i need your help guys.
php code:
<?php
if(isset($_GET['gogo'])){
include('include/connect.php');
$batchcode = $_GET['code'];
$sql = mysql_query("SELECT * FROM score WHERE batchcode = '".$batchcode."' ");
if($sql) {
while($rows = mysql_fetch_array($sql)){
$id[] = $rows['id'];
$name[] = $rows['name'];
$score1[] = $rows['score1'];
$score2[] = $rows['score2'];
$other_qual[] = $rows['score3'];
$interview[] = $rows['score4'];
$total[] = $rows['total'];
}
}
}
?>
<?php
if(isset($_POST['update'])){
include('include/connect.php');
//1
$u1id = $_POST['id1'];
$u1name = $_POST['name1'];
$u1score1 = $_POST['optA1'];
$u1score2 = $_POST['optB1'];
$u1other_qual = $_POST['other_qual1'];
$u1interview = $_POST['interview1'];
$u1total = $_POST['total1'];
//2
$u2id = $_POST['id2'];
$u2name = $_POST['name2'];
$u2score1 = $_POST['optA2'];
$u2score2 = $_POST['optB2'];
$u2other_qual = $_POST['other_qual2'];
$u2interview = $_POST['interview2'];
$u2total = $_POST['total2'];
//1
mysql_query("UPDATE score SET score1='$u1score1', score2='$u1score2', total='$u1total' WHERE id='$u1id'");
//2
mysql_query("UPDATE score SET score1='$u2score1', score2='$u2score2', total='$u2total' WHERE id='$u2id'");
header("Location: index.php");
}
?>
html code:
<form method="get">
<form method="post">
Search batchcode: <input type="text" name="code" id="query" /><input type="submit" value="Go" name="gogo" /><br />
<table>
<tr>
<td>
ID: <br />
<input type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>
<td>
Name: <br />
<input type="text" name="name1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" readonly /> <br />
<input type="text" name="name2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" readonly /> <br />
</td>
<td>
Score 1: <br />
<input type="text" name="optA1" value="<?php if(empty($score1[0])){$score1[0] = array(NULL);}else{echo $score1[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optA2" value="<?php if(empty($score1[1])){$score1[1] = array(NULL);}else{echo $score1[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Score 2: <br />
<input type="text" name="optB1" value="<?php if(empty($score2[0])){$score2[0] = array(NULL);}else{echo $score2[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optB2" value="<?php if(empty($score2[1])){$score2[1] = array(NULL);}else{echo $score2[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Other Qualification: <br />
<input type="text" name="other_qual1" value="<?php if(empty($other_qual[0])){$other_qual[0] = array(NULL);}else{echo $other_qual[0];} ?>" readonly /> <br />
<input type="text" name="other_qual2" value="<?php if(empty($other_qual[1])){$other_qual[1] = array(NULL);}else{echo $other_qual[1];} ?>" readonly /> <br />
</td>
<td>
Interview: <br />
<input type="text" name="interview1" value="<?php if(empty($interview[0])){$interview[0] = array(NULL);}else{echo $interview[0];} ?>" readonly /> <br />
<input type="text" name="interview2" value="<?php if(empty($interview[1])){$interview[1] = array(NULL);}else{echo $interview[1];} ?>" readonly /> <br />
</td>
<td>
Total: <br />
<input type="text" name="total1" value="<?php if(empty($total[0])){$total[0] = array(NULL);}else{echo $total[0];} ?>" readonly onKeyUp="optTotal1()" /> <br />
<input type="text" name="total2" value="<?php if(empty($total[1])){$total[1] = array(NULL);}else{echo $total[1];} ?>" readonly onKeyUp="optTotal2()" /> <br />
</td>
</tr>
</table>
<input type="submit" value="update" name="update" />
</form>
</form>
You cannot do a GET and POST at the same time. Use one or the other..
In your HTML remove the <form method="get"> and the corresponding </form> and just use POST. (<form method="post">)
See this: Post and get at the same time in php
So then in your PHP, change GET to POST like so:
if(isset($_POST['gogo'])){
include('include/connect.php');
$batchcode = $_POST['code'];
$sql = mysql_query("SELECT * FROM score WHERE batchcode = '".$batchcode."' ");
...
EDIT:
Or alternatively, you could keep your php code the same the way you have it and just make it 2 seperate forms in your HTML,.. The search form using GET and the other form using POST
So HTML would be this:
<form method="get">
Search batchcode: <input type="text" name="code" id="query" /><input type="submit" value="Go" name="gogo" /><br />
</form>
<form method="post">
<table>
<tr>
<td>
ID: <br />
<input type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>...
...
</form>
If your code won't update then it is very likely you are updating the wrong files. Make sure that you are updating the files on the server or even better updating the files on your local drive and then uploading them to the server.
Check that you have permissions to upload to the correct place too. Might be that your uploads are failing because of bad permissions.
how can i insert this to my database?
I tried a lot of ways to do this, but not succesfull.
Also how can i count the amount of input types?
Thank you
<input class="beschrijving" style="width: 436px" type="text" name="beschrijving[]" />
<input style="width: 60px" type="text" maxlength="" name="aantal[]" />
<input style="width: 100px" type="text" maxlength="" name="prijs[]" />
<br />
<br />
<input class="beschrijving" style="width: 436px" type="text" name="beschrijving[]" />
<input style="width: 60px" type="text" maxlength="" name="aantal[]" />
<input style="width: 100px" type="text" maxlength="" name="prijs[]" />
<br />
<br />
<input class="beschrijving" style="width: 436px" type="text" name="beschrijving[]" />
<input style="width: 60px" type="text" maxlength="" name="aantal[]" />
<input style="width: 100px" type="text" maxlength="" name="prijs[]" />
<br />
<br />
<input class="beschrijving" style="width: 436px" type="text" name="beschrijving[]" />
<input style="width: 60px" type="text" maxlength="" name="aantal[]" />
<input style="width: 100px" type="text" maxlength="" name="prijs[]" />
<br />
<br />
<input class="beschrijving" style="width: 436px" type="text" name="beschrijving[]" />
<input style="width: 60px" type="text" maxlength="" name="aantal[]" />
<input style="width: 100px" type="text" maxlength="" name="prijs[]" />
<br />
<br />
<input class="beschrijving" style="width: 436px" type="text" name="beschrijving[]" />
<input style="width: 60px" type="text" maxlength="" name="aantal[]" />
<input style="width: 100px" type="text" maxlength="" name="prijs[]" />
<br />
<br />
</div>
EDIT:
It seems some people don't know what i mean, first of all i'm working with PHP
This is my problem,
There are multiply input fields in my form with the same name, i have made a array from the names and now i want the values of the array into my database
It tried this but it isn't working,
for( $i = 1; $i <= 5; $i++ ){
$nummer = $_POST['factuurnaam'];
$des = $_POST['beschrijving[]'.$i];
$amount = $_POST['aantal[]'.$i];
$prijs = $_POST['prijs[]'.$i];
$sql = mysql_query("INSERT INTO `facturen`(`beschrijving`,`aantal`, `prijs`, `factuurnaam`) VALUES ('".$des."','".$amount."','".$prijs."','".$nummer."')") or die(mysql_error());
}
you can use array_shift function to get value from all parameter, further for your information in php $variables work fine inside double quotes! see the modified code.
for ($i = 1; $i <= 5; $i++) {
$nummer = $_POST['factuurnaam']; // NOTE: variable not mentioned in HTML form ?
$des = array_shift($_POST['beschrijving']);
$amount = array_shift($_POST['aantal']);
$prijs = array_shift($_POST['prijs']);
$sql = mysql_query("INSERT INTO `facturen` (`beschrijving`,`aantal`, `prijs`, `factuurnaam`)
VALUES ('$des','$amount','$prijs','$nummer')"
) or die(mysql_error());
}
To count the input fields:
$texttofind = "<input";
echo 'Number of inputfields: ' . substr_count($input, $texttofind);
http://php.net/manual/en/function.substr-count.php
Insert html into the database is as easy as adding any string to the database, only you have to escape it like this:
$html = mysql_real_escape_string($input);
http://php.net/manual/en/function.mysql-real-escape-string.php
$input has to be your html.
I think this what what you will need,
$beschrijving = $_POST['beschrijving'];
$aantal = $_POST['aantal'];
$prijs = $_POST['prijs'];
as all are in the same number, so we can loop any of them
for($i=0;$i<count($beschrijving );$i++){
$sql = mysql_query("INSERT INTO `facturen` (`beschrijving`,`aantal`, `prijs`) VALUES ('$beschrijving[$i] ','$aantal[$i] ','$prijs[$i] ')"
)
}
I hope this will help you.
I'm having issues with the form below, whenever i click on an item it catches the item and updates on the mySQL table, it only displays 1 item(how do i make it display all the items that i have checked?).
Also when i put in a quantity in it doesn't update on the mySQL table and it just says 0 when i've put multiple quantities of each item.
Are you guys able to help if that's ok?
<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" size ="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" 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[]" size ="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<input type="text" name="qty[]" 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: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN3" /><label for="rd1">Snapback Bullets: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN4" /><label for="rd1">Snapback Bullets: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN5" /><label for="rd1">Snapback Bullets: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN6" /><label for="rd1">Snapback Bullets: $29.99</label></div><br />
<br />
</td>
<td>
<br />
<input type="text" name="qty" size ="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<br />
</td>
</tr>
</tr>
</table>
<br />
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit']))
{
$con = mysql_connect('$localhost','$url','$pass');
if (!$con)
{
die("Could Not Connect: " . mysql_error());
}
mysql_select_db("$username",$con);
$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,'$_POST[items]','$_POST[qty]')";
mysql_query($sql,$con);
mysql_close($con);
}
?>
The first thing you need to do is update in a foreach loop so that you are inserting one row for each checked item and secondly you need to relate the quantity fields to those items by using an array.
Change your Quantity field names to an array including the code for the items:
<input type="text" name="qty['SO1']" size ="2"/><br/>
<input type="text" name="qty['SO2']" size="2"/><br/>
etc ...
Then in your PHP:
foreach ($_POST['items'] as $item) {
foreach($_POST['qty'] as $key => $value) {
$quantity = 0;
if ($key == $item) {
$quantity = $value;
}
}
$sql = "INSERT INTO Order_Information(Order_Items,Order_Quantity) VALUES ('$item', '$quantity')";
.
.
}
HTML
<input type="checkbox" name="items" value="SH01" />
<input type="text" name="qty_SH01" ..../>
PHP
foreach ($_POST as $key => $val) {
if (!preg_match("/^SH/", $key)) continue;
$qty = $_POST['qty_' . $key];
$sql = "INSERT INTO Order_Information(Order_Items,Order_Quantity) VALUES ('$key', '$qty')";
}
When using the $_POST[items], you forgot about the apostrophes - $_POST['items'].
To get all checked checkboxes, you need a loop:
if(!empty($_POST['check_list']))
{
foreach($_POST['items'] as $item)
{
....
}
}
Hey guys I've been trying to do a code where I submit a form from a PHP Order Page so that it can update the MySQL Database with the required information
I've got the Order PHP Code Here:
<form action="http://zim.cs.uow.edu.au/~ga420/order.php" 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" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" 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[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" 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: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN3" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN4" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN5" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN6" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<br />
</td>
<td>
<br />
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<br />
</td>
</tr>
</tr>
</table>
<br />
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])){
$conn = mysql_connect('url','username','password');
if (!$con){
die("Could Not Connect: " . mysql_error());
}
mysql_select_db("db",$conn);
$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,$_POST[items]','$_POST[qty]')";
mysql_query($sql, $con);
mysql_close($con);
}
?>
Obviously my username and password I won't display but when I hit the submit button it says that it cannot connect.
You can try the form yourself on this website:
http://zim.cs.uow.edu.au/~ga420/order.php
How come it is saying that I can't connect when clearly I have been putting the right details in.
Can anyone help? this has been stressing me out :'(
Your help is appreciated greatly!!
You need to serialize all your inputs/quantities if you will have the same name "qty" in all fields. I will update my answer later if you do t get answer about this.
You had also small bugs on your code, notice this:
VALUES (null,'$_POST[items]','$_POST[qty]')"; - you were missing ' before $_POST[items]
$conn = mysql_connect('zim.cs.uow.edu.au','username','password'); - $conn with 2 "n"
So, a corrected version would be:
<?php
if (isset($_POST['submit'])){
$con = mysql_connect('url','username','password');
if (!$con){
die("Could Not Connect: " . mysql_error());
}
mysql_select_db("db",$con);
$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,'$_POST[items]','$_POST[qty]')";
mysql_query($sql, $con);
mysql_close($con);
}
?>
Change to this. You did some mistake on $conn and $con. Then, '$_POST[items]','$_POST[qty]' in query.
if (isset($_POST['submit'])){
$conn = mysql_connect('url','username','password');
if (!$conn){
die("Could Not Connect: " . mysql_error());
}
mysql_select_db("db",$conn);
$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,'$_POST[items]','$_POST[qty]')";
mysql_query($sql, $conn);
mysql_close($conn);
}
Hope this help