Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

No results displayed when searching mysql

New Here ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

Hello!
When I search mysql database using the following code all I get is a white page. No results indicating there was any error or indication that the database or table couldn't be selected. What am I doing wrong? Any and all help will be greatly appriecated!

Thank you,
Amanda

<?php

DEFINE ('DB_USER', 'manda');
DEFINE ('DB_PASSWORD', '*****');
DEFINE ('DB_HOST', '**.***.**.***');
DEFINE ('DB_NAME', 'products');

$dbc = @MySQL_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

@MySQL_select_db (DB_NAME_ OR die ('Could not select the database; ' .
mysql_error() );
$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM products WHERE item number LIKE '%$search%'");

//grab all the content
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
//modify these to match your mysql table columns

$image=$r["title"];
$item number=$r["message"];
$title=$r["who"];
$description=$r["date"];
$price=$r["time"];

//display the row
echo "$image <br> $item number <br> $title <br> $description | $price <br>";
}

?>

---Of course I put n the correct info for the database connection, I just substitued it when I pasted the script. All the rest of the script is exactly what I used.
TOPICS
Server side applications

Views

670
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 20, 2007 Mar 20, 2007

Copy link to clipboard

Copied

SexyManda85 wrote:
> Hello!
> When I search mysql database using the following code all I get is a white
> page. No results indicating there was any error or indication that the database
> or table couldn't be selected. What am I doing wrong? Any and all help will be
> greatly appriecated!

When you get a blank page, it usually means that display_errors is
turned off. However, you have also used the error control operator (@)
in a couple of places, so error messages are also being suppressed by
your own script.

Check that display_errors is on. Also remove @ from your script.
However, I suspect the problem is here:

> @mysql_select_db (DB_NAME_ OR die ('Could not select the database; ' .
> mysql_error() );

You are using a non-existent constant, DB_NAME_. Remove the underscore
after NAME.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 20, 2007 Mar 20, 2007

Copy link to clipboard

Copied

SexyManda85 wrote:

> Hello!
> When I search mysql database using the following code all I get is a white
> page. No results indicating there was any error or indication that the database
> or table couldn't be selected. What am I doing wrong? Any and all help will be
> greatly appriecated!
>

$item number=$r["message"];

Looks suspect to me.
Mick


> Thank you,
> Amanda
>
> <?php
>
> DEFINE ('DB_USER', 'manda');
> DEFINE ('DB_PASSWORD', '*****');
> DEFINE ('DB_HOST', '**.***.**.***');
> DEFINE ('DB_NAME', 'products');
>
> $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not
> connect to MySQL: ' . mysql_error() );
>
> @mysql_select_db (DB_NAME_ OR die ('Could not select the database; ' .
> mysql_error() );
> $search=$_POST["search"];
>
> //get the mysql and store them in $result
> //change whatevertable to the mysql table you're using
> //change whatevercolumn to the column in the table you want to search
> $result = mysql_query("SELECT * FROM products WHERE item number LIKE
> '%$search%'");
>
> //grab all the content
> while($r=mysql_fetch_array($result))
> {
> //the format is $variable = $r["nameofmysqlcolumn"];
> //modify these to match your mysql table columns
>
> $image=$r["title"];
> $item number=$r["message"];
> $title=$r["who"];
> $description=$r["date"];
> $price=$r["time"];
>
> //display the row
> echo "$image <br> $item number <br> $title <br> $description | $price <br>";
> }
>
> ?>
>
> ---Of course I put n the correct info for the database connection, I just
> substitued it when I pasted the script. All the rest of the script is exactly
> what I used.
>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 20, 2007 Mar 20, 2007

Copy link to clipboard

Copied

On Tue, 20 Mar 2007 11:37:44 +0000, David Powers <david@example.com>
wrote:

>> @mysql_select_db (DB_NAME_ OR die ('Could not select the database; ' .
>> mysql_error() );
>
>You are using a non-existent constant, DB_NAME_. Remove the underscore
>after NAME.


While that's true, the die should still display the message. I think
Mick's on the right track.

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 20, 2007 Mar 20, 2007

Copy link to clipboard

Copied

Gary White wrote:
> While that's true, the die should still display the message. I think
> Mick's on the right track.

Yep. PHP always chokes on the first mistake, so that's what I look for.
Then tackle them one by one.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 21, 2007 Mar 21, 2007

Copy link to clipboard

Copied

On Tue, 20 Mar 2007 23:14:16 +0000, David Powers <david@example.com>
wrote:

>Yep. PHP always chokes on the first mistake, so that's what I look for.
>Then tackle them one by one.


The difference being that the one you mentioned first would be a runtime
error. I get a compile error because of a missing closing parenthesis on
the same line you mentioned:

The original:
@mysql_select_db (DB_NAME_ OR die ('Could not select the database; ' .
mysql_error() );

With the constant name fixed and the closing parenthesis would be:

@mysql_select_db (DB_NAME) OR die ('Could not select the database; ' .
mysql_error() );

Once that's fixed, you get a compile error on this line (the one Mick
mentioned):

$item number=$r["message"];

I'm guessing it should be:

$item_number=$r["message"];

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 21, 2007 Mar 21, 2007

Copy link to clipboard

Copied

Gary White wrote:
> The difference being that the one you mentioned first would be a runtime
> error.

Sure, but if display_errors is off, you get a blank screen.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 21, 2007 Mar 21, 2007

Copy link to clipboard

Copied

Thank you for all your advise!!!! I am very new to this and this may seem like a rediculous question but where do I go to turn on display errors? Now, my second question is once I do that will I get error messages or will my script work and display my results? If this helps, I am using the php and mysql off of the Yahoo server which is hosting my website. (Right now I am also tring to connect to the database on my computer so that Dreamweaver will connect to it b/c Yahoo doesnt allow remote access. However, Dreamweaver wont connect to my local database either, so if you can assist w/that as well that would be wonderful! Thank you all again for the previous and continous help!
Manda

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 21, 2007 Mar 21, 2007

Copy link to clipboard

Copied

On Wed, 21 Mar 2007 12:39:36 +0000, David Powers <david@example.com>
wrote:

>Sure, but if display_errors is off, you get a blank screen.

True. However, a doSomething() or die("Some message"); will display Some
message if the function fails, regardless of display_errors. I know you
understand it, David. I'm just trying to be clear to anyone else who
might be reading this. The OP doesn't seem to have come back, so it's
probably all a moot point anyway.

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 21, 2007 Mar 21, 2007

Copy link to clipboard

Copied

Gary White wrote:
> True. However, a doSomething() or die("Some message"); will display Some
> message if the function fails, regardless of display_errors.

No, it won't - at least not in this case.

I didn't notice it first time, but there's no closing parenthesis after
the database name, which causes a parse error. Even when you correct
that, the problem that Mick spotted causes another parse error. Both
parse errors prevent anything appearing onscreen if display_errors is off.

There are at least three mistakes in that script. The one I spotted, the
one that Mick spotted, and the closing parenthesis that I've just
noticed. The following might work:

<?php

DEFINE ('DB_USER', 'manda');
DEFINE ('DB_PASSWORD', '*****');
DEFINE ('DB_HOST', '**.***.**.***');
DEFINE ('DB_NAME', 'products');

$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not
connect to MySQL: ' . mysql_error() );

@mysql_select_db (DB_NAME) OR die ('Could not select the database; ' .
mysql_error() );
$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM products WHERE item number LIKE
'%$search%'");

//grab all the content
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
//modify these to match your mysql table columns

$image=$r["title"];
$item_number=$r["message"];
$title=$r["who"];
$description=$r["date"];
$price=$r["time"];

//display the row
echo "$image <br> $item number <br> $title <br> $description |
$price <br>";
}

?>

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2007 Mar 22, 2007

Copy link to clipboard

Copied

On Wed, 21 Mar 2007 22:47:57 +0000, David Powers <david@example.com>
wrote:

>No, it won't - at least not in this case.

True in this case because of the compile errors that prevent it ever
being executed.


>There are at least three mistakes in that script. The one I spotted, the
>one that Mick spotted, and the closing parenthesis that I've just
>noticed. The following might work:

Those are the same three that I pointed out yesterday. ;-)

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2007 Mar 22, 2007

Copy link to clipboard

Copied

Gary White wrote:
> Those are the same three that I pointed out yesterday. ;-)

So, we finally agree. :-)

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2007 Mar 22, 2007

Copy link to clipboard

Copied

LATEST
On Thu, 22 Mar 2007 14:24:00 +0000, David Powers <david@example.com>
wrote:

>So, we finally agree. :-)


We've agreed all along. We just haven't communicated well. :-)

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines