doulang9521 2011-06-05 01:10
浏览 31

数据无法与数据库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)

  • 写回答

1条回答 默认 最新

  • doutan5798 2011-06-05 02:35
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端