PHP MSQL FORM查询将无法连接 [英] PHP MSQL FORM Query Won't Connect
问题描述
我一直试图做一个代码,我从PHP订单页面提交表单,以便它可以用所需的信息更新MySQL数据库。
我已经在这里订购PHP代码:
< form action =http://zim.cs.uow .edu.au /〜ga420 / order.phpmethod =post>
< tr>
< th>衬衫< / th>
< th>数量< / th>
< / tr>
< tr>
< td>
< br />
< input type =checkboxname =itemsvalue =SH01/>
< label for =rd1> Obey T恤:9.99美元< / label>
< / div>
< br />
< input type =checkboxname =itemsvalue =SH02/>
< label for =rd1> Obey教授:$ 9.99< / label>
< / div>
< br />
< input type =checkboxname =itemsvalue =SH03/>
< label for =rd1> Hustle T恤:9.99美元< / label>
< / div>
< br />
< input type =checkboxname =itemsvalue =SH04/>
< label for =rd1>嘻哈支持:$ 9.99< / label>
< / div>
< br />
< input type =checkboxname =itemsvalue =SH05/>
< label for =rd1> 90年代衬衫:9.99美元< / label>
< / div>
< br />
< input type =checkboxname =itemsvalue =SH06/>
< label for =rd1> DOPE Shirt:$ 9.99< / label>
< / div>
< br />
< br />
< / td>
< td>
< br />
< input type =textname =qtysize =2/>
< br />
< input type =textname =qtysize =2/>
< br />
< input type =textname =qtysize =2/>
< br />
< input type =textname =qtysize =2/>
< br />
< input type =textname =qtysize =2/>
< br />
< input type =textname =qtysize =2/>
< br />
< br />
< / td>
< / tr>
< tr>
< td>
< br />
< input type =checkboxname =items []value =SO1/>
< label for =rd1>鞋 - 红色鞋带:$ 19.99< / label>
< / div>
< br />
< input type =checkboxname =items []value =SO2/>
< label for =rd1>鞋 - 红色高帮:$ 19.99< / label>
< / div>
< br />
< input type =checkboxname =items []value =SO3/>
< label for =rd1>鞋子 - 白色:19.99美元< / label>
< / div>
< br />
< input type =checkboxname =items []value =SO4/>
< label for =rd1>鞋 - 黑色:$ 19.99< / label>
< / div>
< br />
< input type =checkboxname =items []value =SO5/>
< label for =rd1>鞋 - 黑色上衣:$ 19.99< / label>
< / div>
< br />
< input type =checkboxname =items []value =SO6/>
< label for =rd1>红色篮球:$ 19.99< / label>
< / div>
< br />
< br />
< / td>
< td>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< br />
< / td>
< / tr>
< tr>
< td>
< br />
< input type =checkboxname =items []value =SN1/>
< label for =rd1> Snapback项目符号:29.99美元< / label>
< / div>
< br />
< input type =checkboxname =items []value =SN2/>
< label for =rd1> Snapback:$ 29.99< / label>
< / div>
< br />
< input type =checkboxname =items []value =SN3/>
< label for =rd1> Snapback项目符号:29.99美元< / label>
< / div>
< br />
< input type =checkboxname =items []value =SN4/>
< label for =rd1> Snapback项目符号:29.99美元< / label>
< / div>
< br />
< input type =checkboxname =items []value =SN5/>
< label for =rd1> Snapback项目符号:29.99美元< / label>
< / div>
< br />
< input type =checkboxname =items []value =SN6/>
< label for =rd1> Snapback项目符号:29.99美元< / label>
< / div>
< br />
< br />
< / td>
< td>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< input type =textname =qty []size =2/>
< br />
< br />
< / td>
< / tr>
< / tr>
< / table>
< br />
< input type =submitname =submit>
< / form>
$ php
if(isset($ _ POST ['submit'])){
$ conn = mysql_connect('url' ,'用户名密码');
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);
}
?>
很明显,我的用户名和密码我不会显示,但是当我点击提交按钮时,无法连接。
您可以在此网站上自行尝试表单:
http://zim.cs.uow.edu.au/~ga420/order.php
任何人都可以帮忙吗?这一直在强调我:'(b / b)
您的帮助非常感谢!!
如果您在所有字段中都使用相同的名称qty,则需要序列化所有输入/数量。如果您没有得到有关此答案的信息,我会稍后更新我的答案。
$ b
您的代码中也存在一些小错误,请注意:
$ b
VALUES(null,'$ _ POST [ items]','$ _ POST [qty]');
- 您在$ _POST [items]
'
$ conn = mysql_connect('zim.cs.uow.edu.au','用户名','密码');
- $ conn with 2n
所以,一个修正后的版本会是:
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 INT O Order_Information(Order_ID,Order_Items,Order_Quantity)VALUES(null,'$ _ POST [items]','$ _ POST [qty]');
mysql_query($ sql,$ con);
mysql_close($ con);
}
?>
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);
}
?>
这篇关于PHP MSQL FORM查询将无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!