我想一次提交一個完整的信息表,並不能找到答案。向數據庫提交一組信息沒有任何問題,但我需要立刻在1到50之間侮辱相同的值。這裏有一個例子:插入多行到MySQL在一次
我們記錄單圈時間,因此,我們需要能夠填寫的表格上一個Web應用程序,其名稱的負荷,事件時間。因此,我們需要一次添加大量的SQL條目。
我曾嘗試只是複製和粘貼表格信息,但是這會導致一個空白集phpMyAdmin的數據。
下面是代碼:
<?php
$host = "localhost";
$databasename = "pe_results";
$databaseusername = "root";
$databasepassword = "";
$conn = mysql_connect("$host", "$databaseusername", "$databasepassword");
mysql_select_db("$databasename", $conn);
if (isset($_POST['Name'])) {
$Name = $_POST['Name'];
}
if (isset($_POST['Short'])) {
$Short = $_POST['Short'];
}
if (isset($_POST['Med'])) {
$Med = $_POST['Med'];
}
if (isset($_POST['Long'])) {
$Long = $_POST['Long'];
}
if (isset($_POST['VLong'])) {
$VLong = $_POST['VLong'];
}
if (isset($_POST['Extreme'])) {
$Extreme = $_POST['Extreme'];
}
if (isset($_POST['LJump'])) {
$LJump = $_POST['LJump'];
}
if (isset($_POST['HJump'])) {
$HJump = $_POST['HJump'];
}
if (isset($_POST['Shotputt'])) {
$Shotputt = $_POST['Shotputt'];
}
if (isset($_POST['Discuss'])) {
$Discuss = $_POST['Discuss'];
}
if (isset($_POST['Javelin'])) {
$Javelin = $_POST['Javelin'];
}
if (isset($_POST['Date'])) {
$Date = $_POST['Date'];
}
if (isset($_POST['Year'])) {
$Year = $_POST['Year'];
}
$i = count($Name);
for ($i=0;$i<10;$i++) {
$n = $Name[$i];
$s = $Short[$i];
$me = $Med[$i];
$lng = $Long[$i];
$slng = $VLong[$i];
$ext = $Extreme[$i];
$ljump = $LJump[$i];
$hjump = $HJump[$i];
$shot = $Shotputt[$i];
$disc = $Discuss[$i];
$jav = $Javelin[$i];
$date = $Date[$i];
$year = $Year[$i];
//and so on with more variable...
$sql="INSERT INTO results_main (`Name`, `Short`, `Med`, `Long`, `Vlong`, `Extreme`, `LJump`, `HJump`, `Shotputt`, `Discuss`, `Javelin`, `Date`, `Year`)
VALUES ('$n', '$s', '$me', '$lng', '$slng', '$ext', '$ljump', '$hjump', '$shot', '$disc', '$jav', '$date', '$year')";
}
$result = mysql_query($sql) or die(mysql_error());;
if($result){
echo"<br/>Everythings been saved";
echo "<BR>";
echo "<a href='index.php'>Back to the main page</a>";
}
else {
echo $result = mysql_query($sql,$conn) or die (mysql_error());
}
// close connection
mysql_close($conn);
?>
還可以找到以下
<?php
// Create connection
$con=mysqli_connect("127.0.0.1","root","","pe_results");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Uh oh, tell chris that " . mysqli_connect_error() . "NO DATA WILL BE SAVED";
}
?>
<a href="results.php"><div id="1" >Results</div></a>
<a href="record.php"><div id="2">Record</div></a>
<a href="overview.php"><div id="3">Overview</div></a>
<div id="4">Blank</div>
<form name="input_primary" action="process.php" method="post">
<font color="#FFFFFF"><strong>Date:</strong></font><input name="Date" type="date" />
<font color="#FFFFFF"><strong>Year:</strong></font><select name="Year">
<option value="7">Year 7</option>
<option value="8">Year 8</option>
<option value="9">Year 9</option>
<option value="10">Year 10</option>
<option value="11">Year 11</option>
<option value="12">Year 12</option>
<option value="13">Year 13</option>
</select>
<input type="submit" value="Save results!" name="submit" />
<table width="200" border="1px solid black" id="maintab">
<tr>
<th scope="col">Name</th>
<th scope="col">100m</th>
<th scope="col">200m</th>
<th scope="col">400m</th>
<th scope="col">800m</th>
<th scope="col">1500m</th>
<th scope="col">Long Jump</th>
<th scope="col">High Jump</th>
<th scope="col">Shotputt</th>
<th scope="col">Discus</th>
<th scope="col">Javelin</th>
</tr>
<tr>
<td>
<input name="Name" type="text" />
</td>
<td>
<input name="Short" type="text" size="10px" />
</td>
<td>
<input name="Med" type="text" size="10px" />
</td>
<td>
<input name="Long" type="text" size="10px" />
</td>
<td>
<input name="VLong" type="text" size="10px" />
</td>
<td>
<input name="Extreme" type="text" size="10px" />
</td>
<td>
<input name="LJump" type="text" size="10px" />
</td>
<td>
<input name="HJump" type="text" size="10px" />
</td>
<td>
<input name="Shotputt" type="text" size="10px" />
</td>
<td>
<input name="Discuss" type="text" size="10px" />
</td>
<td>
<input name="Javelin" type="text" size="10px" />
</td>
</tr>
你的意思是,你可以在50個不同的排50倍相同的值? – bestprogrammerintheworld
見[此](http://dev.mysql.com/doc/refman/5.0/en/repeat.html)。 – Kermit
nope,它有點難以解釋,在一個LAN上的網站,否則ID鏈接你。它基本上是這樣一個事件發生後填寫Excel電子表格,然後提交,這樣,就不會有20多名,20餘百米次,20餘次200米等等等等有在提交任何錯誤,並將其寫入到數據庫,但是所有字段是空白的。 –