我試圖編寫一個窗體,從MySQL數據庫獲取一些數據,其餘的我必須自己填寫客棧。問題是,在add.php女巫插入到MySQL不要從窗體中獲取數據。 我的代碼是:窗體不會發送數據到mysql
<form action="add.php" method="post">
<table border="0px" align="center" width="300px">
<tr align="center">
<td><h2>Flight</h2></td>
<td><h2>Org</h2></td>
<td><h2>Dest</h2></td>
<td><h2>STD</h2></td>
<td><h2>ATD</h2></td>
<td><h2>Delay</h2></td>
<td><h2>NET</h2></td>
<td><h2>Gros</h2></td>
<td><h2>Core Material</h2></td>
<td><h2>ACS</h2></td>
<td><h2>Total sorted</h2></td>
</tr>
<?php
$con = mysql_connect("localhost","db","pass") or die('Could not connect: ' .mysql_error());
mysql_select_db("db", $con) or die(mysql_error());
$q="SELECT flightnr, org, dest, std FROM flight";
$sql = mysql_query($q) or die("MySQL ERROR: ".mysql_error());
while($row = mysql_fetch_array($sql))
{
$flightnr2 = $row['flightnr'];
$org2 = $row['org'];
$dest2 = $row['dest'];
$std2 = $row['std'];
}
?>
<tr>
<td><input type="text" name="flightnr" value="<?php echo $flightnr2;?>" /></td>
<td><input type="text" name="org" id="org" value="<?php echo $org2;?>" /></td>
<td><input type="text" name="dest" id="dest" value="<?php echo $dest2;?>" /></td>
<td><input type="text" name="std" id="std" value="<?php echo $std2;?>" /></td>
<td><input type="time" name="adt" id="adt" placeholder="ATD"></td>
<td><input type="time" name="delay" id="delay" placeholder="Delay"></td>
<td><input type="int" name="net" id="net" placeholder="NET"></td>
<td><input type="int" name="gros" id="gros" placeholder="Gros"></td>
<td><input type="int" name="core" id="core" placeholder="Core Material"></td>
<td><input type="int" name="acs" id="acs" placeholder="ACS"></td>
<td><input type="int" name="tot" id="tot" placeholder="Total sorted"></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
add.php:
<?php
$con = mysql_connect("localhost","db","pass") or die('Could not connect: ' .mysql_error());
mysql_select_db("db", $con) or die(mysql_error());
$date = date("D-m-Y");
$flightnr = $_POST['flightnr'];
$org = $_POST['org'];
$dest = $_POST['dest'];
$std = $_POST['dest'];
$adt = mysql_real_escape_string($_POST['adt']);
$delay = mysql_real_escape_string($_POST['delay']);
$net = mysql_real_escape_string($_POST['net']);
$gros = mysql_real_escape_string($_POST['gros']);
$core = mysql_real_escape_string($_POST['core']);
$acs = mysql_real_escape_string($_POST['acs']);
$tot = mysql_real_escape_string($_POST['tot']);
$sql="INSERT INTO fly (date, flightnr, org, dest, std, adt, delay, net, gros, core, acs, tot)VALUES('$date', '$flightnr', '$org', '$std', '$adt', '$delay', '$net', '$gros', '$core', '$acs', '$tot')";
$result=mysql_query($sql);
if($result){
echo "Successful";
echo "<BR>";
}
else {
echo "ERROR";
}
?>
任何想法,我怎麼能得到它的工作...
你在哪裏學來編程這樣的形式?我很好奇。我在Stack Overflow上看到了很多這樣的代碼,並且想知道人們在哪裏獲得它們的引用。 – tadman
我在我的代碼中嘗試了幾件事情,刪除了som錯誤..,並得到了一些新的..:P我認爲我做了一些正確的..,並得到了信息,以add.php。但是當我運行該腳本時,我遇到了錯誤。有人可以看看這些文件,看看我做錯了什麼嗎? – xzibiz