10/10/2018, 10:32
[PHP] Lỗi với combobox lấy giá trị!
Mình có đoạn code sau:
Vấn đề của mình là nó đã load dữ liệu từ table đổ ra combobox. Tuy nhiên, khi chọn 1 giá trị bất kỳ từ combobox thì nó ko thực thi được đoạn này:
Mong các bạn giúp!
Code:
<?php
$user = root;
$password = root;
$database = project;
// Connect to the database
$con = mysql_connect("localhost",$user,$password) or die ('Could not connect: ' . mysql_error());
mysql_select_db($database, $con);
// Create the form, post to the same file
echo "<form method='post' action='combo.php'>";
// Form a query to populate the combo-box
$query = "SELECT DISTINCT * FROM manga;";
// Successful query?
if($result = mysql_query($query)) {
// If there are results returned, prepare combo-box
if($success = mysql_num_rows($result) > 0) {
// Start combo-box
echo "<select name='item' onchange='location.href='manga.php?id='+this.value'>
";
echo "<option>-- Equipment --</option>
";
// For each item in the results...
while ($row = mysql_fetch_array($result))
// Add a new option to the combo-box
echo "<option value='$row[user_id]'>$row[user_name]</option>
";
// End the combo-box
echo "</select>
";
}
// No results found in the database
else { echo "No results found."; }
}
// Error in the database
else { echo "Failed to connect to database."; }
// Add a submit button to the form
echo "<input type='submit' value='Submit' /></form>";
?>
Code:
echo "<select name='item' onchange='location.href='manga.php?id='+this.value'> ";
Bài liên quan





Theo như đoạn code trên thì nó hiểu onchange='location.href=' => lỗi
onchange='location.href='manga.php?id=';
Thay =, đủ kiểu
echo "<select name='item' onchange='location.href="manga.php?id='+this.value">\n";
echo "<script language="javascript">function redirect(value){ location.href='manga.php?id='+value; }</script>"; echo "<select name='item' onchange='redirect(this.value)'> \n";