zenrab Posted August 7, 2008 Share Posted August 7, 2008 Hello I am trying to create a simple contact management db. when the user enters a phone number the full recordset of the customer should be delivered or an empty form with the entered search telephone number already in place. I am getting the following error message when executing: Notice: Use of undefined constant submit - assumed 'submit' in /home/gourmet/public_html/control-panel/find13.php on line 24 Notice: Undefined index: submit in /home/gourmet/public_html/control-panel/find13.php on line 24 Line 24 refers to the .... if ($_POST[submit] == "Search") line. All code below. Any help would be greatly appreciated. ***************************** <body> <?php $host="localhost"; // Host name $username="ok"; // Mysql username $password="ok"; // Mysql password $db_name="ok"; // Database name error_reporting(E_ALL); $link = mysql_connect($host,$username,$password); if ( ! $link ) { die( "Couldn't connect to MySQL: ".mysql_error() ); } mysql_select_db( $db_name, $link ) or die ( "Couldn't connect to database: ".mysql_error() ); if ($_POST[submit] == "Search") { //Collect Form Data $string = $_POST['search']; //Issue SQL SELECT Statement $query = "SELECT * FROM contacts WHERE telephone1 = '$string'"; $result = mysql_query($query) or die(mysql_error()); $mysql_num = mysql_num_rows($result ); if ($mysql_num == 0) { print "<tr>"; print "<td>First Name:"; print "<td><input name='firstname' type='text'></td>"; print "</td>"; print "<td>Last Name:"; print "<td><input name='lastname' type='text'></td>"; print "</td>"; print "<td>Address 1:"; print "<td><input name='address2' type='text'></td>"; print "</td>"; print "<td>Address 2:"; print "<td><input name='address2' type='text'></td>"; print "</td>"; print "<td>Telephone 1:"; print "<td><input name='telephone1' type='text' value='"; echo $string; print "'></td>"; print "</td>"; print "<td>Telephone 2:"; print "<td><input name='telephone2' type='text'></td>"; print "</td>"; print "<td>Email:"; print "<td><input name='email' type='text'></td>"; print "</td>"; print "</tr>"; } else { // enter your code here if your query finds a customer with the number your searching for while($row = mysql_fetch_array($result)) { print "<tr>"; print "<td>First Name:"; echo $row['firstname']; print "</td>"; print "<td>Last Name:"; echo $row['lastname']; print "</td>"; print "<td>Address 1:"; echo $row['address1']; print "</td>"; print "<td>Address 2:"; echo $row['address2']; print "</td>"; print "<td>Telephone 1:"; echo $row['telephone1']; print "</td>"; print "<td>Telephone 2:"; echo $row['telephone2']; print "</td>"; print "<td>Email:"; echo $row['email']; print "</td>"; print "</tr>"; } } } ?> Many thanks Link to comment https://forums.phpfreaks.com/topic/118565-solved-problem-with-if-_postsubmit-quotsearchquot/ Share on other sites More sharing options...
zenrab Posted August 7, 2008 Author Share Posted August 7, 2008 Hello I appear to have resolved this problem. I replaced the .... if ($_POST[submit] == "Search") with ............. if (!isset($_POST['submit'])) and i have my results. Yay! Thanks again Link to comment https://forums.phpfreaks.com/topic/118565-solved-problem-with-if-_postsubmit-quotsearchquot/#findComment-610430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.