我是PHP的新手,我第一次做代码。我创建了一个表和插入查询,但是没有用 - 有人能告诉我我的错误吗?
HTML表单
<form action="placeimiorder.php" method="post">
<select name="opt"></option><optgroup label="Iphone checker">
<option value="Full Gsx Report">Iphone Full Gsx Report lock/unlock status and network - 0.40 Credits
<option value="Iphone lock/unlock">Iphone lock/unlock status till 4s - 0.05 Credits </option>
<option value="uk checkmen">uk checkmend full report - 60.00 Credits </option>
</option>
<optgroup label="UK">
<option value="audi">O2/Tesco uk iphone 3/3gs/4/4s/5 - 20.00 Credits </option>
<option value="audi">Three 3 Hutchison Uk all iphone (clean imei) - 25.00 Credits </option>
<option value="audi">vodafone all clean (iphone 3 3gs 4 4s and 5) - 30.00 Credits </option>
<option value="audi">Vodafone uk iphone 5s/5c (all clean) - 35.00 Credits</option>
</optgroup>
</select>
</form>
<!--Radio buttons-->
Single <input type="radio" name="f1" value="1">
Multi <input type="radio" name="f1" value="2"><br>
<form>
IMEI:* <input type="text" name="imei" placeholder="ENTER IMEI*">
Notes: <input type="text" name="notes" placeholder="ENTER NOTES*">
Responsive Email: <input type="text" name="email" placeholder="ENT Responsive Email*"><br><br>
<input type="submit" class="classname" value = "submit">
</form>
我认为有些问题的PHP代码:
<?php
include ("sess.php");
mysql_connect("localhost","root","");
mysql_select_db("jj");
$msg='';
$msg1='';
if(isset($_POST['submit']))
{
$opt =$_POST["select"]. "-" .
$f1 =$_POST["single"]. "-" .
$imei =$_POST["imei"]. "-" .
$notes =$_POST["notes"]. "-" .
$email =$_POST["email"];
$qry = "insert into table (opt,f1,imei,notes,email) values('{$opt}','{$f1}','{$imei}','{$notes}','{$email}')";
$sql=mysql_query($qry);
if ($sql)
{
$msg1="Record Added";
}
else
{
$msg="Error";
}
}
?>
答案 0 :(得分:0)
例如:
$query= "INSERT INTO user SET
username ='".$username."',
password ='".$username."',
name ='".$name."'";
mysql_query($query) OR die(mysql_error());
答案 1 :(得分:0)
您获得missing semicolon
(为什么要对所有帖子值进行联接)之后,从字段名称中获取所有帖子值以获取帖子数据必须与您在表单中使用的字段名称相同。 Also remove </form> after select
if(isset($_POST['submit'])) {
$opt =$_POST["opt"];
$f1 =$_POST["f1"];
$imei =$_POST["imei"];
$notes =$_POST["notes"];
$email =$_POST["email"];
$qry = "insert into table (opt,f1,imei,notes,email) values('$opt','$f1','$imei','$notes','$email')";
$sql=mysql_query($qry);
if ($sql) {
$msg1="Record Added";
}
else {
$msg="Error";
}
}
注意: - mysql_*
已弃用[{1}}或mysqli_*
也使用PDO
来转发帖子数据