Hi folks,
This is a pathetic one that in all honesty I should be able to figure out (having done so in the past) but my brain is refusing to give up the answers today…..
I have a form into which the user can enter the name of a musical instrument and then submit to query a MySQL database containing lists of bands (this is not a commercial project) who use that instrument and then display the results on a results page.
Should be simple.
Here’s what I have so far:
The form
<form name="form1" method="POST" action="qresults.php">
<p>Instrument:
<input name="instrument" type="text" id="instrument_id">
<p><input type="submit" name="submit" value="submit">
</form>
The results page
<?
$db_name = "dbname";
$table_name = "tablename";
$connection = @mysql_connect("localhost", "username", "password") or die("Could not connect.");
$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql =
"SELECT *
FROM $table_name WHERE instrument=" . $_POST['instrument_id'] . "";
$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$fname = $row['fname'];
$lname = $row['lname'];
$county = $row['county'];
$instrument = $row['instrument'];
$style = $row['style'];
$howlong = $row['howlong'];
$standard = $row['standard'];
$bandb4 = $row['bandb4'];
$tranpost = $row['tranport'];
$songwriter = $row['songwriter'];
$description = $row['description'];
$display_block .= "
All I get is the “Couldn’t execute query” message when I try to run this.
Please, any thoughts would be muchly appreciated.
Many thanks.
This is a pathetic one that in all honesty I should be able to figure out (having done so in the past) but my brain is refusing to give up the answers today…..
I have a form into which the user can enter the name of a musical instrument and then submit to query a MySQL database containing lists of bands (this is not a commercial project) who use that instrument and then display the results on a results page.
Should be simple.
Here’s what I have so far:
The form
<form name="form1" method="POST" action="qresults.php">
<p>Instrument:
<input name="instrument" type="text" id="instrument_id">
<p><input type="submit" name="submit" value="submit">
</form>
The results page
<?
$db_name = "dbname";
$table_name = "tablename";
$connection = @mysql_connect("localhost", "username", "password") or die("Could not connect.");
$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql =
"SELECT *
FROM $table_name WHERE instrument=" . $_POST['instrument_id'] . "";
$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$fname = $row['fname'];
$lname = $row['lname'];
$county = $row['county'];
$instrument = $row['instrument'];
$style = $row['style'];
$howlong = $row['howlong'];
$standard = $row['standard'];
$bandb4 = $row['bandb4'];
$tranpost = $row['tranport'];
$songwriter = $row['songwriter'];
$description = $row['description'];
$display_block .= "
All I get is the “Couldn’t execute query” message when I try to run this.
Please, any thoughts would be muchly appreciated.
Many thanks.