Reputation: 117
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>";
?>
Upvotes: 0
Views: 72
Reputation: 411
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']..
Upvotes: 1
Reputation: 948
You are trying to use a variable that doesn't exist $_POST['submit']
. use:
$query = "SELECT s_id FROM states WHERE
state_name= '".$_POST['ok']."'";
Be sure to migrate to mysqli_*
see Hank's comment to your question.
Upvotes: 0