is my query correct?
Posted: Tue Jan 15, 2013 6:22 pm
Hey all,
I'm trying to do an assignment for school.
Our website should be able to search in our database.
I think this could be done easier but we have to do it like this.
Anyways I could use some help and I was hoping to find it here.
I made the following form:
[syntax=xhtml]
<form action="" method="get">
<label>Zoek op: </label>
<select name="filter">
<option value="*">alles</option>
<option value="achternaam">achternaam</option>
<option value="studentnummer">studentnummer</option>
<option value="voornaam">voornaam</option>
<option value="geboortedatum">geboortedatum</option>
<option value="slb">slb</option>
</select>
<input type="text" name="zoeken">
<select name="order">
<option value="achternaam">achternaam</option>
<option value="studentnummer">studentnummer</option>
</select>
<input type="submit" value="zoek">
</form>
[/syntax]
I've got the following php code to go with it:
[syntax=php]
$search = mysql_query("select
* from student
where {$_GET['filter']}= {$_GET['zoeken']}
order by {$_GET['order']} asc");
[/syntax]
I hope it's clear what I am trying to do here
If my sql query is wrong, could someone tell me how it should look otherwise.
Thanks in advance!
I'm trying to do an assignment for school.
Our website should be able to search in our database.
I think this could be done easier but we have to do it like this.
Anyways I could use some help and I was hoping to find it here.
I made the following form:
[syntax=xhtml]
<form action="" method="get">
<label>Zoek op: </label>
<select name="filter">
<option value="*">alles</option>
<option value="achternaam">achternaam</option>
<option value="studentnummer">studentnummer</option>
<option value="voornaam">voornaam</option>
<option value="geboortedatum">geboortedatum</option>
<option value="slb">slb</option>
</select>
<input type="text" name="zoeken">
<select name="order">
<option value="achternaam">achternaam</option>
<option value="studentnummer">studentnummer</option>
</select>
<input type="submit" value="zoek">
</form>
[/syntax]
I've got the following php code to go with it:
[syntax=php]
$search = mysql_query("select
* from student
where {$_GET['filter']}= {$_GET['zoeken']}
order by {$_GET['order']} asc");
[/syntax]
I hope it's clear what I am trying to do here
If my sql query is wrong, could someone tell me how it should look otherwise.
Thanks in advance!