开发者

Data can not be intered to Database PHP -- AFTER EDITING --

开发者 https://www.devze.com 2023-03-11 14:29 出处:网络
This is my last question https://stackoverflow.com/questions/6233894/data-can-not-be-intered-to-database-php

This is my last question

https://stackoverflow.com/questions/6233894/data-can-not-be-intered-to-database-php

I did some changes in both; the pages that has the text boxes and the action page.

In the first page, I made the text boxes have different names with each loop:

$count1=100;
$count2=200;
$count3=300;
$count4=400;

echo "<form action='ConfirmEnter.php' method='post'>";
echo "<table border cellpadding=3>"; 
echo "<tr>"; 
echo "<th>ID</th>";
echo "<th>MidTerm</th>"; 
echo "<th>Project</th>"; 
echo "<th>Final</th>";
echo "<th>Total</th>". "</tr>";

while($row1 = mysql_fetch_array($result1)) 
{ 
echo "<tr>";
echo "<td><input name='".$count1."' readonly='readonly' value='". $row1['ID'] ."'  size=5/></td> "; 
echo "<td><input type='text' name='".$count2."' size=5 value='0.0' /></td>";
echo "<td><input type='text' name='".$count3."' size=5 value='0.0' /></td>";
echo "<td><input type='text' name='".$count4."' size=5 value='0.0' /></td>";
echo "</tr>";
$count1++;
$count2++;
$count3++;
$count4++;
} 
echo "</table>"; 
echo "<input type='submit' value='Submit' />";
echo "</form>"; 

In the action page:

$count=1;
$count1=100;
$count2=200;
$count3=300;
$count4=400;

function addtwo($a = 0.0 , $b = 0.0 , $c = 0.0)
   {
          return ($a + $b + $c);
   }

while($row1 = mysql_fetch_array($result1)) 
 { 
  $id[$count] = $_POST['$count1'];
  $mt[$count] = $_POST['$count2'];
  $pr[$count]开发者_如何学编程 = $_POST['$count3'];
  $fi = $_POST['$count4'];
  $tot[$count] = addtwo($mt[$count]+$pr[$count]+$fi);
  echo $fi;
  mysql_query("INSERT INTO Marks (ID, Name, MidTerm, Project, Final, Total)
  VALUES ('$id[$count]', 'EMPTY', '$mt[$count]', '$pr[$count]', '$fi', '$tot[$count]')");
  $count++;
  $count1++;
  $count2++;
  $count3++;
  $count4++;
  }

The problem is still the same. The data can not be inserted to the database. I tested each line by print it using echo statement and I finaaly discovered that when I print the statements of $_POST it doesn't print anything ( as you can see in the code there is echo $fi)


I would guess that ID is defined as key, so you can't insert another row with the same ID. When my guess is right, use INSERT....ON DUPLICATE KEY UPDATE

But however, whenever an INSERT fails, mysql_error() can tell you why, so you should ask it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号