gpt4 book ai didi

javascript - PHP 新手在将下拉值发布到 MySQL 数据库时遇到问题。我的表格格式也关闭了。任何人都可以对此有所了解吗?

转载 作者:行者123 更新时间:2023-11-30 22:41:25 24 4
gpt4 key购买 nike

建立一个足球预测网站。我正在从 DBMS 的固定装置表中获取主队名称和客队名称,每个固定装置都有相应的下拉框,以便用户可以预测比分。我无法让它工作。感谢您的帮助!

    //establish connection

<?php

$connection = mysql_connect('localhost', 'root', 'password');
mysql_select_db('mls');

$query = "SELECT * FROM fixtures WHERE Fixture_ID BETWEEN '1' and '10' ";
$result = mysql_query($query);

$num = mysql_num_rows($result);

if($num>0){
echo"<table>";

echo "<th>Home Team</th>";
echo "<th>Home Score</th>";
echo "<th>Away Score</th>";
echo "<th>Away Team</th>";

for($count=0;$count<$num; $count++){
$row = mysql_fetch_array($result);


echo"<tr>
<td>".$row['Home_Team']."</td>


<td>
<form id="myForm" method="post" action="process3.php">

<select name="Home_Score">
<select id='H".$count."'>


<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>

</select >
</td>

<td>

<form id="myForm" method="post" action="process3.php">

<select name="Home_Score">
<select id='A".$count."'>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>


</select>
</td>
<td>".$row['Away_Team']."</td>
</tr>";




}
echo"</table>";


<input type="submit" title="Submit the form">
</form>



}
?>
<html>

<?php

//process3.php file

<?php

include_once('db.php');


$Home_Score = $_POST['Home_Score'];
$Away_Score = $_POST['Away_Score'];

if(mysql_query("INSERT INTO user_prediction VALUES('$Home_Score', '$Away_Score')")){

$result = "Successfully Inserted";
else
$result = "Insert failed";

?>



//myscript.js file


?>

$("#sub").click(function(){

$.post( $("#myForm).attr("action"), $("#myForm:input").serializeArray(),
function (info){$("#result").html(info);});



});

$("#myForm").submit(function(){

return false;
});

最佳答案

虽然有很多事情可能会导致问题,但请注意:

<select name="Away_Score"> 
//count id for unique values in dropdown
<select id='A".$count."'>

$count 在此处将按字面意思表示为字符串“$count”,因为此代码未包含在 PHP 标记中。尝试将与此类似的代码实例更正为如下内容:

<?php
echo '<select name="Away_Score">';
//count id for unique values in dropdown
echo '<select id="A' . $count . '">';
?>

关于javascript - PHP 新手在将下拉值发布到 MySQL 数据库时遇到问题。我的表格格式也关闭了。任何人都可以对此有所了解吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31046437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com