0

hello!
Being a newbie (70 years young) I an trying to complete this php code so my search-form with a multichoice-checkbox may return a selected response on a webpage from mysql 5.4 database.
So far I have this query that is working BUT returning ALL members from the DTB regardless of requested specialties or zip

WHAT I NEED TO DO:
I only need visitors to be able to retreive pet Service providers from our group, performing one or several requested services (checkbox) within the client zipcode (drop-down menu showing available zipcodes) - since providers go to the client's place.
a text entry would make the client entering HIs own zip code that is not nessessarily covered by the group so a dropdown menu (single zipcode choice) is preferable-showing only covered zip codes areas)

I know I am missing "WHERE specialty=??? and WHERE zip=??? on line 2, following the "SELECT from mydtb_table" query but all I tryed is returning syntax errors or blanc page..
Can anyone can help me finish this. Please?
I am using Mysql 5.5.40 and phpmyadmin 5.4

I made my HTML form using a software that wrote every code for me exepted that is only sending emails and POSt to the database,( not retreiving from a multicheckbox,) so I had to replace its php file with my own (that is
working exepted, as I said earlier, it is returning a webpage with the COMPLETE List from the DTB, REGARDLESS.

 <?php

** $result = mysql_query("SELECT * FROM wp_uvmj_participants_database", $db);**

 if (!$result) {
 die("Database query failed: " . mysql_error());
 }
while ($row = mysql_fetch_array($result)) {
 echo "<h2>";
 echo $row[company]."";
 echo "</h2>";
 echo "<p>";
 echo $row[first_name];
echo $row[specialty];

echo $row[sub_category];
echo $row[area];
echo $row[photo];
echo $row[bio];
echo "</p>";
 }
?>
</div>
 </body>
</html>

<?php
    mysql_close($db);
?>
2
Contributors
4
Replies
24
Views
2 Years
Discussion Span
Last Post by PierJean
0

Well for a start you need to specify the WHERE bit in youur query:

$result = mysql_query("SELECT * FROM wp_uvmj_participants_database WHERE zip='abcd123' AND specialty='abc123'", $db);

You will also need to put quote marks here:

echo $row['company']."";

While we're here, there are slightly neater ways of writing this:

while ($row = mysql_fetch_array($result)) {
    echo "<h2>".$row['company']."</h2>";
    echo "<p>".$row['first_name']." - ".$row['specialty']."</p>";
    echo "<p>".$row['sub_category']."</p>";
    echo "<p>".$row['area']."</p>";
    echo "<p>".$row['photo']."</p>";
    echo "<p>".$row['bio']."</p>";
}

Even still you should use OOP/classes and probably PDO/mysqli - but as a beginner it doesn't make too much difference ;)

0

Thank you for giving me hope,
I have been studying. experimenting, asking for 5 weeks now at 8 to 10 hours a day 7 days a week and the reason I did not give up is knowing I was close to it. You are actually the first one who gave me a real answer without letting me guessing.
however I tried to correct my codes (and learning in the process) but my returned page is blanc. (at least it does not say"syntax error"!>
To make sure I did not forget anything I then copied/pasted your code. The only thing I suppose you want me to do is replace the zip='abcd123' AND specialty='abc123'" with the real number and specialties ??? (I tried abc123 just in case but page was still blanc...(You can tell how newbie I am!!!
:)
I separated the avalable zip and specialties with comas and reported the specialties as they are written in my Database.
they are reported with capital letters and no underscore, could it be my problem? i/e Pet Sitting versus pet_sitting.

( I rather have the response to be like "Pet Sitting" on the result page)
If you do have some time to spare for me may be you could tell we what I am doing wrong?
You would have all my blessing on this Holiday Season and I would really beleive to Santa Claus again!
:)

<?php
 $db = mysql_connect("localhost","myDTB_user_name","DTB_password"); 
 if (!$db) {
 die("Database connection failed miserably: " . mysql_error());
 }
 $db_select = mysql_select_db("mydatabase_name",$db);
 if (!$db_select) {
 die("Database selection also failed miserably: " . mysql_error());
 }
?>
<html>
 <head>
 <title>members</title>
 </head>
 <body>  

 IN CONSTRUCTION. TRY OUT ONLY<br/>
 please try later.than you

 This is the results according to your selection
 if you have any question please call 702- 739-9591
 or email me pierjean@cox.net
<div class="cssstyle">
 <?php
$result = mysql_query("SELECT * FROM wp_uvmj_participants_database WHERE zip='89002, 89005, 89011, 89012, 89014, 89015, 89030, 89031, 89032, 89033, 89044, 
89052, 89074, 89081, 89084, 89085, 89086, 89087, 89101, 89102, 89103, 89104, 89106, 89107, 89108, 89109, 89110, 89113, 89115, 89117, 89118, 89119, 89120, 
89121, 89122, 89123, 89124, 89128, 89129, 89130, 89131, 89134, 89135, 89138, 89139, 89141, 89142, 89143, 89144, 89145, 89146, 89147, 89148, 89149, 89156, 
89161, 89165, 89166, 89169, 89178, 89179, 89183' AND specialty='Animal Massage, Hospice Care,Dog Training,Dog Reiki,Dog walking,Dog Yoga,House 
Sitting,Hotel Sitting,Overnight Stay, Pet Sitting,Puppy Specialist, Pet Taxi,Vet Tech'", $db);
if (!$result) {
 die("Database query failed: " . mysql_error());
 }
while ($row = mysql_fetch_array($result)) {
    echo "<h2>".$row['company']."</h2>";
    echo "<p>".$row['first_name']." - ".$row['specialty']."</p>";
    echo "<p>".$row['sub_category']."</p>";
    echo "<p>".$row['area']."</p>";
    echo "<p>".$row['photo']."</p>";
    echo "<p>".$row['bio']."</p>";
}
?>
</div>
 </body>
</html>

<?php
//Step5
 mysql_close($db);
?>
0

Hello

I have copied exctly the code above from Mattster but I Still cannot get my results. I have changed my database name to a more simple one to limit possible typo, I have check all names in colomns, they match.
Still when requesting a list of possbiel members in"zip"89144 and specialty "Dog Walking" that I know match one of the members, the result page is blank showing only the html sentence from the search.php file


IN CONSTRUCTION. TRY OUT ONLY<br/>
please try later.than you

This is the results according to your selection
if you have any question please Email us.
this is the html page with the form:
http://www.southernnevadapets.com/search/search.html

the result page after request:
http://www.southernnevadapets.com/search/search.php

my search.php file:

 <?php
 $db = mysql_connect("localhost","database_user","password"); 
 if (!$db) {
 die("Database connection failed miserably: " . mysql_error());
 }


 $db_select = mysql_select_db("database_name",$db);
 if (!$db_select) {
 die("Database selection also failed miserably: " . mysql_error());
 }
?>


<html>
 <head>
 <title>members</title>
 </head>
 <body>  

 IN CONSTRUCTION. TRY OUT ONLY<br/>
 please try later.than you

 This is the results according to your selection
 if you have any question please email us

<div class="cssstyle">
<?php
$result = mysql_query("SELECT * FROM participants_database WHERE zip='abcd123' AND specialty='abc123'", $db);
while ($row = mysql_fetch_array($result)) {
    echo "<h2>".$row['company']."</h2>";
    echo "<p>".$row['first_name']." - ".$row['specialty']."</p>";
    echo "<p>".$row['sub_category']."</p>";
    echo "<p>".$row['area']."</p>";
    echo "<p>".$row['photo']."</p>";
    echo "<p>".$row['bio']."</p>";
}
?>
</div>
 </body>
</html>

<?phphttps://www.daniweb.com/web-development/databases/mysql/threads/489364/what-would-be-the-php-code-for-when-responding-to-a-search-inquiry#
//Step5
 mysql_close($db);
?>

what am I doing wrong?
Thanks for any advice.

0

hum,sorry, a link came out for this page included in the code for some reason...here it is again:

<?php
 $db = mysql_connect("localhost","rivervi9_Juli052","JrML**11606"); 
 if (!$db) {
 die("Database connection failed miserably: " . mysql_error());
 }


 $db_select = mysql_select_db("rivervi9_wo2635",$db);
 if (!$db_select) {
 die("Database selection also failed miserably: " . mysql_error());
 }
?>


<html>
 <head>
 <title>members</title>
 </head>
 <body>  

 IN CONSTRUCTION. TRY OUT ONLY<br/>
 please try later.than you

 This is the results according to your selection
 if you have any question please call 702- 655-7307
 or email us snappsemail@cox.net
<div class="cssstyle">
<?php
$result = mysql_query("SELECT * FROM participants_database WHERE zip='abcd123' AND specialty='abc123'", $db);
while ($row = mysql_fetch_array($result)) {
    echo "<h2>".$row['company']."</h2>";
    echo "<p>".$row['first_name']." - ".$row['specialty']."</p>";
    echo "<p>".$row['sub_category']."</p>";
    echo "<p>".$row['area']."</p>";
    echo "<p>".$row['photo']."</p>";
    echo "<p>".$row['bio']."</p>";
}
?>
</div>
 </body>
</html>

<?php
mysql_close($db);
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.