1

I don't enter or enter any random info in search, result shows, "No Results Found" And I am okay with that but when I enter anything related to MySQL table shows error,

"**Fatal error: Call to undefined function mysql_fetch_assocc() in /home/opticfhb/public_html/vacationsbychoice.com/search_result.php on line 10".

I know page is able to connect to db.

Form:

<form name="form_search" method="post" action="search_result.php">
    <input name="search" id="search" type="text" value="Type the name of City, State or Place you are visiting.." onFocus="if (value == 'Type the name of City, State or Place you are visiting..') {value=''}" onBlur="if (value== '') {value='Type the name of City, State or Place you are visiting..'}" />

    <input id="from" type="date" value="Check In" onFocus="if (value == 'Check In') {value=''}" onBlur="if (value== '') {value='Check In'}" />

    <input id="to" type="date" value="Check Out" onFocus="if (value == 'Check Out') {value=''}" onBlur="if (value== '') {value='Check Out'}" />

    <input name="submit" type="submit" value="Search" />
</form>

PHP:

if(!isset($_POST['search'])) {
header("Location:index.php");
}

$search_sql="SELECT * FROM world_wise WHERE stat_province LIKE '%".$_POST['search']."%' or city LIKE '%".$_POST['search']."%'";

$search_query=mysql_query($search_sql);
if (mysql_num_rows($search_query)!=0) {
    $search_rs=mysql_fetch_assocc($search_query);
}

?>

Result:

<h2>Search Result</h2>
<?php if (mysql_num_rows($search_query)!=0) {
do { ?>

<p><?php echo $search_rs['name']; ?></p>

<?php   } while ($search_rs=mysql_fetch_assocc($search_query));

} else {
echo "No Results Found";

}
?>
user1978142
  • 7,946
  • 3
  • 17
  • 20
Sebastian
  • 286
  • 2
  • 10
  • Add error reporting to the top of your file(s) `error_reporting(E_ALL); ini_set('display_errors', 1);` – Funk Forty Niner May 05 '14 at 04:33
  • `mysql_fetch_assocc`. `assoc` **not** `assocc` – AyB May 05 '14 at 04:34
  • As stated above, you're using an invalid mysql syntax. Also why is there a closing curly brace just before the `while` loop in ` – asprin May 05 '14 at 04:40
  • I've also noticed that and will wait for OP to tell us. @asprin Edit: The OP's question has been edited and it now shows the "why". The question's code must have been improperly indented. – Funk Forty Niner May 05 '14 at 04:45
  • Thanks all for the answers. Yes I got it fixed, moreover I am gonna use error reporting to. It was stupid me. New to php. – Sebastian May 05 '14 at 04:57
  • You're welcome @Sebastian do read what I have in my answer though. – Funk Forty Niner May 05 '14 at 04:57
  • I have got this strange problem now where it says,"Notice: Undefined index: name in /home/opticfhb/public_html/vacationsbychoice.com/search_result.php on line 226" For demo please visit www.vacationsbychoice.com and enter winter in search. Any help would be appreciated. – Sebastian May 05 '14 at 05:03

3 Answers3

3

Simple; change both instances of mysql_fetch_assocc to mysql_fetch_assoc (a typo)
There are 2x c's instead of one at the end of the function's name.

Use error reporting at the top of your files when in production mode.

error_reporting(E_ALL); ini_set('display_errors', 1);


Footnotes:

Your present code is open to SQL injection. Use prepared statements, or PDO.

mysql_* functions deprecation notice:

http://www.php.net/manual/en/intro.mysql.php

This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.

Documentation for MySQL can be found at » http://dev.mysql.com/doc/.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
0

I think it's a simple typo: mysql_fetch_assoc(), not mysql_fetch_assocc().

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
  • I have got this strange problem now where it says,"Notice: Undefined index: name in /home/opticfhb/public_html/vacationsbychoice.com/search_result.php on line 226" For demo please visit www.vacationsbychoice.com and enter winter in search. Any help would be appreciated. – Sebastian May 05 '14 at 05:05
0

As you can see you are using wrong mysql function mysql_fetch_assocc, its mysql_fetch_assoc

if(!isset($_POST['search'])) {
header("Location:index.php");
}   
$search_sql="SELECT * FROM world_wise WHERE stat_province LIKE '%".$_POST['search']."%' or city LIKE '%".$_POST['search']."%'";
$search_query=mysql_query($search_sql);
if (mysql_num_rows($search_query)!=0) {
$search_rs=mysql_fetch_assoc($search_query);
}
?>

If you are not sure about the functions you are using , try to put debug mode on , in short make error_reporting ON always to display errors

v2solutions.com
  • 1,439
  • 9
  • 8