derekstattin
asked on
Using php and mysql switch from URL data and user input search
I have pay per click adds and I send people to a page
http://mysite.com/search-members-by-city.php?city=somecityname
Right now I have it set up so people can type in the city they want to search
$get_pro_sql = "SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username FROM DB where city='$city_menu_choice' ORDER BY update DESC";
$get_pro_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli)) ;
I would like to make it so when someone clicks on an add and goes to this page, the members from "somecity" are posted.
Then if they want to search a different city they can type the name of the city in
<table width="250px">
<form method='post' action=<?php $_SERVER['PHP_SELF'] ?> >
<td><strong>City:</strong> </td>
<td>
<input type="text" name="city_choice" size="20" value=<?php $_POST['city_choice'] ?> >
</td>
<td>
<input type="submit" name="submit" id="submit"/>
</td>
</tr>
</form>
</table>
Can you help me so I can do this either or situation?
thanks
http://mysite.com/search-members-by-city.php?city=somecityname
Right now I have it set up so people can type in the city they want to search
$get_pro_sql = "SELECT DATE_FORMAT(profile_update
$get_pro_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli))
I would like to make it so when someone clicks on an add and goes to this page, the members from "somecity" are posted.
Then if they want to search a different city they can type the name of the city in
<table width="250px">
<form method='post' action=<?php $_SERVER['PHP_SELF'] ?> >
<td><strong>City:</strong>
<td>
<input type="text" name="city_choice" size="20" value=<?php $_POST['city_choice'] ?> >
</td>
<td>
<input type="submit" name="submit" id="submit"/>
</td>
</tr>
</form>
</table>
Can you help me so I can do this either or situation?
thanks
ASKER
I put the code you sent above, above the sql statement,
$get_pro_sql = "SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username FROM DB where city='$city_menu_choice' ORDER BY update DESC";
$get_pro_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli)) ;
but I am not having any luck,
can you give me another tip
$get_pro_sql = "SELECT DATE_FORMAT(profile_update
$get_pro_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli))
but I am not having any luck,
can you give me another tip
can I point out the obvious?
$get_pro_sql is not the same as $get_profiles_sql
:)
Michael
ps: been there done that before myself.
$get_pro_sql is not the same as $get_profiles_sql
:)
Michael
ps: been there done that before myself.
ASKER
I have it right in my script, I just abreviated to make the question shorter, I just did not change the third profiles. I must be doing something else wrong. If I search , say philadelphia I still see chicago members.
// after you set the sql
echo "get:".$_GET['city']."<br />\n";
echo "post:".$_POST['city_choic e']."<br />\n";
echo "sql:".$get_profiles_sql." <br />\n";
Let's see if it's getting set correctly
echo "get:".$_GET['city']."<br />\n";
echo "post:".$_POST['city_choic
echo "sql:".$get_profiles_sql."
Let's see if it's getting set correctly
ASKER
$get_pro_sql = "SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username FROM DB where city='$city_menu_choice' ORDER BY update DESC";
$get_pro_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli)) ;
I put your code above after, the above $sql
I don't get any variables echoed in the body of the page
$get_pro_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli))
I put your code above after, the above $sql
I don't get any variables echoed in the body of the page
ASKER
Do you need more of the srcipt?
even if you 'view source' on the html?
guess You'll have to post your php cope
guess You'll have to post your php cope
ASKER
<?php
$mysqli = mysqli_connect("");
$city_menu_choice = $_POST['city_choice'];
$city_menu_choice='';
if (isset($_GET['city']))
$city_menu_choice=$_GET['c ity'];
if (isset($_POST['city_choice ']))
$city_menu_choice = $_POST['city_choice'];
//gather the topics
$get_pro_sql = "SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username, profile_update, city, state, profession FROM profile where city_menu_choice='$city' ORDER BY profile_update DESC";
$get_profiles_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli)) ;
echo "get:".$_GET['city']."<br />\n";
echo "post:".$_POST['city_choic e']."<br />\n";
echo "sql:".$get_profiles_sql." <br />\n";
if (mysqli_num_rows($get_prof iles_res) < 1) {
//there are no topics, so say so
$display_block = "<p><strong><em>There are no member profiles for ".$city_menu_choice." at this time.</em></strong></p>";
} else {
//create the display string
$display_block = "
<table cellpadding=\"10\" cellspacing=\"1\" border=\"0\" border-color=\"121212\">
<tr>
<th>User Name</th>
<th>Location</th>
<th>Profession</th>
<th>View Profile</th>
</tr>";
while ($user_info = mysqli_fetch_array($get_pr ofiles_res )) {
$users_state_choice = $_POST['city_choice'];
$state = stripslashes($user_info['s tate']);
$city = stripslashes($user_info['c ity']);
$username = stripslashes($user_info['u sername']) ;
$profession = stripslashes($user_info['p rofession' ]);
$ID = stripslashes($user_info['I D']);
$profile_update = stripslashes($user_info['p rofile_upd ate']);
//add to display
$display_block .= "
<tr>
<td align=center>".$username." </td>
<td align=center>".$city.",&nb sp;".$stat e."</td>
<td align=center>".$profession ."</td>
<td><a href=\"show_members_profil e.php?ID=" .$ID."\">g o to profile</a></td>
</tr>";
}
//free results
mysqli_free_result($get_pr ofiles_res );
//close connection to mysqli
mysqli_close($mysqli);
//close up the table
$display_block .= "</table>";
}
?>
<table width="250px">
<form method='post' action=<?php $_SERVER['PHP_SELF'] ?> >
<td><strong>City:</strong> </td>
<td>
<input type="text" name="city_choice" size="20" value=<?php $_POST['city_choice'] ?> >
</td>
<td>
<input type="submit" name="submit" id="submit"/>
</td>
</tr>
</form>
</table>
<p>
<?php echo $display_block; ?>
</p>
$mysqli = mysqli_connect("");
$city_menu_choice = $_POST['city_choice'];
$city_menu_choice='';
if (isset($_GET['city']))
$city_menu_choice=$_GET['c
if (isset($_POST['city_choice
$city_menu_choice = $_POST['city_choice'];
//gather the topics
$get_pro_sql = "SELECT DATE_FORMAT(profile_update
$get_profiles_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli))
echo "get:".$_GET['city']."<br />\n";
echo "post:".$_POST['city_choic
echo "sql:".$get_profiles_sql."
if (mysqli_num_rows($get_prof
//there are no topics, so say so
$display_block = "<p><strong><em>There are no member profiles for ".$city_menu_choice." at this time.</em></strong></p>";
} else {
//create the display string
$display_block = "
<table cellpadding=\"10\" cellspacing=\"1\" border=\"0\" border-color=\"121212\">
<tr>
<th>User Name</th>
<th>Location</th>
<th>Profession</th>
<th>View Profile</th>
</tr>";
while ($user_info = mysqli_fetch_array($get_pr
$users_state_choice = $_POST['city_choice'];
$state = stripslashes($user_info['s
$city = stripslashes($user_info['c
$username = stripslashes($user_info['u
$profession = stripslashes($user_info['p
$ID = stripslashes($user_info['I
$profile_update = stripslashes($user_info['p
//add to display
$display_block .= "
<tr>
<td align=center>".$username."
<td align=center>".$city.",&nb
<td align=center>".$profession
<td><a href=\"show_members_profil
</tr>";
}
//free results
mysqli_free_result($get_pr
//close connection to mysqli
mysqli_close($mysqli);
//close up the table
$display_block .= "</table>";
}
?>
<table width="250px">
<form method='post' action=<?php $_SERVER['PHP_SELF'] ?> >
<td><strong>City:</strong>
<td>
<input type="text" name="city_choice" size="20" value=<?php $_POST['city_choice'] ?> >
</td>
<td>
<input type="submit" name="submit" id="submit"/>
</td>
</tr>
</form>
</table>
<p>
<?php echo $display_block; ?>
</p>
guess you need to favor get over post, but you are doing the reverse here, try this
<?php
$mysqli = mysqli_connect("");
$city_menu_choice='';
$city_menu_choice = isset($_POST['city'])? mysqli_real_escape_string($_POST['city']): '';
$city_menu_choice = isset($_GET['city'])? mysqli_real_escape_string($_GET['city']): '';
$get_pro_sql = "SELECT DATE_FORMAT(profile_update, '%b %e %Y at %r') AS fmt_profile_update, ID, username, profile_update, city, state, profession FROM profile where city_menu_choice='$city_menu_choice' ORDER BY profile_update DESC";
$get_profiles_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli)."in\n$get_pro_sql");
...........
..........
.........
change this
$get_pro_sql = "SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username, profile_update, city, state, profession FROM profile where city_menu_choice='$city' ORDER BY profile_update DESC";
to
$get_profiles_sql = "SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username, profile_update, city, state, profession FROM profile where city_menu_choice='$city' ORDER BY profile_update DESC";
$get_pro_sql = "SELECT DATE_FORMAT(profile_update
to
$get_profiles_sql = "SELECT DATE_FORMAT(profile_update
ASKER
Not working quite yet, do you have another suggestion? I still get only the ?city=somecity from the url, and the post does not work.
few corrections to html, but shouldn't be the problem
what's the output from the echo commands? Is this available on the web? If so, post the url.
what's the output from the echo commands? Is this available on the web? If so, post the url.
// px only valid in css
<table width="250">
// missing " around action value
<form method='post' action="<?php $_SERVER['PHP_SELF'] ?>" >
<td><strong>City:</strong></td>
<td>
// missing " around value
<input type="text" name="city_choice" size="20" value="<?php $_POST['city_choice'] ?>" >
ASKER
no luck with that change
what's the output from the echo commands? Is this available on the web? If so, post the url.
ASKER
the url is http://real-estate-proforma.com/search-members-by-city.php?...eg ...city=chicago
I added the code below in the body, but it does not echo anything
<?php
echo "get:".$_GET['city']."<br />\n";
echo "post:".$_POST['city_choic e']."<br />\n";
echo "sql:".$get_profiles_sql." <br />\n";
?>
I added the code below in the body, but it does not echo anything
<?php
echo "get:".$_GET['city']."<br />\n";
echo "post:".$_POST['city_choic
echo "sql:".$get_profiles_sql."
?>
put the echo's right after the
$get_profiles_res = mysqli_query........
you also didn't add the quotes around the action and value= in your form (add the echo also)
action="<?php echo $_SERVER['PHP_SELF'] ?>" >
(view the html source code to verify)
$get_profiles_res = mysqli_query........
you also didn't add the quotes around the action and value= in your form (add the echo also)
action="<?php echo $_SERVER['PHP_SELF'] ?>" >
(view the html source code to verify)
ASKER
I get this warning
Warning: mysqli_real_escape_string( ) expects exactly 2 parameters, 1 given in /home/content/M/a/n/Manzan illo8/html /search-me mbers-by-c ity.php on line 5
get:
post:chicago
Here is the code, I am sorry I am such an amatuer, thanks so much for your patients
sql:SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username, profile_update, city, state, profession FROM profile where city='' ORDER BY profile_update DESC
Warning: mysqli_real_escape_string( ) expects exactly 2 parameters, 1 given in /home/content/M/a/n/Manzan illo8/html /search-me mbers-by-c ity.php on line 5
get:
post:chicago
sql:SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username, profile_update, city, state, profession FROM profile where city='' ORDER BY profile_update DESC
<?php
$mysqli = mysqli_connect("");
$username = $_COOKIE["username"];
$city_menu_choice='';
$city_menu_choice = isset($_POST['city_choice' ])? mysqli_real_escape_string( $_POST['ci ty_choice' ]): '';
$city_menu_choice = isset($_GET['city'])? mysqli_real_escape_string( $_GET['cit y']): '';
$get_profiles_sql = "SELECT DATE_FORMAT(profile_update , '%b %e %Y at %r') aS fmt_profile_update, ID, username, profile_update, city, state, profession FROM profile where city='$city_menu_choice' ORDER BY profile_update DESC";
$get_profiles_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli). "in\n$get_ profiles_s ql");
echo "get:".$_GET['city']."<br />\n";
echo "post:".$_POST['city_choic e']."<br />\n";
echo "sql:".$get_profiles_sql." <br />\n";
if (mysqli_num_rows($get_prof iles_res) < 1) {
//there are no topics, so say so
$display_block = "<p><strong><em>There are no member profiles for ".$city_menu_choice." at this time.</em></strong></p>";
} else {
//create the display string
$display_block = "
<table cellpadding=\"10\" cellspacing=\"1\" border=\"0\" border-color=\"121212\">
<tr>
<th>User Name</th>
<th>Location</th>
<th>Profession</th>
<th>View Profile</th>
</tr>";
while ($user_info = mysqli_fetch_array($get_pr ofiles_res )) {
$state = stripslashes($user_info['s tate']);
$city_member = stripslashes($user_info['c ity']);
$username = stripslashes($user_info['u sername']) ;
$profession = stripslashes($user_info['p rofession' ]);
$ID = stripslashes($user_info['I D']);
$profile_update = stripslashes($user_info['p rofile_upd ate']);
//add to display
$display_block .= "
<tr>
<td align=center>".$username." </td>
<td align=center>".$city_membe r.", ".$state." </td>
<td align=center>".$profession ."</td>
<td><a href=\"show_members_profil e.php?ID=" .$ID."\">g o to profile</a></td>
</tr>";
}
//free results
mysqli_free_result($get_pr ofiles_res );
//close connection to mysqli
mysqli_close($mysqli);
//close up the table
$display_block .= "</table>";
}
?>
<table width="250">
<form method='post' action="<?php echo $_SERVER['PHP_SELF'] ?>" >
<td><strong>City:</strong> </td>
<td>
<input type="text" name="city_choice" size="20" value="<?php $_POST['city_choice'] ?>" >
</td>
<td>
<input type="submit" name="submit" id="submit"/>
</td>
</tr>
</form>
</table>
Warning: mysqli_real_escape_string(
get:
post:chicago
Here is the code, I am sorry I am such an amatuer, thanks so much for your patients
sql:SELECT DATE_FORMAT(profile_update
Warning: mysqli_real_escape_string(
get:
post:chicago
sql:SELECT DATE_FORMAT(profile_update
<?php
$mysqli = mysqli_connect("");
$username = $_COOKIE["username"];
$city_menu_choice='';
$city_menu_choice = isset($_POST['city_choice'
$city_menu_choice = isset($_GET['city'])? mysqli_real_escape_string(
$get_profiles_sql = "SELECT DATE_FORMAT(profile_update
$get_profiles_res = mysqli_query($mysqli, $get_profiles_sql) or die(mysqli_error($mysqli).
echo "get:".$_GET['city']."<br />\n";
echo "post:".$_POST['city_choic
echo "sql:".$get_profiles_sql."
if (mysqli_num_rows($get_prof
//there are no topics, so say so
$display_block = "<p><strong><em>There are no member profiles for ".$city_menu_choice." at this time.</em></strong></p>";
} else {
//create the display string
$display_block = "
<table cellpadding=\"10\" cellspacing=\"1\" border=\"0\" border-color=\"121212\">
<tr>
<th>User Name</th>
<th>Location</th>
<th>Profession</th>
<th>View Profile</th>
</tr>";
while ($user_info = mysqli_fetch_array($get_pr
$state = stripslashes($user_info['s
$city_member = stripslashes($user_info['c
$username = stripslashes($user_info['u
$profession = stripslashes($user_info['p
$ID = stripslashes($user_info['I
$profile_update = stripslashes($user_info['p
//add to display
$display_block .= "
<tr>
<td align=center>".$username."
<td align=center>".$city_membe
<td align=center>".$profession
<td><a href=\"show_members_profil
</tr>";
}
//free results
mysqli_free_result($get_pr
//close connection to mysqli
mysqli_close($mysqli);
//close up the table
$display_block .= "</table>";
}
?>
<table width="250">
<form method='post' action="<?php echo $_SERVER['PHP_SELF'] ?>" >
<td><strong>City:</strong>
<td>
<input type="text" name="city_choice" size="20" value="<?php $_POST['city_choice'] ?>" >
</td>
<td>
<input type="submit" name="submit" id="submit"/>
</td>
</tr>
</form>
</table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks so much,
works great now!
I hope I can get better at php and mysql!
Thank you for spending so much time with me
works great now!
I hope I can get better at php and mysql!
Thank you for spending so much time with me
Open in new window