PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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>
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!
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]
Thanks for the quick response, Ace.
I've amended what you've suggested but the damn thing still isn't working.
Although i'm now getting something along the lines of this error being displayed;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''%BOOKTABLE%' WHERE item OR loan OR company LIKE '%css book%'' at line 1
Of course there isn't anything of interest on line one apart from the HTML start.
I think the problem now is that the table names arn't being picked up from the drop down box.
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]
Certainly, Sorry!
<?
$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","blabla","blablablaa");
mysql_select_db("asset tracker", $db);
$query = "SELECT * FROM '%$dropdown%' WHERE item OR loan OR company LIKE '%$search%'";
$result = mysql_query($query)or die(mysql_error());
while ($item = mysql_fetch_assoc($result)) {
while (list($fieldname, $fieldvalue) = each ($item)) {
echo $fieldname.": <b>".$fieldvalue."</B><br>";
} echo "<p>";
}
?>
Like i said, think its because the Variable to each of the Menu's items, arnt linked to the database. Im not to sure how to do that, or even if thats right.
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]
Last edited by nick.phillips on Mon Sep 17, 2007 2:52 am, edited 1 time in total.