我正在嘗試獲取用戶使用複選框檢查的sql行並將該ID發佈到將用戶選定行保存到db的腳本中,以便他們可以在稍後的數據中提取「已保存」的行。PHP MySQL根據用戶複選框將行ID保存到數據庫
下面是我的代碼 - 問題是當我發佈複選框值顯示爲「1」,我不知道爲什麼會發生這種情況。所有複選框值都顯示爲「1」。
require('./wp-blog-header.php');
$current_user = wp_get_current_user();
$school = $_POST['school'];
$connection = mysql_connect('198.71.225.63:3306', 'newmslsuper', '');
mysql_select_db('msl_data');
$query = "INSERT INTO searches (ID, school, type) VALUES('$current_user->ID', '$school', '1')";
mysql_query($query);
$search = mysql_query("SELECT * FROM `data` WHERE `school` LIKE '%$school%'");
$count=mysql_num_rows($search);
if ($count==0) {
echo 'Sorry your search for'; echo " $school "; echo 'returned no results. Please try again.';
}
else {
$fields_num1 = mysql_num_fields($search);
echo "<form action='save.php' method='post'>";
echo "<p>Check the box next to a Scholarship you would like to save and hit the SAVE button.<p/><table><tr><th>Save Search</th>";
// printing table headers
for($i=0; $i<$fields_num1; $i++)
{
$field1 = mysql_fetch_field($search);
echo "<th>{$field1->name}</th>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_array($search)){
foreach($row as $rowarray)
while($row1 = mysql_fetch_row($search)){
echo "<tr>";
echo "<td><input type='checkbox' value='$rowarray' name='cell'></td>";
// $row is array... foreach(..) puts every element
// of $row1 to $cell1 variable
foreach($row1 as $cell1)
echo "<td>$cell1</td>";
echo "</tr>\n";
}
}
}
echo "<input type='submit' value='SAVE'>";
mysql_close(); //Make sure to close out the database connection
如果複選框被選中,您將始終將值設爲1。您需要做的是,根據數據庫標識值命名複選框。 – Maximus2012
你不應該那樣做。 http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – miken32