Jump to content

Error at line 25


b0y

Recommended Posts

I can't fix the error
fhw6HVY.png

 

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. 

Link to comment
https://forums.phpfreaks.com/topic/287387-error-at-line-25/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/287387-error-at-line-25/#findComment-1474407
Share on other sites

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) 

Link to comment
https://forums.phpfreaks.com/topic/287387-error-at-line-25/#findComment-1474410
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/287387-error-at-line-25/#findComment-1474414
Share on other sites

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();
Link to comment
https://forums.phpfreaks.com/topic/287387-error-at-line-25/#findComment-1474424
Share on other sites

 

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

Link to comment
https://forums.phpfreaks.com/topic/287387-error-at-line-25/#findComment-1474477
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.