php - how to form values in to database

717

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

 ?>
814

Answer

Solution:

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']..

501

Answer

Solution:

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 tomysqli_* see Hank's comment to your question.

People are also looking for solutions to the problem: php - Error trying to get accesstoken

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.