tommyda Posted November 20, 2007 Share Posted November 20, 2007 What i need to do is when i call the url www.mysite.com/list.php?site=fakesite that should set the $site var to 'fakesite' then select all from database where 'fakesite' = 'active' But its not pulling any results from the database is it reading '$site' as the previusly posted $POST['fakesite'] ?? <?php $site = $_POST['site']; include"mysql.php"; // Get the data from the table $result = mysql_query("SELECT * FROM listings WHERE ('$site' = 'active)")or die(mysql_error()); include'table.php'; ?> Quote Link to comment Share on other sites More sharing options...
Hooker Posted November 20, 2007 Share Posted November 20, 2007 Just a couple of questions: * Is that your full source? * Are you getting any errors? It looks like you're pulling the data, just not using it. Quote Link to comment Share on other sites More sharing options...
tommyda Posted November 20, 2007 Author Share Posted November 20, 2007 No errors just a blank screen?? Full source for list.php <?php $payment = $_POST['payment']; $subcat = $_POST['subcat']; include"mysql.php"; // Get all the data from the "example" table $result = mysql_query("SELECT * FROM listings WHERE ('$payment' = 'yes')")or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row echo $row['title']; }; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted November 20, 2007 Share Posted November 20, 2007 You really ought check your query for success before attempting to use any results. <?php if (isset($_POST['submit'])) { $payment = $_POST['payment']; $subcat = $_POST['subcat']; include "mysql.php"; // Get all the data from the "example" table if ($result = mysql_query("SELECT title FROM listings WHERE $payment = 'yes'")) { if (mysql_num_rows($result)) { // keeps getting the next row until there are no more to get while ($row = mysql_fetch_assoc($result )) { // Print out the contents of each row echo $row['title']; } } } } ?> Quote Link to comment Share on other sites More sharing options...
Hooker Posted November 20, 2007 Share Posted November 20, 2007 Can you show your MYSQL table? seem's a little strange to have to define the column with a variable. If you're trying to find out if the website exists in your database and if it's active this is what i'd probably do to make your code work: * First, instead of just the site name, have the site name (in this instance the column is called "website" in the table) and another field that would be a boolen called "active". <?php include"mysql.php"; $site = $_POST['site']; $site = $_POST['active']; // Get all the data from the "example" table $sql = "SELECT * FROM listings WHERE website=$site AND active=$active"; $result = mysql_query($sql)or die(mysql_error()); // keeps getting the next row until there are no more to get if (mysql_num_rows($result)) { while($row = mysql_fetch_array( $result )) { // Print out the contents of each row echo $row['title']; } } ?> This would then select only the active websites that it finds in the database. Note: to choose if you want active or inactive websites you simply change the value of "$active" to 1 or 0 respectively. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.