HTML dropdown, PHP Variables.
Posted: Fri Sep 14, 2007 6:37 am
feyd | Please use
Page 2[/syntax]
What this should do, is allow the user to search for "x" item in the selected table. Which is then echoed out.
Is there something that i am missing, or a syntax error?
I'm going bald!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hey all,
Firstly as probably all posts start with, I'm new to PHP. I was thrown into it by my Boss. I've managed to query a very basic search, delete, edit and add to interact with a SQL database, however, hes now asking for dropdown menus and such. I know how to create one in HTML, and how to assign variables, post them to the next page. Im just a bit stuck where to go next. I have a piece of code i drew up, but its just not working.
I'm pretty sure that its the Query thats wrong, or that im assigning the variables wrongly.
Normally im against posting whole chunks of code, but im really stuck.
So Page 1
[syntax="html"]<FORM ACTION="searchresults01.php" METHOD="post">
<p>Search for:
<INPUT NAME="search" TYPE="text">
in table:
<select name="dropdown" id="dropdown">
<option value="ALLTABLES" selected="selected">*</option>
<option value="BOOKTABLE">BOOKS</option>
<option value="FURNTABLE">FURNITURE</option>
<option value="ITTABLE">IT</option>
<option value="KITCHENTABLE">KITCHEN</option>
<option value="MISCTABLE">MISC</option>
<option value="ARCHIVETABLE">ARCHIVE</option>
</select>
<INPUT TYPE="submit" VALUE="Proceed" name = "dropdown">
</p>
<p>
<label></label>
</p>
</FORM>Code: Select all
<?
$search = $_POST['search'];
$dropdown = $_POST['dropdown'];
$ALLTABLES = $_POST['ALLTABLES'];
$BOOKTABLE = $_POST['BOOKTABLE'];
$FURNTABLE = $_POST['FURNTABLE'];
$ITTABLE = $_POST['ITTABLE'];
$KITCHENTABLE = $_POST['KITCHENTABLE'];
$MISCTABLE = $_POST['MISCTABLE'];
$ARCHIVETABLE = $_POST['ARCHIVETABLE'];
$db = mysql_connect("localhost","rarar","blabla");
mysql_select_db("asset tracker", $db);
$query = "SELECT * FROM '%".$ALLTABLES."%' || '%".$BOOKTABLE."%' || '%".$FURNTABLE."%' || '%".$ITTABLE."%' || '%".$KITCHENTABLE."%' || '%".$MISCTABLE."%' || '%".$ARCHIVETABLE."%' WHERE item || loan || company LIKE '%".$search."%'";
$result = mysql_query($query)or die(Error, query failed.);
while ($item = mysql_fetch_assoc($result)) {
while (list($fieldname, $fieldvalue) = each ($item)) {
echo $fieldname.": <b>".$fieldvalue."</B><br>";
} echo "<p>";
}
?>Is there something that i am missing, or a syntax error?
I'm going bald!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]