$sql="SELECT * FROM $tbl_name WHERE technology = '".$_GET['technology']."' AND range = '".$_GET['range']."' AND output = '".$_GET['output']."' AND configuration='".$_GET['configuration']."'";
Last edited by cinematic_jesi; 06-16-2009 at 02:26 PM.
also since we went to page 2 of the thread, i wanted to make sure you saw on page 1 the sql injection code (i believe its the very last post on that page)
Ok I updated the code and I still get the same error code
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\selection\product_view.php on line 24
here is updated code without the above recommended changes (going to try, just haven't had a chance Shorts)
PHP Code:
<html> <body>
<?php include "db.php"; include "error.php";
$tbl_name="product";
// Connect to server and select database. mysql_connect($hostname, $username, $password)or die("cannot connect"); mysql_select_db($database)or die("cannot select DB");
$total_result = mysql_query( "SELECT* FROM $tbl_name" ) or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($total_result);
// Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE technology = '".$_GET['technology']."' AND range = '".$_GET['range']."' AND output = '".$_GET['output']."' AND configuration='".$_GET['configuration']."'"; $result=mysql_query($sql);
// Start looping rows in mysql database. while ($rows=mysql_fetch_assoc($result)) { ?>
Here is the updated code with "Shorts" recommendations.
PHP Code:
<html> <body>
<?php include "db.php"; include "error.php";
$tbl_name="product";
// Connect to server and select database. mysql_connect($hostname, $username, $password)or die("cannot connect"); mysql_select_db($database)or die("cannot select DB");
$total_result = mysql_query( "SELECT* FROM $tbl_name" ) or die("SELECT Error: ".mysql_error());
// Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE technology = '".$_GET['technology']."' AND range = '".$_GET['range']."' AND output = '".$_GET['output']."' AND configuration='".$_GET['configuration']."'"; $result=mysql_query($sql);
// Start looping rows in mysql database. while ($rows=mysql_fetch_assoc($result)) { ?>
<p><?php echo $rows['product']; ?></p>
<?php // close while loop }
// close connection mysql_close(); ?>
</body> </html>
I still get the following error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\selection\product_view.php on line 27
For some reason it doesn't like "mysql_fetch_assoc():" and can't figure out why?
$sql="SELECT * FROM $tbl_name WHERE technology = '".$_GET['technology']."' AND range = '".$_GET['range']."' AND output = '".$_GET['output']."' AND configuration='".$_GET['configuration']."'"; echo "SQL: ",$sql,"<br />\n";
And see what the SQL actually looks like.
Also, rearrange the lines, the stuff I gave you, put above the $sql you already had. Right now it's being rewritten ($sql) with the code I gave and that can be causing you a new issue.
So we now have:
PHP Code:
<html> <body>
<?php include "db.php"; include "error.php";
$tbl_name="product";
// Connect to server and select database. mysql_connect($hostname, $username, $password)or die("cannot connect"); mysql_select_db($database)or die("cannot select DB");
$total_result = mysql_query( "SELECT * FROM $tbl_name" ) or die("SELECT Error: ".mysql_error());
// Let's get the total number of rows $sql = "SELECT COUNT(*) FROM $tbl_name"; $sql = mysql_query($sql); $num_rows = mysql_fetch_row($sql); $num_rows = $num_rows[0];
// Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE technology = '".$_GET['technology']."' AND range = '".$_GET['range']."' AND output = '".$_GET['output']."' AND configuration='".$_GET['configuration']."'"; // Let's now print the sql to screen to see what we have :D echo "SQL: ",$sql,"<br />\n"; $result=mysql_query($sql);
// Start looping rows in mysql database. while ($rows=mysql_fetch_assoc($result)) { ?>
Bookmarks