0

我正在尝试将我的表单值添加到我的数据库中,但我收到类似未定义索引的错误:在第 120 行提交一些代码是,

<?php

echo "</tr></table></form>";

$conn = mysql_connect('localhost','root','');

 mysql_select_db('itcompanylist',$conn);
 $result = mysql_query("SELECT state_name FROM `states` WHERE c_id =1");

$i = 0;

echo "<form method='post' action=''><table border='1' ><tr>";

while ($row = mysql_fetch_row($result)){
 // echo "<td><a href='#' onclick='someFunction()'>" .$row['0']. "</a> </td>";
 echo '<td><input type="submit" name="submit"  value="'.$row['0'].'"></td>'; 


  if ($i++ == 2) 
  { 
     echo "</tr><tr>";
     $i=0;
  }
}

echo "</tr></table></form>";

 ?>

动作在同一页面上触发,页面在下面,当动作触发到页面时,我遇到错误:未定义的索引:在第 120 行提交

<?php

 mysql_connect("localhost","root","");//database connection
    mysql_select_db("itcompanylist");

    $query  = "SELECT s_id FROM states WHERE `state_name` = '".$_POST['submit']."'";
$result1 = mysql_query($query);
$row = mysql_fetch_array($result1);

 $result2 = mysql_query("SELECT city_name FROM `city` WHERE s_id ='".$row['s_id']."'");

$i = 0;

echo "<form method='post' action='demo2.php'><table border='1' ><tr>";

while ($row = mysql_fetch_row($result2)){

  echo '<td><input type="submit" name="ok" value="'.$row['0'].'"></td>'; 



}



echo "</tr></table></form>";

 ?>
4

2 回答 2

1

请替换代码

echo '<td><input type="submit" name="submit" value="'.$row['0'].'"></td>'; 

代替

echo '<td><input type="submit" name="ok" value="'.$row['0'].'"></td>'; 

因为你打电话给 $_post['submit']..

于 2013-03-08T13:09:26.330 回答
0

您正在尝试使用不存在的变量$_POST['submit']。使用:
$query = "SELECT s_id FROM states WHEREstate_name= '".$_POST['ok']."'";
一定要迁移mysqli_*查看 Hank 对您的问题的评论。

于 2013-03-08T13:47:15.947 回答