使用提交按钮插入数据 - PHP,MySQL

时间:2012-07-24 07:40:59

标签: php mysql

$a = mysql_query('SELECT cc.name, c.fullname,c.shortname FROM course c, category cc 
                  WHERE cc.id = c.categoryid');
 echo '<form action="" method="post">';
echo '<center><div style="margin-top:40px;"><input type="submit" name="submit" value="PUBLISH"></div></center>';    
echo '<table border="1" width="100%" style="border:1px solid lightgray;">
      <tr style="color:#808080;">       
        <th>CategoryName</th>
        <th>Course Fullname</th>
        <th>Course Shortname</th>
                    <th>Total</th>  
      </tr>';

        while ($row = mysql_fetch_assoc($a))
            {

                $categoryname = $row['name'];
                $coursename = $row['fullname'];
                $shortname = $row['shortname'];
                echo '<tr><td>'.$categoryname.'</td>
                          <td>'.$coursename.'</td>
                          <td>'.$shortname.'</td>
                          <td style="padding:17px;"><center><input type="text" size="4%" name="grade"></center></td></tr>';
if($_SERVER['REQUEST_METHOD']=='POST')
   {
       $total = $_REQUEST["grade"]; 
 $sql="INSERT INTO course_custom(category,fullname,shortname,total) VALUES('$categoryname', '$coursename', '$shortname','$total')";
       $result=mysql_query($sql);
}
}
    echo '</table>';         
echo '</form>';

Rightnow我能够使用上面的代码正确插入category,coursename和shortname,但是总列的所有行都会重复使用。

是否有人建议将每行的正确值插入数据库

0 个答案:

没有答案