我想做一个批量从表1添加入表2的php但是我添加不了.sets.php是一个循环表1+checkbox选择.stes02.php是添加的sql.sets.php基本上没问题.但是stes02.php却添加不了.希望各位大大能帮忙看看.感激.//sets.php<?php/* view.php */session_start();$host = "localhost";$username = "root";$password = "";$database = "assignment";
$connection = mysql_connect($host, $username, $password);mysql_select_db($database, $connection) or die("MysQL Error");
$sql = mysql_query("select * from subject");
?><html><body>
<table width="734" height="90" border="0" cellpadding="1" cellspacing="1"> <tr> <td width="730"></td> </tr></table><table width="733" border="0" cellspacing="1" cellpadding="1"> <tr> <td width="665" bgcolor="#0099FF">Student Information: [<a href="edit_s.php?=userID=<? echo $userID ?>">Edit</a>] [<a href="pl_request.php?userID=<? echo $userID ?>">Request</a>] </td> </tr></table><table width="734" border="0" cellspacing="1" cellpadding="1"> <tr> <td width="665" bgcolor="#00CCFF">Subject Information: [<a href="pl_adds.php?userID=<? echo $userID ?>">Add</a>] [<a href="view_sub.php?userID=<? echo $userID ?>">View & Update</a>] [<a href="subject_md.php">Multiple Delete</a>] [<a href="pl_sets.php?userID=<? echo $userID ?>">Set</a>] [<a href="pl_history.php?userID=<? echo $userID ?>">History</a>]</td> </tr></table><table width="731" border="0" cellspacing="1" cellpadding="1"> <tr> <td><?php echo "WELCOME BACK, ".$_SESSION['id']."";?></td> </tr></table>
<p> </p><form action="sets02.php" method="POST">
<?phpecho "<table border=1>";echo "<tr><th> </th><th>Name</th><th>Code</th><th>Date Added</th></tr>";while ($result = mysql_fetch_array($sql)){echo "<tr><td><input type=checkbox name=del[] id=del value=$result[id]></td><td>$result[name] </td><td> $result[code] </td><td> $result[date]</td></tr>";}
?></table><input type="submit" name="justset" value="set" id="justset"></form></body></html>
//sets02.php<?php
$host = "localhost";$username = "root";$password = "";$database = "assignment";
$connection = mysql_connect($host, $username, $password);mysql_select_db($database, $connection) or die("MysQL Error");$sql2 = mysql_query("select * from subject");$result = mysql_fetch_array($sql2);$id = $_REQUEST['del'];$count = count($id);
if($_POST['justset']){
for ($i=0; $i<$count; $i++){
$sql = mysql_query("insert into subjectoffer (name) values('.$id[$i].')where id='.$id[$i].'" );
}
if ($sql){print "Record successfully added<br>";print "<a href=subject_md.php>Click here to go back</a>";}elseecho "oh no";}
?>
$connection = mysql_connect($host, $username, $password);mysql_select_db($database, $connection) or die("MysQL Error");
$sql = mysql_query("select * from subject");
?><html><body>
<table width="734" height="90" border="0" cellpadding="1" cellspacing="1"> <tr> <td width="730"></td> </tr></table><table width="733" border="0" cellspacing="1" cellpadding="1"> <tr> <td width="665" bgcolor="#0099FF">Student Information: [<a href="edit_s.php?=userID=<? echo $userID ?>">Edit</a>] [<a href="pl_request.php?userID=<? echo $userID ?>">Request</a>] </td> </tr></table><table width="734" border="0" cellspacing="1" cellpadding="1"> <tr> <td width="665" bgcolor="#00CCFF">Subject Information: [<a href="pl_adds.php?userID=<? echo $userID ?>">Add</a>] [<a href="view_sub.php?userID=<? echo $userID ?>">View & Update</a>] [<a href="subject_md.php">Multiple Delete</a>] [<a href="pl_sets.php?userID=<? echo $userID ?>">Set</a>] [<a href="pl_history.php?userID=<? echo $userID ?>">History</a>]</td> </tr></table><table width="731" border="0" cellspacing="1" cellpadding="1"> <tr> <td><?php echo "WELCOME BACK, ".$_SESSION['id']."";?></td> </tr></table>
<p> </p><form action="sets02.php" method="POST">
<?phpecho "<table border=1>";echo "<tr><th> </th><th>Name</th><th>Code</th><th>Date Added</th></tr>";while ($result = mysql_fetch_array($sql)){echo "<tr><td><input type=checkbox name=del[] id=del value=$result[id]></td><td>$result[name] </td><td> $result[code] </td><td> $result[date]</td></tr>";}
?></table><input type="submit" name="justset" value="set" id="justset"></form></body></html>
//sets02.php<?php
$host = "localhost";$username = "root";$password = "";$database = "assignment";
$connection = mysql_connect($host, $username, $password);mysql_select_db($database, $connection) or die("MysQL Error");$sql2 = mysql_query("select * from subject");$result = mysql_fetch_array($sql2);$id = $_REQUEST['del'];$count = count($id);
if($_POST['justset']){
for ($i=0; $i<$count; $i++){
$sql = mysql_query("insert into subjectoffer (name) values('.$id[$i].')where id='.$id[$i].'" );
}
if ($sql){print "Record successfully added<br>";print "<a href=subject_md.php>Click here to go back</a>";}elseecho "oh no";}
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货