View Full Version : Easy script problem
Hi how are you doing? what I am doing is when a user chooses Gender(male or female), country(Japan, Korea, or China), and age(18-35), it comes these datas from my database.
However my script is not working. Could you please help me out for it.
my php is 4.23
<?php
if(isset($_POST['formSubmitted'])) AND $_POST['formSubmitted']=="yes")
{
$dbconnect = mysql_connect("localhost", "username", "password");
if (!$dbconnect) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
if (! mysql_select_db("database") ) {
echo( "<p>Unable to locate the host " .
"database at this time.</p>" );
exit();
}
$gender=$_POST["gender"];
$country=$_POST["country"];
$age=$_POST["age"];
if($gender=="m"){
$query="select * from grils where gender='male'";
}
else
$query="select * from girls where gender='female'";
}
if($country=="j"){
$query="select * from girls where country='Japan' ";
}
elseif($country=="k"){
$query="select * from girls where country='Korea'";
}
else{
$query="select * from girls where country='China'";
}
if($age>=18 && $age<=35){
$query="select * from girls where age between 18 and 35";
}
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo("<p>itohideo.com found: " . $num_results . "</p>");
for($i=0; $i<$num_results; $i++)
{
$row=mysql_fetch_array($result);
echo"<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
echo"<tr>";
echo"<td width=70% align=right>";
echo "<strong>".($i+1).".Name: ";
echo htmlspecialchars( stripslashes($row["name"]));
echo"</td>";
echo"<td valign=top rowspan=4 align=right>";
echo"<img src=\"$row[images]\" width=180 height=160>";
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Country: ";
echo htmlspecialchars( stripslashes($row["country"]));
echo"</td>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["age"]));
echo"<td>";
echo "</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["gender"]));
echo"<td>";
echo "</tr>";
echo"<table>";
}
}else{
?>
<html>
<body>
<from method="post" action=<?php $_SERVER['PHP_SELF'];?>>
<font color="#34499F" face=verdana>Specific Search for friends</font>
Gender:<select name="gender">
<option value="m">Male</option>
<option value="f">Fmale</option>
</select>
Country:<select name="country" >
<option value="j">Japan</option>
<option value="k">Korea</option>
<option value="c">China</option>
</select>
From:<select name="age" >
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
to
<select name="age">
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
<input type="submit" name="sumbit" value="submit"><input type="reset" value="reset" name="reset"><br>
<input type="hidden" name="formSubmitted" value="yes">
</form>
</body>
</html>
It would help us if you gave abit more information to do with the error.
What is the error message you receive if any ??
One thing I did notice without looking at the rest till you give abit more indication as to the error is that you appear to have spelled one of the table names incorrectly in one of the query statements.
You have put 'grils' where I think you may mean 'girls'
:thumbsup:
Nightfire
11-23-2002, 12:46 AM
if($gender=="m"){
$query="select * from grils where gender='male'";
Spelled grils wrong
<edit>Guess I should read the first reply better. Wish humans didn't have stress, prolly why i didn't notice your reply, my appoligies wapster3 (new knickname to you from me, give most ppl I give respect to a knickname)</edit>
I fixed like this but not working now
I got an error
Parse error: parse error in /home/itohideo/public_html/spe.php on line 107
<?php
if(isset($_POST['submit']))
{
$dbconnect = mysql_connect("localhost", "itohideo_hide", "0810");
if (!$dbconnect) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
if (! mysql_select_db("itohideo_japan") ) {
echo( "<p>Unable to locate the host " .
"database at this time.</p>" );
exit();
}
$gender=$_POST["gender"];
$country=$_POST["country"];
$age=$_POST["age"];
if($gender=="m"){
$query="select * from girls where gender='male'";
}
else
$query="select * from girls where gender='female'";
}
if($country=="j"){
$query="select * from girls where country='Japan' ";
}
elseif($country=="k"){
$query="select * from girls where country='Korea'";
}
else{
$query="select * from girls where country='China'";
}
if($age>=18 && $age<=35){
$query="select * from girls where age between 18 and 35";
}
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo("<p>itohideo.com found: " . $num_results . "</p>");
for($i=0; $i<$num_results; $i++)
{
$row=mysql_fetch_array($result);
echo"<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
echo"<tr>";
echo"<td width=70% align=right>";
echo "<strong>".($i+1).".Name: ";
echo htmlspecialchars( stripslashes($row["name"]));
echo"</td>";
echo"<td valign=top rowspan=4 align=right>";
echo"<img src=\"$row[images]\" width=180 height=160>";
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Country: ";
echo htmlspecialchars( stripslashes($row["country"]));
echo"</td>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["age"]));
echo"<td>";
echo "</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["gender"]));
echo"<td>";
echo "</tr>";
echo"<table>";
}
}else{
?>
<html>
<body>
<from method="post" action=<?php echo $_SERVER['PHP_SELF'];?>>
<font color="#34499F" face=verdana>Specific Search for friends</font>
Gender:<select name="gender">
<option value="m">Male</option>
<option value="f">Fmale</option>
</select>
Country:<select name="country" >
<option value="j">Japan</option>
<option value="k">Korea</option>
<option value="c">China</option>
</select>
From:<select name="age" >
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
to
<select name="age">
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
<input type="submit" name="sumbit" value="submit"><input type="reset" value="reset" name="reset"><br>
</form>
</body>
</html>
<?}?>
<edit>Guess I should read the first reply better. Wish humans didn't have stress, prolly why i didn't notice your reply, my appoligies wapster3 (new knickname to you from me, give most ppl I give respect to a knickname)</edit>
:o
thankyou nightfire. Why have I earned your respect ?? i am pleased I have though. Nice to now. You already have had mine so I guess I should give you a new nickname to ... mmm
how about 'he's on fire'
:confused:
Yer don't ask !! the best I could come up with for now
0810 -
Check the code on line 107 and see if there are any errors.
I would check it but you may have more code besides this on the page.
If i am right in thinking this error message normally menas you have made some kind up typo mistake.
If you can't find it post whats on line 107 and perhaps we can have a look at it for you.
Good luck
:thumbsup:
Ok so I decided to have a look anyway. First I got the same error as you but after playing around and moving and adding some missing curly brackets. I got no errors. So perhaps I have fixed it.
Here you can try this now any
<?php
if(isset($_POST['submit']))
{
$dbconnect = mysql_connect("localhost", "itohideo_hide", "0810");
if (!$dbconnect) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
if (! mysql_select_db("itohideo_japan") ) {
echo( "<p>Unable to locate the host " .
"database at this time.</p>" );
exit();
}
$gender=$_POST["gender"];
$country=$_POST["country"];
$age=$_POST["age"];
if($gender=="m") {
$query="select * from girls where gender='male'";
}
else {
$query="select * from girls where gender='female'";
}
if($country=="j"){
$query="select * from girls where country='Japan' ";
}
elseif($country=="k"){
$query="select * from girls where country='Korea'";
}
else {
$query="select * from girls where country='China'";
}
if($age>=18 && $age<=35) {
$query="select * from girls where age between 18 and 35";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo("<p>itohideo.com found: " . $num_results . "</p>");
for($i=0; $i<$num_results; $i++)
{
$row=mysql_fetch_array($result);
echo"<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
echo"<tr>";
echo"<td width=70% align=right>";
echo "<strong>".($i+1).".Name: ";
echo htmlspecialchars( stripslashes($row["name"]));
echo"</td>";
echo"<td valign=top rowspan=4 align=right>";
echo"<img src=\"$row[images]\" width=180 height=160>";
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Country: ";
echo htmlspecialchars( stripslashes($row["country"]));
echo"</td>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["age"]));
echo"<td>";
echo "</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["gender"]));
echo"<td>";
echo "</tr>";
echo"<table>";
}
}
else {
?>
<html>
<body>
<from method="post" action=<?php echo $_SERVER['PHP_SELF'];?>>
<font color="#34499F" face=verdana>Specific Search for friends</font>
Gender:<select name="gender">
<option value="m">Male</option>
<option value="f">Fmale</option>
</select>
Country:<select name="country" >
<option value="j">Japan</option>
<option value="k">Korea</option>
<option value="c">China</option>
</select>
From:<select name="age" >
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
to
<select name="age">
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
<input type="submit" name="sumbit" value="submit"><input type="reset" value="reset" name="reset"><br>
</form>
</body>
</html>
<?
}
}
?>
druffus
11-23-2002, 05:34 PM
Your making to much work for yourself her. Send in the correct values from the form and make one query string, shouldn't be making multiple ones like that, just writes over them.
<?php
if(isset($_POST['submit']))
{
$dbconnect = mysql_connect("localhost", "itohideo_hide", "0810");
if (!$dbconnect) {
echo( "<p>Unable to connect to the database.</p>" );
exit();
}
if (! mysql_select_db("itohideo_japan") ) {
echo( "<p>Unable to locate the host database</p>" );
exit();
}
//Don't need variables, they are inherint in php
//Make your values for male and female be 'male' and 'female'
//If you send in the information you are looking to from the form you
//can just throw it into your query string and make it a lot easier on yourself
$query="SELECT * FROM girls WHERE gender=".$gender." AND country=".$country;
if($age>=18 && $age<=35) {
$query .= " AND age BETWEEN 18 and 35";
}
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
?>
THE NEW FORM BELOW
Gender:<select name="gender">
<option value="male">Male</option>
<option value="female">Fmale</option>
</select>
Country:<select name="country" >
<option value="japan">Japan</option>
<option value="korea">Korea</option>
<option value="china">China</option>
</select>
Good luck. Don't make things harder than they need to be, saves time and hassle.
Yea but not working yet form has to include age.
When a user looks for friend from my site, the one can choose 1. Gender(male or female), 2.Country(Japan,Korea, and China),3.Age(18-35).
Therefore, I need age form. Without it, users can't choose it.
Can I add this age or not?
From:<select name="age" >
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
to
<select name="age">
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
druffus
11-23-2002, 08:10 PM
Yes of course, sorry I was being brief. Use your same form and everything, just change the values of the options to be what you want to search for. Then you don't have to use those if and else tests.
The big thing when doing your query is to add all you conditions onto the where clause. As an example, with yours you had
if($gender=="m") {
$query="select * from girls where gender='male'";
}
else {
$query="select * from girls where gender='female'";
}
if($country=="j"){
$query="select * from girls where country='Japan' ";
}
elseif($country=="k"){
$query="select * from girls where country='Korea'";
}
else {
$query="select * from girls where country='China'";
}
if($age>=18 && $age<=35) {
$query="select * from girls where age between 18 and 35";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
What happened there was that when you ran your query with mysql_query() you only used the last query you made for age. So with your old one you weren't even searching for gender or country.
On the other hand with this one you are searching all of them
$query="SELECT * FROM girls WHERE gender=".$gender." AND country=".$country." AND age BETWEEN 18 and 35;
Understand what I mean?
Hope that helps some.
Hi how are you doing?
I have no error,but when I click submit button, it doesn't do anything. jsut stays same. When I click sumbit button, it suppose to come out my datas from my database. However, it is not working now.
I fixed like it, but not working my submit button.
could you take a look my scirpt again.
Thanks
<?php
if(isset($_POST['submit']))
{
$dbconnect = mysql_connect("localhost", "itohideo_hide", "0810");
if (!$dbconnect) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
if (! mysql_select_db("itohideo_japan") ) {
echo( "<p>Unable to locate the host " .
"database at this time.</p>" );
exit();
}
$gender=$_POST["gender"];
$country=$_POST["country"];
$age=$_POST["age"];
if($gender=="m") {
$query="select * from girls where gender='male'";
}
else {
$query="select * from girls where gender='female'";
}
if($country=="j"){
$query="select * from girls where country='Japan' ";
}
elseif($country=="k"){
$query="select * from girls where country='Korea'";
}
else {
$query="select * from girls where country='China'";
}
if($age>=18 && $age<=35) {
$query="select * from girls where age between 18 and 35";
}
$result = mysql_query($query);
if (!$result)
echo mysql_error();
$num_results = mysql_num_rows($result);
echo("<p>itohideo.com found: " . $num_results . "</p>");
for($i=0; $i<$num_results; $i++)
{
$row=mysql_fetch_array($result);
echo"<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
echo"<tr>";
echo"<td width=70% align=right>";
echo "<strong>".($i+1).".Name: ";
echo htmlspecialchars( stripslashes($row["name"]));
echo"</td>";
echo"<td valign=top rowspan=4 align=right>";
echo"<img src=\"$row[images]\" width=180 height=160>";
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Country: ";
echo htmlspecialchars( stripslashes($row["country"]));
echo"</td>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["age"]));
echo"<td>";
echo "</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["gender"]));
echo"<td>";
echo "</tr>";
echo"<table>";
}
}
else {
?>
<html>
<body>
<from method="post" action=<?php echo $_SERVER['PHP_SELF'];?>>
<font color="#34499F" face=verdana>Specific Search for friends</font>
Gender:<select name="gender">
<option value="m">Male</option>
<option value="f">Fmale</option>
</select>
Country:<select name="country" >
<option value="j">Japan</option>
<option value="k">Korea</option>
<option value="c">China</option>
</select>
From:<select name="age" >
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
to
<select name="age">
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
<input type="submit" name="sumbit" value="submit"><input type="reset" value="reset" name="reset"><br>
</form>
</body>
</html>
<?
}
?>
druffus
11-24-2002, 01:18 AM
<?php
if(isset($_POST['submit']))
{
$dbconnect = mysql_connect("localhost", "itohideo_hide", "0810");
if (!$dbconnect) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
if (! mysql_select_db("itohideo_japan") ) {
echo( "<p>Unable to locate the host " .
"database at this time.</p>" );
exit();
}
$query="SELECT * FROM girls WHERE gender=".$gender." AND country=".$country." AND age BETWEEN 18 and 35;
$result = mysql_query($query);
if (!$result){
echo mysql_error();
} else {
$num_results = mysql_num_rows($result);
}
echo("<p>itohideo.com found: " . $num_results . "</p>");
for($i=0; $i<$num_results; $i++)
{
$row=mysql_fetch_array($result);
echo"<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
echo"<tr>";
echo"<td width=70% align=right>";
echo "<strong>".($i+1).".Name: ";
echo htmlspecialchars( stripslashes($row["name"]));
echo"</td>";
echo"<td valign=top rowspan=4 align=right>";
echo"<img src=\"$row[images]\" width=180 height=160>";
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Country: ";
echo htmlspecialchars( stripslashes($row["country"]));
echo"</td>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["age"]));
echo"<td>";
echo "</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["gender"]));
echo"<td>";
echo "</tr>";
echo"<table>";
}
}
else {
?>
<html>
<body>
<from method="post" action=<?php echo $_SERVER['PHP_SELF'];?>>
<font color="#34499F" face=verdana>Specific Search for friends</font>
Gender:<select name="gender">
<option value="m">Male</option>
<option value="f">Fmale</option>
</select>
Country:<select name="country" >
<option value="j">Japan</option>
<option value="k">Korea</option>
<option value="c">China</option>
</select>
From:<select name="age" >
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
to
<select name="age">
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
<input type="submit" name="sumbit" value="submit"><input type="reset" value="reset" name="reset"><br>
</form>
</body>
</html>
<?
}
?>
You changed your form, but not your php logic. If we are sending in the values you are searching for we can easily make a one statement query like i have above.
$query="SELECT * FROM girls WHERE gender=".$gender." AND country=".$country." AND age BETWEEN 18 and 35;
First of all I found that two mistakes.
I fixed mispelled "form" and"submit".
Thanks a lot ,but when I click submit button, I got an error.
still not working.
It should be sql command is wrong.
Parse error: parse error in /home/itohideo/public_html/spe.php on line 27
hi how are you doing?
Sorry to post wrong code. It works but I can't choose selections.
When I choose male, japan,and 18-30, the results are female. not male. Selections are not working even though I choose.
I don't know why?????? Do you have any idea??
Sql command should be wrong right.
Here is that I fixed code
<?php
if(isset($_POST['submit']))
{
$dbconnect = mysql_connect("localhost", "itohideo_hide", "0810");
if (!$dbconnect) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
if (! mysql_select_db("itohideo_japan") ) {
echo( "<p>Unable to locate the host " .
"database at this time.</p>" );
exit();
}
$gender=$_POST["gender"];
$country=$_POST["country"];
$age=$_POST["age"];
if($gender=="m") {
$query="select * from girls where gender='male'";
}
else {
$query="select * from girls where gender='female'";
}
if($country=="j"){
$query="select * from girls where country='Japan' ";
}
elseif($country=="k"){
$query="select * from girls where country='Korea'";
}
else {
$query="select * from girls where country='China'";
}
if($age>=18 && $age<=35) {
$query="select * from girls where age between 18 and 35";
}
$result = mysql_query($query);
if (!$result)
echo mysql_error();
$num_results = mysql_num_rows($result);
echo("<p>itohideo.com found: " . $num_results . "</p>");
for($i=0; $i<$num_results; $i++)
{
$row=mysql_fetch_array($result);
echo"<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
echo"<tr>";
echo"<td width=70% align=right>";
echo "<strong>".($i+1).".Name: ";
echo htmlspecialchars( stripslashes($row["name"]));
echo"</td>";
echo"<td valign=top rowspan=4 align=right>";
echo"<img src=\"$row[images]\" width=180 height=160>";
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Country: ";
echo htmlspecialchars( stripslashes($row["country"]));
echo"</td>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["age"]));
echo"<td>";
echo "</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["gender"]));
echo"<td>";
echo "</tr>";
echo"<table>";
}
}
else {
?>
<html>
<body>
<form method="post" action=<?php echo $_SERVER['PHP_SELF'];?>>
<font color="#34499F" face=verdana>Specific Search for friends</font>
Gender:<select name="gender">
<option value="m">Male</option>
<option value="f">Fmale</option>
</select>
Country:<select name="country" >
<option value="j">Japan</option>
<option value="k">Korea</option>
<option value="c">China</option>
</select>
From:<select name="age" >
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
to
<select name="age">
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
<input type="submit" name="submit" value="submit"><input type="reset" value="reset" name="reset"><br>
</form>
</body>
</html>
<?
}
?>
druffus
11-24-2002, 05:18 AM
Maybe I am explaining this wrong.
This code is wrong and will not work at all, it is what you are using.
if($gender=="m") {
$query="select * from girls where gender='male'";
}
else {
$query="select * from girls where gender='female'";
}
if($country=="j"){
$query="select * from girls where country='Japan' ";
}
elseif($country=="k"){
$query="select * from girls where country='Korea'";
}
else {
$query="select * from girls where country='China'";
}
if($age>=18 && $age<=35) {
$query="select * from girls where age between 18 and 35";
}
Why is it wrong you may ask.
1. Everytime you do an if/else statement, you are setting the variable $query to be something. That means on your last one (the age if/else) you are copying over the other two you did before. Therefore, after all the if/else statements above, you will have your variable $query equal to ="select * from girls where age between 18 and 35". Meaning you won't even be searching for gender or country.
2. You want to make one query statement that has all the where commands (what you are searching for) in it.
Now the code that I put in there, which should replace the if/else statements above is:
$query="SELECT * FROM girls WHERE gender='".$gender."' AND country='".$country."' AND age BETWEEN 18 and 35;
What the statement above does (in place of the if/else statements) is search for all those conditions. All it is doing is putting in the valuse you selected from the form into the search commands.
More clear?
I hope I am explaining this correctly to you. Replace the the if/else statements with the code I have directly above.
Thanks druffus.
it works but one more question.
Only one thing it does not work is that age.
What I want to do is that when a user chooses age(18-35),it come out specific age from my database.
In other words, Let's say one is looking for a male friend, from Japan, 18-22age. Then it comes only 18-22age males from my database. Whenever a user choose age, it comes specific age from my database.
I did like this but I got syntax error
$sql="SELECT * FROM girls WHERE gender='$gender' AND country='$country'AND 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35='$age'";
druffus
11-24-2002, 06:38 AM
Ok, I see what your looking to do with age. Alright, in your form, name the two select boxes for age differently. Instead of both being age, make it like age1 and age2 or whatever.
Example:
From:<select name="age1" >
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
to
<select name="age2">
<option value="18" selected>18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
<option value="32" >32</option>
<option value="33" >33</option>
<option value="34" >34</option>
<option value="35" >35</option>
</select>
Then make your sql statement look like this:
$sql="SELECT * FROM girls WHERE gender='$gender' AND country='$country' AND age>$age1 AND age<$age2";
Get how that works?
Good luck and I am glad you got the other stuff to work.
Thanks it works well
Thanks druffus for being with me.
YOu are the best
Again thanks it works well
I learned from you.
Bye
lord_raven
03-15-2003, 05:29 AM
What you could also do with the age variables is this:
<select name="age[]">
...
<options>
...
</select>
Do this code twice and the variable from the first <select> would be age[0] and the variable from the second would be age[1]...
or...
<select name="age[min]">
...
<options>
...
</select>
<select name="age[max]">
...
<options>
...
</select>
...then your variables would be age[min] and age[max] respectively...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.