![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) | |
|
Registered User
Join Date: Nov 2006
Posts: 3
OS: Win
|
Hello guys,
i need your help please.. am trying to "connect" with Php a FORM to my mysql database so that i can execute like this any possible query that will result from the use of this form. My database keeps data for cars and the table that i made is here : Quote:
The form looks as follow : Code:
<form method="post" action="search.php"> <input type="text" name="search" size=25 maxlength=25> <select name="search2"> <option value="">""</option> <option value=skoda>fiat</option> <option value=hunday>hunday</option> <option value=bmw>reno</option> <option value=reno>toyota</option> <option value=fiat>skoda</option> <option value=mercedes>audi</option> <input type="Submit" name="Submit" value="Submit"> </form> And the not succesfull php code that i tried to write here : Code:
//connect to mysql
mysql_connect("localhost","labuerga","labuerga");
mysql_select_db("amaxadiko");
$search=$_POST["search"] ;
$search2=$_POST["search2"] ;
//get the mysql and store them in $result
$result = mysql_query("SELECT * FROM auto WHERE company = '" . $_POST['$search'] . "' AND model = '" . $_POST['search2'] ."'");
//grab all the content
while($r=mysql_fetch_array($result))
{
$marka=$r["company"] ;
$modelo=$r["model"] ;
//display the row
echo "$company <br> $model <br><br>";
}
At general, this that i dont understand the most is which & how we can write the correct query in the php code from the moment that every user that uses the FORM can according to his choices and combination to have a different query ? As you see am quite confused..much :) :( ..so plz try to help me guys and code examples are always better for me to understand Help to make it work.. Thanks and waiting for your answers and help, this was my 1st post to da forum ![]() Last edited by machineros : 11-05-2006 at 05:43 AM. |
|
|
|
|
|
|
#2 (permalink) |
|
Design Team
|
In the last code that does all the processing, towards the bottom I think you spelled "model" wrong. You spelled it "modelo". Maybe that's the problem? Everything else looks perfect to me.
__________________
![]() Nvu || Notepad++ || Apache || PHP || Keep TSF Alive "The great thing about a computer notebook is that no matter how much you stuff into it, it doesn't get bigger or heavier." |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Nov 2006
Posts: 3
OS: Win
|
DJ-Zep, finally is fixed by getting help & reading
..but i came to the point that i face an other problem now Look here how it seems my form and php part now : Code:
<form method="post" action="search.php">
<select name="search">
<option value="">""</option>
<option value="fiat">fiat</option>
<option value="hunday">hunday</option>
<option value="reno">reno</option>
<option value="toyota">toyota</option>
<option value="skoda">skoda</option>
<option value="audi">audi</option>
</select>
<input type="text" name="search2" size=25 maxlength=25>
<input type="Submit" name="Submit" value="Submit"> </form>
Code:
mysql_connect("localhost","nn","nnn");
mysql_select_db("amaxadiko");
$search=$_POST['search'];
$search2=$_POST['search2'];
$result = mysql_query("SELECT * FROM auto WHERE company = '$search' AND model = '$search2'");
$numRows = mysql_num_rows($result);
if( $numRows == "0" ){
echo "No Results Found";
} else {
while($r=mysql_fetch_array($result))
{
$company=$r['company'];
$model=$r['model'];
echo "$company<br> $model<br>";
}
}
How we can fix it in such a way so that when one of the 2 elements(select - input ) is empty then to dont write echo "No Results Found"; but to write the result of the element that is selected only . Par example, if is selected only in select SKODA, but the next input text is EMPTY then to dont write "No results found" but to write the SKODAs that exist in database . ..am waiting for your help ![]() |
|
|
|
|
|
#4 (permalink) |
|
Design Team
|
Would you mind giving me another example of what you're looking for? I think I know what you mean, but I'm not certain.
__________________
![]() Nvu || Notepad++ || Apache || PHP || Keep TSF Alive "The great thing about a computer notebook is that no matter how much you stuff into it, it doesn't get bigger or heavier." |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Join Date: Nov 2006
Posts: 3
OS: Win
|
I mean when we have this case :
![]() As you can see one of those 2 elements of the FORM the input text in this case is empty, so in this case the result that am going to take is the => echo "No Results" . But i want when one element is empty then to show-write results from the elemenets that are not empty. In this case par example, i want to write all skodas even that we havent set any model in the input and remains empty . So i want to get results when a field is empty and others are not and not the echo "No results". How we can make it ? plz help ![]() Last edited by machineros : 11-06-2006 at 01:27 AM. |
|
|
|
|
|
#6 (permalink) |
|
Design Team
|
I see what you're saying. I'm trying to compile a forevery statements nested within an if statement so that when the field is empty it will do what you want it to. I just need a little time to make sure everything is going right. I haven't forgotten about you!
![]()
__________________
![]() Nvu || Notepad++ || Apache || PHP || Keep TSF Alive "The great thing about a computer notebook is that no matter how much you stuff into it, it doesn't get bigger or heavier." |
|
|
|
![]() |
| Thread Tools | |
|
|