Page 1 of 1

pass variables

Posted: Mon Oct 04, 2004 5:54 pm
by infomorelos
feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi,

I'm new to programming and got stuck with a drop down list populated from a field in a table and attempting to get this processed by the form action script.
I have one table (visitsofvendor) with fields like 'id', 'vendor', 'client', 'clientphone' etc.
I can display all the content of the table with a simple select and I can make a form with a select object that is populated with the values from the 'vendor' field, that's as far as I get.
Now, when I click the submit button, I want to display only the rows with the name of the vendor I choose in the form. In the best of the cases, I get a mysql error like : mysql_num_rows(): supplied argument is not a valid MySQL result resource
As I'm absolutely new to programming, Im not sure if
- there is no variable at all passed to the form action file or
- the variable is not passed correctly
- the WHERE clause is not correct
- there is a missing element
- the files are inconsistent.

The code for the population of the dropdown menu in the form is:

Code: Select all

<html>
...
<form method="post" action="showonlyrecordsofselectedvendor.php">
<?php
include_once("connection.php");
$sql = "SELECT distinct vendor FROM visitsofvendor";
$result = mysql_query($sql) or die("mysql error in $sql: ".mysql_error());
echo "<select name="vendedor">";
while ($row = mysql_fetch_array($result))
{
echo "<option value="".$row['vendor']."">".$row['vendor']."</option>";
}
echo "</select>";
?>
<!-- I'm not sure about the next line, when it wasn't there, the misbehaviour was the same, so I dont know if it is necessary -->
<input type="hidden" name="visits" value="<?php echo "['vendor']";?>">
<!-- on the next line, I'm not sure about the name (I suppose this has to be the same in the ifset on the form action page) and value and if this makes any difference -->
<input type="submit" name="byvendor" value="show_them">


I was happy when the drop down menu got populated and thought I was close to get my result. But the dream was quickly over when I tried to put the WHERE clause in the showonlyrecordsofselectedvendor.php (form action) file. See what I tried:

Code: Select all

// I'm not sure if I need the following line
if(isset($_POST['byvendor']))

$sql = "SELECT * FROM visitsbyvendor WHERE $visits LIKE vendor".$orderByQuery.$limitQuery;
$result = MYSQL_QUERY($sql);
$numberOfRows = MYSQL_NUM_ROWS($result);
As commented, I get the 'mysql_num_rows(): supplied argument is not a valid MySQL result resource'-error on the last line of shown code.
When I try a simple

Code: Select all

SELECT * FROM visitsbyvendor WHERE vendor LIKE one_of_the_vendors_names.$orderByQuery.$limitQuery;
I get the desired result. However, I would like to get the result via a drop down menu in order to allow only one form action file for different vendors.
I know that this post is a mess, especially because I'm unsure if the problem arises from an error in the form file or from an error in the form action file or from inconsistencies between both files. Or maybe I'm missing an additional element?
_________________
Thank you in advance


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Oct 04, 2004 6:05 pm
by feyd
you likely have an error in your query syntax, adding the usual "or die" mysql_error hook should tell you something of more detail.

I would bet that 'vendor' in line 4 of the second php block you posted is supposed to be the posted variable? Unless you have register_globals on $vendor, provided you spell it correctly (as it's not in the first php block), will not exist. $_POST['vendor'] should however. You will need a quoted string to mysql, unless it's a field name reference.