BlackWidow Posted March 19, 2009 Share Posted March 19, 2009 I keep getting the following message when I search for a name. Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in /home/users/uks50665/html/cowellfamily.org.uk/database/search16.php on line 21 Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in /home/users/uks50665/html/cowellfamily.org.uk/database/search16.php on line 21 The code I am using is <html> <body> <?php $page_title = 'Search Births'; //check if form has been submitted if (isset($_POST['submitted'])) { $hostname = "localhost"; require_once ("mysql_connect.php"); // Connect to the database //create function for escaping the data function escape_data ($data) { global $dbc; //need the connection if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string(trim($data), $dbc); } //end of function $errors = array(); // Initialize an error array //check for a surname if (empty($_POST['surname'])) { $errors[] = 'You have forgotten to enter a surname'; } else { $s = escape_data($_POST['surname']); } //check for a forename if (empty($_POST['forename'])) { $errors[] = 'You have forgotten to enter a forename'; } else { $f = escape_data($_POST['forename']); } if (empty($errors)) { //if everything is okay // create the query $query="SELECT birth.year, birth.surname, birth.forename, birth.district, birth.church, birth.abode, birth.dob, birth.bapDate, birth.parent, birth.fatherOccup, birth.note, FROM birth WHERE (birth.surname = 'surname') AND birth.forename = ('forename')"; $result = @mysql_query($query); //run the query if ($result > 0) { // if it ran okay, display the records echo "<p>There are no records to view</p>\n"; //fetch and print all the records while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo $row['year']; echo $row['surname']; echo $row['forename']; echo $row['district']; echo $row['church']; echo $row['abode']; echo $row['dob']; echo $row['bapDate']; echo $row['parent']; echo $row['fatherOccup']; echo $row['notes']; } mysql_free_result ($result); // free up the resources } else { // if it did not run ok echo '<p class="error">There are currently no records to view.</p>'; } } // end of if (empty($errors)) IF. } // end of the main submit conditional ?> <h2>Search births database</h2> <form action="search16.php" method="post"> <p>Enter the surname and forename details for the search</p> <p>Surname: <input type="text" name="surname" size="15" maxlength="15" value="<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>" /></p> <p>Forenames: <input type="text" name="forename" size="15" maxlength="15" value="<?php if (isset($_POST['forename'])) echo $_POST['forename']; ?>" /></p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/150235-php/ Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 I'm willing to guess that $dbc is not defined anywhere. Link to comment https://forums.phpfreaks.com/topic/150235-php/#findComment-788993 Share on other sites More sharing options...
BlackWidow Posted March 19, 2009 Author Share Posted March 19, 2009 Thank you I have declared it in the mysql_connect.php file, I had mispelt it in there. The error message is no longer there but it deosn't return anything from the table. Link to comment https://forums.phpfreaks.com/topic/150235-php/#findComment-789000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.