我的代码存在问题。我尝试了不同的方法,但我没有找到解决方案。我从$get_id
表中获取golfers
。我想将$get_id
发布到名为courseid
的列中。我的代码现在所做的不是发布到courseid
,而是将$get_id
发布到我的索引id
。我希望索引id
自然地自动增加数字,并将$get_id
发布到courseid
列。请参阅下面的代码,如果您有解决方案,请告诉我。谢谢。
<?php
if (isset($_POST["submit"]) && $_POST["submit"] == "Submit")
{
for ($count = 1; $count <= 9; $count++)
{
$fields[$count] = "";
if (isset($_POST["field" . $count . ""]))
{
$fields[$count] = trim($_POST["field" . $count . ""]);
//echo $fields[$count] . "<br />";
}
}
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$coursename = mysql_real_escape_string($_POST['coursename']);
$courseid = mysql_real_escape_string($_POST['courseid']);
$hn = mysql_real_escape_string($_POST['hn']);
$id = mysql_real_escape_string($_POST['id']);
$id = mysql_real_escape_string($_GET["id"]);
$insert = "INSERT INTO holes (`coursename` ,`courseid` ,`hn` ,`id` ) VALUES('$coursename' ,'$courseid' ,'$hn' ,'$id');";
mysql_query($insert) or die(mysql_error());
$select = "SELECT `coursename` ,`courseid` ,`hn` ,`id` FROM `holes` WHERE id = '$courseid'";
$result = mysql_query($select) or die(mysql_error());
}
if (isset($_GET["id"]))
{
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$id = mysql_real_escape_string($_GET["id"]);
$select = "SELECT * FROM `golfers` WHERE `id` = '$id'";
$result = mysql_query($select) or die(mysql_error());
$fields = mysql_fetch_array($result, MYSQL_BOTH);
mysql_close($con);
}
else
{
header("Location:board.php");
}
?>
</script>
<style ="text-align: center; margin-left: auto; margin-right: auto;"></style><br><br><br>
</head>
<body>
<div
style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;">
<form action="" method="post";">
<div
style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br>
<table style="font-weight: normal; width: 100%; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<table
style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<tbody>
<tr>
<td style="width: 35%;">Course Name:</td><td><input id="coursename" name="coursename" maxlength="50" style="width: 100%;" type="text" value="<?php echo $fields[coursename]; ?>">
</tr>
<tr>
<td style="width: 10%;">Hole #:</td><td>
<select name="hn">
<option></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
</select>
</td>
</tr>
</tbody>
</table>
<p style="text-align: center;"><input name="submit" value="Submit"
class="submit" type="submit"></p>
</div>
</form>
</div>