旨在将数据输入数据库的php脚本有选择性地工作。五年级和十年级的数据进入,但所有其他成绩的数据不会出现。我已经检查了其他块,并且逻辑工作正常,它执行内部块,因为它应该不会将任何数据输入到数据库中。对于除第5或第10个等级以外的等级,第2个块得到执行,并且我已检查它是否回复了它应该输入数据库的正确值。并在sql()查询后使用回声,我也发现它的工作太多,所以不知道怎么回事,请帮助。无法将数据输入到mysql
这里是代码,让我知道,如果你们需要HTML表格太
<?php
$roll=$_POST['roll'];
$marks=$_POST['marks'];
$dbase=$_POST['std'];
$sec=$_POST['sec'];
$sec1=$_POST['sec1'];
$expire= time()+60;
if (empty($roll) || empty($marks) || ($dbase==0))
{
echo '<p align="center">You did not enter all data. Please go back and enter them.</p>';
echo '<FORM><p align="center"><INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1);return true;"></p></FORM>';
die();
}
else
{
if($dbase==5)
{
$temp="five";
}
if($dbase==6)
{
$temp="six";
}
if($dbase==7)
{
$temp="seven";
}
if($dbase==8)
{
$temp="eight";
}
if($dbase==9)
{
$temp="nine";
}
if($dbase==10)
{
$temp="ten";
}
if($dbase==11)
{
$temp="eleven";
}
if($dbase==12)
{
$temp="twelve";
}
if(($dbase==5)&&($sec=="0"))
{
echo '<p align="center">You did not enter all data. Please go back and enter them. 2</p>';
echo '<FORM><p align="center"><INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1);return true;"></p></FORM>';
die();
}
else
{
if($dbase<6)
{
$sect=$sec;
setcookie("tab", $temp, $expire, "/","skc-hs.com");
$host="127.0.0.1"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="data"; // Database name
$tbl_name=$temp; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// To protect MySQL injection (more detail about MySQL injection)
$roll = stripslashes($roll);
$marks = stripslashes($marks);
$roll = mysql_real_escape_string($roll);
$marks = mysql_real_escape_string($marks);
$sql="insert into $tbl_name (roll , marks, std, sec) values ('$roll' , '$marks' , '$dbase' , '$sect')";
mysql_query($sql);
header('Location: dcreate.html');
die();
}
}
if(($dbase!=10)&&($dbase!=5)&&($sec1=="0"))
{
echo '<p align="center">You did not enter all data. Please go back and enter them. 3</p>';
echo '<FORM><p align="center"><INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1);return true;"></p></FORM>';
die();
}
else
{
if(($dbase!=5)&&($dbase!=10))
{
$sect=$sec1;
setcookie("tab", $temp, $expire, "/","skc-hs.com");
$host="127.0.0.1"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="data"; // Database name
$tbl_name=$temp; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// To protect MySQL injection (more detail about MySQL injection)
$roll = stripslashes($roll);
$marks = stripslashes($marks);
$roll = mysql_real_escape_string($roll);
$marks = mysql_real_escape_string($marks);
$sql="insert into $tbl_name (roll , marks, std, sec) values ('$roll' , '$marks' , '$dbase' '$sect')";
mysql_query($sql);
header('Location: dcreate.html');
die();
}
}
if($dbase==10)
{
setcookie("tab", $temp, $expire, "/","skc-hs.com");
$host="127.0.0.1"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="data"; // Database name
$tbl_name=$temp; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// To protect MySQL injection (more detail about MySQL injection)
$roll = stripslashes($roll);
$marks = stripslashes($marks);
$roll = mysql_real_escape_string($roll);
$marks = mysql_real_escape_string($marks);
$sql="insert into $tbl_name (roll , marks, std) values ('$roll' , '$marks' , '$dbase')";
mysql_query($sql);
header('Location: dcreate.html');
die();
}
}
?>
结构(预计为表“十”)
列类型整理属性Null默认ExtraAction ID INT(11)否无AUTO_INCREMENT
辊VARCHAR(3)latin1_swedish_ci否无
马克SMALLINT(6)否无STD VARCHAR(2)latin1_swedish_ci否无
秒VARCHAR(1)latin1_swedish_ci表中的否无
结构10
列类型整理属性Null默认ExtraAction ID INT(11)否无AUTO_INCREMENT
辊VARCHAR(3)latin1_swedish_ci否无
马克SMALLINT (6)否无STD VARCHAR(2)latin1_swedish_ci否无
如果当我修改第二块这样
if(($dbase!=5)&&($dbase!=10))
{
$sect=$sec1;
echo "roll- ";
echo $roll;
echo " marks- ";
echo $marks;
echo " std- ";
echo $dbase;
echo " section- ";
echo $sect;
setcookie("tab", $temp, $expire, "/","skc-hs.com");
$host="127.0.0.1"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="data"; // Database name
$tbl_name=$temp; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// To protect MySQL injection (more detail about MySQL injection)
$roll = stripslashes($roll);
$marks = stripslashes($marks);
$roll = mysql_real_escape_string($roll);
$marks = mysql_real_escape_string($marks);
$sql="insert into $tbl_name (roll , marks, std, sec) values ('$roll' , '$marks' , '$dbase' '$sect')";
mysql_query($sql);
echo " done";
die();
}
当我在html表单中输入这些值时,它会回显“roll-12 marks-454 std- 7 section-B done”。我不明白为什么它不会只是在数据库中输入这些值
的var_dump($质数据库),你碰上第一个if()比较之前的查询,我不认为== 0是一种强(准确)足够的比较... – Cups 2012-08-16 11:03:18
看到表的结构会很有趣,因为它似乎插入有时4,有时3列。 – 2012-08-16 11:03:59
哦亲爱的你需要一些干的课 – TigerTiger 2012-08-16 11:04:21