2013-05-18 82 views
-1

我創建的表單不接收條目。php不通過mysql循環結果

這裏是index.html的:

<html> 
<body> 
<iframe name = "main_frame" src = "http://stelucir.com/entry_ac.php" style = "position:absolute; width:80%; height:70%; left:10%; top:12%;"> 
</iframe> 
<form name="form1" method="post" action="http://stelucir.com/entry_ac.php" target = "main_frame"> 
<div style = "position:absolute; width:80%; height:5%; left:0%; top:84%;">Image:</div> <input type="text" name="one" id="one" style = "position:absolute; width:80%; height:5%; left:10%; top:83%;"><br> 
<div style = "position:absolute; width:80%; height:5%; left:0%; top:89%;">Part Descr:</div><input type="text" name="two" id="two" style = "position:absolute; width:80%; height:5%; left:10%; top:88%;"><br> 
<div style = "position:absolute; width:80%; height:5%; left:0%; top:94%;">Email:</div> <input type="text" name="three" id="three" style = "position:absolute; width:80%; height:5%; left:10%; top:93%;"> 
<input type="submit" name="Submit" value="Submit" style = "position:absolute; height:5%; left:90%; top:93%;"> 
</form> 
</body> 
</html> 

這裏是entry_ac.php:

<?php 

$host="mysql7.namesco.net"; // Host name 
$username="djangofawkes"; // Mysql username 
$password="mypass"; // Mysql password 
$db_name="PH392701_corpses"; // Database name 
$tbl_name="part"; // Table name 

// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

// Get values from form 
$one=$_POST['one']; 
$two=$_POST['two']; 
$three=$_POST['three']; 

// Insert data into mysql 
$sql="INSERT INTO $tbl_name(one, two, three)VALUES('$one', '$two', '$three')"; 
$result = mysql_query("SELECT one, two, three FROM part"); 

//loops through results 
echo "<table border='1'>"; 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
    echo "<tr><td>"; 
    echo $row['one']; 
    echo "</td><td>"; 
    echo $row['two']; 
    echo "</td><td>"; 
    echo $row['three']; 
    echo "</td></tr>"; 
} 
echo "</table>"; 
mysql_free_result($result); 
?> 

<?php 
// close connection 
mysql_close(); 
?> 

在phpMyAdmin在MySQL數據庫I輸入:

CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment, 
`one` varchar(65) NOT NULL default '', 
`two varchar(65) NOT NULL default '', 
`three` varchar(65) NOT NULL default '', 
PRIMARY KEY (`id`) 
) ENGINE=MyISAM AUTO_INCREMENT=0 ; 

當我輸入到它不顯示數據庫結果的形式,問題似乎是它根本不會進入數據庫,因爲l oop似乎工作。 然而,它確實進入本地主機的數據庫並部分工作。在本地主機上,循環也可以工作。 Plz的幫助。

+0

它插入數據正確??? –

+0

爲了以防萬一,不要給你的數據庫信息! – rcpayan

回答

1

您沒有執行您的INSERT查詢

$sql="INSERT INTO $tbl_name(one, two, three)VALUES('$one', '$two', '$three')"; 

只需加上後

$mysql = mysql_query($sql) or die(mysql_error()); 

然後我想r記住你mysql_函數已被棄用,所以我建議你切換到mysqliPDO,事實上你有風險sql injection,看看這裏How can I prevent SQL injection in PHP?。您應該使用準備statment以避免任何風險

0

請注意,你不發出(忘了嗎?)INSERT命令...

// Insert data into mysql 
$sql="INSERT INTO $tbl_name(one, two, three)VALUES('$one', '$two', '$three')"; 
$result = mysql_query("SELECT one, two, three FROM part");