473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

???passing a query from a form???

Joe
I have wrote a script to query my mysql database based up a name that
is selected from an HTML list menu, the form action calls to my php
script from my html doc, I have tested connectivity to the databse and
have added a manual sql query to my php script to be sure it is
functioning properly, the problem is I'm not sure how to get the
script to see what option the html form is sending, I thought I could
use:

$query = "SELECT * FROM table WHERE email =
'{$_GET['selecteduser']}@mydomain.com'";

but that doesn't seem to be working properly. Maybe the HTML document
is sending it correctly? Here is my form:

<form action="report_results.php" method="post">
<select name="selecteduser">
<option value="selecteduser">Select One:</option>
<option value="us***@mydomain.com">user1</option>
<option value="us***@mydomain.com">user2</option>
</select>
<input type="submit" name="submit" value="Go!">
</form>

This form calls to the php script which then takes the input from the
HTML form and processes it into the $_GET query and sends it to the
while loop in the script, I'm not sure why this is not working? Here
is my php code:

PHP:
--------------------------------------------------------------------------------
<?php
$db = mysql_connect("localhost", "sqluser", "sqlpasswd") or
die("Could not connect to Mysql");
if (!$db == False)
{
mysql_select_db("mydb");
$query = "SELECT * FROM table WHERE email =
'{$_GET['selecteduser']}@mydomain.com'";

$result = mysql_query($sql,$db);
while ($row = mysql_fetch_row($result))
{
print "<tr>";
foreach ($row as $field)
{
print "<td>$field</td>";
}
print "</tr>";
}
mysql_close($cn);
}
else
{
print "Problem Connecting to the Database<br>";
}
?>
--------------------------------------------------------------------------------

Does anyone have any suggestions??

Thanks
Jul 17 '05 #1
4 1962
On 28 Mar 2004 17:11:54 -0800, t3***@hotmail.com (Joe) wrote:
I have wrote a script to query my mysql database based up a name that
is selected from an HTML list menu, the form action calls to my php
script from my html doc, I have tested connectivity to the databse and
have added a manual sql query to my php script to be sure it is
functioning properly, the problem is I'm not sure how to get the
script to see what option the html form is sending, I thought I could
use:

$query = "SELECT * FROM table WHERE email =
'{$_GET['selecteduser']}@mydomain.com'";

but that doesn't seem to be working properly. Maybe the HTML document
is sending it correctly? Here is my form:

<form action="report_results.php" method="post">
<select name="selecteduser">
<option value="selecteduser">Select One:</option>
<option value="us***@mydomain.com">user1</option>
<option value="us***@mydomain.com">user2</option>
</select>
<input type="submit" name="submit" value="Go!">
</form>

This form calls to the php script which then takes the input from the
HTML form and processes it into the $_GET query and sends it to the
while loop in the script, I'm not sure why this is not working? Here
is my php code:

PHP:
--------------------------------------------------------------------------------
<?php
$db = mysql_connect("localhost", "sqluser", "sqlpasswd") or
die("Could not connect to Mysql");
if (!$db == False)
{
mysql_select_db("mydb");
$query = "SELECT * FROM table WHERE email =
'{$_GET['selecteduser']}@mydomain.com'";

$result = mysql_query($sql,$db);
while ($row = mysql_fetch_row($result))
{
print "<tr>";
foreach ($row as $field)
{
print "<td>$field</td>";
}
print "</tr>";
}
mysql_close($cn);
}
else
{
print "Problem Connecting to the Database<br>";
}
?>
--------------------------------------------------------------------------------

Does anyone have any suggestions??

Thanks


Try
$_POST['selecteduser']
instead of
$_GET['selecteduser']

in the PHP script.

Either that or use method="get" in your HTML page.

That oughta do it :]
Jul 17 '05 #2
t3***@hotmail.com (Joe) wrote in
news:69**************************@posting.google.c om:
$query = "SELECT * FROM table WHERE email =
'{$_GET['selecteduser']}@mydomain.com'";
You're trying to retrieve the value from $_GET, which assumes your form was
using the GET method...
but that doesn't seem to be working properly. Maybe the HTML document
is sending it correctly? Here is my form:

<form action="report_results.php" method="post">
but your form is using the POST method, so the value will be in $_POST.

But wait, there's more...
<select name="selecteduser">
<option value="selecteduser">Select One:</option>
<option value="us***@mydomain.com">user1</option>
<option value="us***@mydomain.com">user2</option>


The value in $_POST will end in "@mydomain.com" so when you fix the first
problem, you'll find you're asking your database for a value ending in
"@my**********@mydomain.com" and it will tell you it doesn't have it.
Append it in one place, not two.

Oh, and I'd really run that value through mysql_escape_string() before
letting it near a SELECT statement.
Jul 17 '05 #3
Joe
I changed the method to post in my html document, so that it matches
in both documents.I also the line <option value="selecteduser">Select
One:</option>
to <option value="NULL">Select One:</option> since there is no option
to pass there.

Now when you say:
The value in $_POST will end in "@mydomain.com" so when you fix the
first
problem, you'll find you're asking your database for a value ending in
"@my**********@mydomain.com" and it will tell you it doesn't have it.
Append it in one place, not two.

Do you mean only put the $_POST in my $sql query and no where else?

Eric Bohlman <eb******@earthlink.net> wrote in message news:<Xn*******************************@130.133.1. 4>...
t3***@hotmail.com (Joe) wrote in
news:69**************************@posting.google.c om:
$query = "SELECT * FROM table WHERE email =
'{$_GET['selecteduser']}@mydomain.com'";


You're trying to retrieve the value from $_GET, which assumes your form was
using the GET method...

but that doesn't seem to be working properly. Maybe the HTML document
is sending it correctly? Here is my form:

<form action="report_results.php" method="post">


but your form is using the POST method, so the value will be in $_POST.

But wait, there's more...
<select name="selecteduser">
<option value="selecteduser">Select One:</option>
<option value="us***@mydomain.com">user1</option>
<option value="us***@mydomain.com">user2</option>


The value in $_POST will end in "@mydomain.com" so when you fix the first
problem, you'll find you're asking your database for a value ending in
"@my**********@mydomain.com" and it will tell you it doesn't have it.
Append it in one place, not two.

Oh, and I'd really run that value through mysql_escape_string() before
letting it near a SELECT statement.

Jul 17 '05 #4
Perhaps you overlook this line:
$result = mysql_query($sql,$db);

I think it should be
$result = mysql_query($query,$db);

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
12
by: zig | last post by:
I've posted this on alt.comp.lang.coldfusion, but is predominantly a javascript problem: I have a CF query which returns several rows of records. I wanted to have a checkbox on each record of...
2
by: MX1 | last post by:
HELP! I have a query that gets a few values from a form. The problem I'm having is a date field in the query. When I put the value in the criteria, it works fine. When I put the same value as...
7
by: Mike | last post by:
I have to pass a date from a form to a report query. I have written a query that works fine when I execute from SQL view, But I dont know how to pass a value from the form to this query. SELECT...
2
by: Bob Sanderson | last post by:
I have a search form from which I hope to be able to select a record by field JobNumber and display it with an output form titled test.php <html> <head> <title>Job Database Search</title>...
2
by: dath | last post by:
Hi, Searched the forum and found a lot on passing form input to aquery but not the other way around. Here is the situation: I have a timesheet form based on a subform query that asks the...
3
by: Jahangir | last post by:
Dear Fellows, I m in in Access VB, and working on a small project. Problem is that In main form (called search )I have made a textbox name text34, and a search button, which responsiblity is...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
6
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.