Jump to content

[SOLVED] mysql_query("SELECT * FROM listings WHERE ('$site' = 'active)")


Recommended Posts

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';

?>

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'];

};

?>

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'];
      }
    }
  }
}

?>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.