0

i am trying to add my form values in to my data base but i am getting error like Undefined index: submit in line no.120 some of code is,

<?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>";

 ?>

action is fire on same page an page is below,when action fire into page i am gatting error :Undefined index: submit in line no.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>";

 ?>
Nikunj Jagad
  • 117
  • 4
  • 4
    [**Please, don't use `mysql_*` functions in new code**](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) – hank Mar 08 '13 at 12:37

2 Answers2

1

please replace the code

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

instead of

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

beacuse you called $_post['submit']..

dp4solve
  • 411
  • 6
  • 18
  • That's just a notice, it's not a fatal error. Your page should still run regardless. It simply means that the variables combo1 and combo2 weren't initalized anywhere in your source code yet you're using them somewhere. In order to make sure it doesn't siplay that error put this line of code at the top of your page. – Nikunj Jagad Mar 19 '13 at 05:00
0

You are trying to use a variable that doesn't exist $_POST['submit']. use:
$query = "SELECT s_id FROM states WHEREstate_name= '".$_POST['ok']."'";
Be sure to migrate to mysqli_* see Hank's comment to your question.

IROEGBU
  • 948
  • 16
  • 33