Jump to content

BlackWidow

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

BlackWidow's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for your help, it is now sorted and please accept my apologies if I have upset anyone for posting on another forum.
  2. Hi Pikachu2000, I have used a debugger and it comes back with the error message: Notice: Undefined index: make on line 43 and Notice: Undefined index: model on line 44. These lines relate to the following $make = $_POST['make']; $model = $_POST['model']; I can't see what is wrong with them. I'm off to my paying job now, so please accept my apologies if I don't answer anymore replies today.
  3. Hi Pikachu2000, sorry, If I search using the model field only, for example if I use sonic as the search criteria it brings back a list of all of the canoes with sonic in the model field. If I search using the make field only, for example if I use pyr as the search criteria it brings back a list of all of the canoes in the database, instead of all of the canoes made by Pyranha. This is the bit that doesn't work.
  4. Hi cyberRobot, the search brings back a list of all the canoes in the database.
  5. Hi cyberRobot, tried that doesn't make any difference. What I can't understand is that the model field works ok, it's just the make field that doesn't work. I'm completely confused
  6. Thank you ManiacDan, I hadn't realised I had done that. Normally my user, password details are all in one file that is brought in. I have changed them all now. Checked the database and it is ok. Thank you again
  7. Hi, can anyone see what is wrong with this code. The search works ok on the model field, but will not work on the make field. <?php include("canoe_header.php"); ?> <div id ="container"> <div id="content"> <div id="header"> <div id="midd"> <img src="canoe_image.jpg" width="850" height="160" alt="Search Canoes" /> </div> </div> <div id = "middle"> <h2>Edit Canoes/Kayaks</h2> <?php $make = $_POST['make']; $model = $_POST['model']; if ((!isset($make)) || (!isset($model))) { ?> <p> Search for the canoe or kayak by Make and/or Model. </p> <p> Click on edit underneath the canoe or kayak that you wish to edit. </p> <form method="post" action="update_canoes.php"> <fieldset> <h2>Please enter search details.</h2> <p><label for="make">Make:</label><input type="text" name="make"/><br /></p> <p><label for="model">Model:</label><input type="text" name="model"/></p> <p class="submit"><input type="submit" name="submit" value="Search Canoes/Kayaks"/></p> </fieldset> </form> <?php } else { $hostname = "localhost"; $username = "changeme"; $password = "changeme"; $database = "changeme"; $con = mysql_connect("$hostname", "$username", "$password"); mysql_select_db("$database"); if(!$con) { echo "Cannot connect to database." . mysql_error();; exit; } if(!mysql_select_db("$database")) { echo "Unable to select database: " . mysql_error(); exit; } //query to see if there is a record which matches $sql="SELECT * FROM canoes WHERE make LIKE '%$make%' OR model LIKE '%$model%'"; $rs = mysql_query($sql,$con); //run the query if(!$rs) { echo "Cannot run query."; exit; } if (mysql_num_rows($rs) == 0) { echo "Sorry no canoes or kayaks can be found.."; exit; } while ($row = mysql_fetch_assoc($rs)) { echo '<table class="search1"> <tr><th width="20">ID</th><th width="40">Make</th><th width="65">Model</th><th width="75">Colour</th><th width="75">Type</th> <th width="50">Location</th><th width="100">Comments</th><th width="250">Image</th></tr> <tr><td width="20">' . $row['id'] . '</td><td width="40">' . $row['make'] . '</td><td width="65">' . $row['model'] . '</td> <td width="75">' . $row['colour'] . '</td><td width="75">' . $row['type'] . '</td><td width="50">' . $row['location'] . '</td> <td width="100">' . $row['comments'] . '</td><td width="250">' . $row['image'] . '</td></tr> <tr><td colspan="2" width="100"><a href="edit_canoes.php?id=' . $row['id'] . '">Edit Record</a></td></tr> </table>'; echo "<br />"; } mysql_free_result($rs); mysql_close($con); } ?> <?php include("canoe_footer.php"); ?> </div> </div> <?php include("canoe_menu.php"); ?> </div> </body> </html>
  8. hi ken2k7 thank you for your kelp it appears to be working now.
  9. Hi, Done what you suggested, it is working now. Why has it worked sometimes ang not other times though?
  10. I have having problems with the following code, sometimes it will login and carry the session to the next page, sometimes it logs in but doesnt carry the session to the next page. Can anyone see why? It has me flumuxed. <?php //$uname = ""; //$pword = ""; //$errorMessage = ""; //========================================== // ESCAPE DANGEROUS SQL CHARACTERS //========================================== function quote_smart($value, $handle) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value, $handle) . "'"; } return $value; } if ($_SERVER['REQUEST_METHOD'] == 'POST'){ $uname = $_POST['username']; $pword = $_POST['password']; $uname = htmlspecialchars($uname); $pword = htmlspecialchars($pword); //========================================== // CONNECT TO THE LOCAL DATABASE //========================================== $hostname = "removed"; $username = "removed"; $password = "removed"; $database = "removed"; $db_handle = mysql_connect("$hostname", "$username", "$password"); $db_found = mysql_select_db("$database", $db_handle); if ($db_found) { //$uname = quote_smart($uname, $db_handle); //$pword = quote_smart($pword, $db_handle); $sql = "SELECT * FROM user WHERE uname = '$uname' AND pword = '$pword'"; $result = mysql_query($sql, $db_handle); if ($result) { $num_rows = mysql_num_rows($result); if ($num_rows > 0) { //$db_field = mysql_fetch_assoc($result); //$uname = $db_field['uname']; session_start(); $_SESSION['uname'] = $uname; $_SESSION['pword'] = $pword; header ("Location: loggon.php"); }else { $errorMessage = "Invalid Login."; session_start(); $_SESSION['uname'] = ''; $_SESSION['pword'] = ''; //========================================== // YOUR SIGNUP PAGE HERE //========================================== header ("Location: test_reg.php"); } } else { $errorMessage = "Error logging on - no results"; //header ("Location: reg.php"); } } else { $errorMessage = "Error logging on - last error"; } } ?> <?php include("member_header.php"); ?> <?php include("member_menu.php"); ?> <div id="content1"> <form name ="form1" method ="post" action ="logv1.php"> <fieldset> Username: <input type = "text" name ="username" value="<?php print $uname;?>" maxlength="20"><br /><br /> Password: <input type = "text" name ="password" value="<?php print $pword;?>" maxlength="16"><br /> <p> <input type = "submit" name = "submit" value = "Login"> </p> </fieldset> </form> <?php print $errorMessage;?> </div> </body> </html>
  11. 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.
  12. BlackWidow

    PHP

    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>
  13. Thank you I will try that
  14. New code. I have changed the word "query" to "sql" as above,
  15. Sorry, ok will do, Im new to this. Have changed code, still doesnt work.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.