Jump to content
Larry Ullman's Book Forums

lalarukh12

Members
  • Posts

    61
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by lalarukh12

  1. hey i am connected i checked by echo @mysql_ping() ? 'true' : 'false'; what else can be the error?
  2. Hi i am using this code for searching by name and getting some errors. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Search Contacts</title> </head> <p><body> <h3>Search Contacts Details</h3> <p>You may search either by first or last name</p> <form method="post" action="search.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="Search"> </form> </body> </html> </p> <style type="text/css" media="screen"> ul li{ list-style-type:none; } </style> </form> <p><a href="?by=A">A</a> | <a href="?by=B">B</a> | <a href="?by=K">K</a></p> <?php //end of search form script if(isset($_GET['by'])){ $letter=$_GET['by']; //connect to the database require_once ('../mysqli_connect.php'); //-query the database table $sql="SELECT designer_id, first_name, last_name FROM designers WHERE first_name LIKE '%" . $letter . "%' OR last_name LIKE '%" . $letter ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-count results $numrows=mysql_num_rows($result); echo "<p>" .$numrows . " results found for " . $letter . "</p>"; //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $first_name =$row['first_name']; $last_name=$row['last_name']; $designer_id=$row['designer_id']; //-display the result of the array echo "<ul>\n"; echo "<li>" . "<a href=\"search.php?id=$designer_id\">" .$first_name . " " . $last_name . "</a></li>\n"; echo "</ul>"; } } ?> errors: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search.php on line 65 results found for A Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search.php on line 71 can anyone help me plz?
  3. thanks for your reply. now i am using the following code to search a single table when user enters a keyword. <html> <head> <title>Search the Database</title> </head> <body> <html> <head> <title>Search the Database</title> </head> <body> <form action="searchlast.php" method="post"> Search: <input type="text" name="term" /><br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> </body> </html> <?php echo $_POST['term']; require_once ('mysqli_connect.php'); $term = $_POST['term']; $sql = mysql_query("select * from designers where first_name like '%$term%'"); $term = $_POST['term']; $sql = mysql_query("select * from designers where first_name like '%$term%'"); while ($row = mysql_fetch_array($sql)){ echo 'designer_id: '.$row['designer_id']; echo '<br/> First Name: '.$row['first_name']; echo '<br/> Last Name: '.$row['last_name']; echo '<br/><br/>'; } ?> and getting the following errors Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 30 Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 40 Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 48 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\searchlast.php on line 52 do someone know the solution please?
  4. hi thanks for your reply. i am using this code now to search a single table when user enters a first name. the code is : <html> <head> <title>Search the Database</title> </head> <body> <html> <head> <title>Search the Database</title> </head> <body> <form action="searchlast.php" method="post"> Search: <input type="text" name="term" /><br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> </body> </html> <?php echo $_POST['term']; require_once ('mysqli_connect.php'); $term = $_POST['term']; $sql = mysql_query("select * from designers where first_name like '%$term%'"); $term = $_POST['term']; $sql = mysql_query("select * from designers where first_name like '%$term%'"); while ($row = mysql_fetch_array($sql)){ echo 'designer_id: '.$row['designer_id']; echo '<br/> First Name: '.$row['first_name']; echo '<br/> Last Name: '.$row['last_name']; echo '<br/><br/>'; } ?> and i am getting these errors: Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 30 Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 40 Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 48 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\searchlast.php on line 52 do someone know the solution please?
  5. Actually there was another form in my header file and it was calling another page and this header page is included in this code register.php and the form it this code was also calling the same page as was in header file. when i removed the form form from header file , register.php started calling register.php. so resolved
  6. ok.... i setup the mail server as given in this forum and it worked. thanks alot.
  7. hi, i tried to send an email through a php code as given in the book but following error occured Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\email.php on line 47 i tried to fix it by trying alot of things searching from internet but can't solve .
  8. yes it calls register.php. actually i am making my first website and i am a student thats why this happens
  9. Notice: Undefined variable: first_name in C:\xampp\htdocs\includes\header.php on line 16 Notice: Undefined variable: last_name in C:\xampp\htdocs\includes\header.php on line 16 these errors come up when i echo
  10. <?php # Script 16.6 - register.php // This is the registration page for the site. require_once ('includes/config.inc.php'); $page_title = 'Register'; include ('includes/header.html'); if (isset($_POST['submitted'])) { // Handle the form. require_once ('mysqli_connect.php'); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p =$ad =$ph = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); }else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT customer_id FROM customers WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { // Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // Add the user to the database: $q = "INSERT INTO customers (email,pass, first_name, last_name, registration_date) VALUES ('$e',SHA1('$p'), '$fn', '$ln', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at YourDesigner.com. To activate your account, please click on this link:www.yourdesigner.com\n\n"; $body .= BASE_URL . 'activate.php? x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'],'Registration Confirmation', $body, 'From: lalarukh@yourdesigner.com'); // Finish the page: echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered.If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please re-enter your passwords and try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> <style type="text/css"> label { display:block; float: left; width: 10em; margin-right: 1em; text-align: left; } fieldset.submit { float: none; width: auto; border: 0 none #FFF; padding-left: 12em; } </style> <p> First fill the registeration form and register yourself before you can order. A confirmation email will be sent to your email address upon registering. </p> <h1>Register</h1> <form action="register.php" method="post" style="border:medium" > <div class="fieldset" align="center"> <fieldset> <legend><b>Register<b></legend> <p><label>First name:</label><input type="text" name="first_name" size="20" maxlength= "20" value="<?php if (isset($trimmed ['first_name'])) echo $trimmed ['first_name']; ?>" /> </p> <p><label>Last Name:</label> <input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed ['last_name'])) echo $trimmed ['last_name']; ?>" /></p> <p><label>Email:</label> <input type="text" name="email" size="20" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> </p> <p><label>Password:</label> <input type= "password" name="password1" size="20" maxlength="20" /></p> <p><small><i>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></i></p> <p><label>Confirm Password:</label> <input type="password" name="password2" size="20" maxlength="20" /></p> </fieldset> <fieldset> <div align="center"><input type="submit" name="submit" value="Register" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <?php // Include the HTML footer. include ('includes/footer.html'); ?> this is my code. when i click submit after entering the values it always returns the first page of my site instead of any error messages in case of leaving something or submitted message. what probably is wrong ?
  11. $q = "SELECT * FROM your_table WHERE first_name LIKE '%$first_name%' AND last_name LIKE '%$last_name%'"; this query returns nothing but when i use some alphabet like h between % this, then i get results matching with the alphabet. what should i do?
  12. yeah i just corrected it now it is giving no errors but it gives no results and returns the same page..... what is the problem now?
  13. Notice: Undefined index: first_name in C:\xampp\htdocs\includes\header.php on line 52 Notice: Undefined index: last_name in C:\xampp\htdocs\includes\header.php on line 53 Notice: Undefined variable: query in C:\xampp\htdocs\includes\header.php on line 56 Notice: Undefined variable: query in C:\xampp\htdocs\includes\header.php on line 62 Invalid query: Query was empty Whole query: it gives these errors
  14. actually i followed the same code as in the book php6 and mysql chapter ecommerce with different table and field names modified and i want to add a search form on the home page to let the users enter a keyword and it ll search the two designers and dresses tables. as they were artists and prints in the chapter and have the same fields as in chapter. what ll be the correct code then?
  15. <form action="browse_dresses.php" method="get"> <fieldset> <legend>Site Search</legend> <input type="text" name="a" value= "<? $product_search; ?>" /> <input type="submit" name="go" id="go" value="Search" /> </fieldset> <?php require_once ('../mysqli_connect.php'); $query = ("SELECT * FROM first_name,last_name, MATCH(first_name, last_name) AGAINST('$product_search') AS first_name FROM designers WHERE MATCH(first_name, last_name) AGAINST('$product_search') ORDER BY first_name DESC"); // Perform Query $results = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$results) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } // Store item information $chosen_item = mysql_fetch_array($results); ?> i am using this code and having a number of errors and have no idea how to fix
×
×
  • Create New...