b0y Posted March 30, 2014 Share Posted March 30, 2014 I can't fix the error This is line 25 code: if (mysql_num_rows($results)==0) This is full code in case you need it: <?php $db = "user"; $tb = "clients"; $link = mysql_connect('localhost', 'root', ''); if (!$link) die (mysql_error()) ; else echo 'Connect to MySql Server - Success! <br>'; // Open Database - USE SEARCH ENGINE mysql_select_db($db , $link) or die(mysql_error()); // Retrieve table if (isset($_POST['Search'])) { $keywoord = $_POST['keyword']; $keywoord = trim($keywoord); $results = mysql_query($result = "SELECT * FROM clients WHERE name like '%".$keywoord. "%' \n" . "OR\n" . " address like '%". $keywoord. "%' \n" . "OR\n" . " contact like '%". $keywoord. "%' ;"); echo "<br><h2>Search Results:</h2><hr>"; if (mysql_num_rows($results)==0) { echo "Nothing was found! Please try Joogle! Again"; } else {while($row = mysql_fetch_array( $results, MYSQL_NUM)) { echo "Name: " . $row[1] . "<br>"; echo "Address: " . $row[2] . "<br>"; echo "Contact: " . $row[3] . "<br>"; // printf(" %s %s %s", $row[1], $row[2], $row[3]); echo "<br>"; echo "<hr>"; } } } mysql_close($link); ?> I don't know what's the problem. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 30, 2014 Share Posted March 30, 2014 99% of the time that error means your query failed. Use mysql_error to find out why. And by the way, don't include semicolons in queries. And also by the way, please try to switch to the mysqli or PDO functions. The mysql extension and its mysql_* functions are deprecated because they're old and slow and inefficient. Quote Link to comment Share on other sites More sharing options...
b0y Posted March 30, 2014 Author Share Posted March 30, 2014 99% of the time that error means your query failed. Use mysql_error to find out why. And by the way, don't include semicolons in queries. And also by the way, please try to switch to the mysqli or PDO functions. The mysql extension and its mysql_* functions are deprecated because they're old and slow and inefficient. But I have to use MySQL because of assessment I'm doing (TAFE) Quote Link to comment Share on other sites More sharing options...
.josh Posted March 30, 2014 Share Posted March 30, 2014 But I have to use MySQL because of assessment I'm doing (TAFE) If this "TAFE" thing expects you to use mysql_xxx functions then they are outdated and I have to wonder if it's worth being assessed by them... In any case, you didn't respond to the part where requinix pointed you at mysql_error Quote Link to comment Share on other sites More sharing options...
b0y Posted March 30, 2014 Author Share Posted March 30, 2014 Ah well what can you do? And yes I had a look at it and took my time to read and trying to understand all of them but still no fix. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 30, 2014 Share Posted March 30, 2014 You need to echo mysql_error to see what the error is. Post the full error message here and we'll try to help solve it for you. $results = mysql_query($result = "SELECT * FROM clients WHERE name like '%".$keywoord. "%' \n" . "OR\n" . " address like '%". $keywoord. "%' \n" . "OR\n" . " contact like '%". $keywoord. "%' ;"); // output mysql error if(!$results) echo 'DB Error: ' . mysql_error(); Quote Link to comment Share on other sites More sharing options...
b0y Posted March 31, 2014 Author Share Posted March 31, 2014 You need to echo mysql_error to see what the error is. Post the full error message here and we'll try to help solve it for you. $results = mysql_query($result = "SELECT * FROM clients WHERE name like '%".$keywoord. "%' \n" . "OR\n" . " address like '%". $keywoord. "%' \n" . "OR\n" . " contact like '%". $keywoord. "%' ;"); // output mysql error if(!$results) echo 'DB Error: ' . mysql_error(); Okay I just did that and this is what I got o.O http://prntscr.com/35pzmx Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 31, 2014 Share Posted March 31, 2014 yes, but did you read the output and try to solve this? the error is pretty self explanatory - Table user.clients doesn't exist. Quote Link to comment Share on other sites More sharing options...
b0y Posted April 1, 2014 Author Share Posted April 1, 2014 Okay guys thanks for the help. I tried it at TAFE and it was fully working. I don't know it's not working at home on my very own computer but anyway, sorry for wasting your time, guys. Thanks again. Really appreciated! <3 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 1, 2014 Share Posted April 1, 2014 You are getting that error because you do not have a clients table in your users database. So have you checked to make sure you have setup the database correctly on your home computer? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.