旨在將數據輸入數據庫的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