0

I've commented out the bottom part, and the SQL query works fine. Its the displaying of the query where the error is coming from i believe.

$host = "127.0.0.1"; 
$user = "root"; 
$pass = "Toom13371!";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().":     ".mysql_error()."<BR>");

// 2. Selecting DB.

$dbname = "filters"; 
mysql_select_db($dbname);

// 3. Build/Test SQL Query

$sql = ("select * from filter_bandpass where start_passband=" . $_POST['Lowfreq'] . "         and stop_passband='" . $_POST['Highfreq'] . "'");
//echo $sql; //Comment/Uncomment to test sql query.

// 4. Retrieve info from MySQL.

$query = mysql_query($sql);

// 5. Display Query.

echo "<table border='1'>
<tr>
<th>Low Frequency</th>
<th>High Frequency</th>
</tr>";

while($row = mysql_fetch_array($query)) {
  echo "<tr>";
  echo "<td>" . $row['Lowfreq'] . "</td>";
  echo "<td>" . $row['Highfreq'] . "</td>";
  echo "</tr>";
}

echo "</table>";
  ?>

Any help would be appreciated, I'm sure it's going to be some small stupid error i've over looked.

Thanks in advance :)

3
  • 1
    This looks terrifyingly insecure. Are you sure your user parameters are properly escaped? $_POST data should NEVER go directly into a query. mysql_query is an obsolete interface and should not be used in new applications and will be removed in future versions of PHP. A modern replacement like PDO is not hard to learn. If you're new to PHP, a guide like PHP The Right Way can help explain best practices. Commented Aug 21, 2014 at 10:11
  • Hi, thanks for answering! Will look into PDO. Commented Aug 21, 2014 at 10:13
  • @thomasward1212 - It is good practice on stackoverflow to accept an answer from given answers. Please select an answer Commented Aug 22, 2014 at 7:27

3 Answers 3

1

I'm guessing, based on your query, that you need to change this

mysql_select_db($dbname);

to

mysql_select_db($dbname, $connection);

and

while($row = mysql_fetch_array($query)) {
  echo "<tr>";
  echo "<td>" . $row['Lowfreq'] . "</td>";
  echo "<td>" . $row['Highfreq'] . "</td>";
  echo "</tr>";
}

to

while($row = mysql_fetch_array($query)) {
  echo "<tr>";
  echo "<td>" . $row['start_passband'] . "</td>";
  echo "<td>" . $row['stop_passband'] . "</td>";
  echo "</tr>";
}
Sign up to request clarification or add additional context in comments.

1 Comment

What i'm getting now is the top part of the table, this bit; echo "<table border='1'> <tr> <th>Low Frequency</th> <th>High Frequency</th> </tr>"; But not the query generated part.
0

Change line

mysql_select_db($dbname);

to

mysql_select_db($dbname, $connection);

Also before query check

$_POST['Lowfreq'] and $_POST['Highfreq']

If there is no value in these variables query will must return empty.

Comments

0

In your query there should not brackets for string.

 $sql = ("select * from filter_bandpass where start_passband=" . $_POST['Lowfreq'] . "         and stop_passband='" . $_POST['Highfreq'] . "'");

should be:

 $sql = "select * from filter_bandpass where start_passband=" . $_POST['Lowfreq'] . "         and stop_passband='" . $_POST['Highfreq'] . "'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.