Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

fuck shit piss

Name: Anonymous 2008-11-16 5:30

I am a PHP/mysquirrel newfag. So don't kill me.

i'm just having problems with this little script to search a mysql table 'cities'. i'm not getting any error messages. It's just that it will not display any results, no matter what the search query is(even if it's for the letter e or the exact city name). as if the table 'cities' is empty. Except that it isn't.

it WILL display the "City, Population, Country" html table row, and it will tell me what I searched for, but it will not get the appropriate values in the mysql table.

is there anything obviously wrong i'm doing?

<?php
function query_db($qstring) {
    include('login.php');
    require_once('DB.php');
    $connection=DB::connect("mysql://".$db_username.":".$db_password."@".
    $db_host."/".$db_database);
   
    if (DB::isError($connection)) {
        die ('Could not connect to the database: <br/>'.DB::errorMessage($connection));
        }
    if (get_magic_quotes_gpc()) {
        $qstring=stripslashes($qstring);
        }
        $qstring=mysql_real_escape_string($qstring);
        $query='SELECT cityname,population,countrycode FROM cities WHERE cityname LIKE "%$qstring%"';
        $result=$connection->query($query);
        if (DB::isError($result)) {
            die("Could not query the database:<br/>".
            $query." ".DB::errorMessage($result));
            }
        echo '<table border="1">';
        echo '<tr><th>City Name</th><th>Population</th><th>Country</th></tr>';
        while ($result_row=$result->fetchRow()) {
            echo '<tr><td>';
            echo $result_row[1]."</td><td>";
            echo $result_row[3]."</td><td>";
            echo $result_row[4]."</td></tr>";
            }
        echo '</table>';
        $connection->disconnect();
       
    }
    ?>
<html>
<head>
</head>
<body>
<?php
$search=htmlentities($_GET['search']);
$self=htmlentities($_SERVER['PHP_SELF']);
if ($search !=NULL) {
    echo "The search string is:".$search;
    query_db($search);
    }
else {
    echo ('
    <form action="'.$self.'" method="GET">
    <p>Search</p>
    <input type="text" name="search"/>
    <input type="submit" value="Go"/>
    </form>
    ');
}
?>
</body>
</html>

Name: Anonymous 2008-11-16 6:07

Okay, now we're fuckin'.


<?php
function query_db($qstring) {
    include('login.php');
    require_once('DB.php');
    $connection=DB::connect("mysql://".$db_username.":".$db_password."@".
    $db_host."/".$db_database);
  
    if (DB::isError($connection)) {
        die ('Could not connect to the database: <br/>'.DB::errorMessage($connection));
        }
    if (get_magic_quotes_gpc()) {
        $qstring=stripslashes($qstring);
        }
        $qstring=mysql_real_escape_string($qstring);
        $query='SELECT cityname,population,countrycode FROM cities WHERE cityname LIKE "%$qstring%"';
        $result=$connection->query($query);
        if (DB::isError($result)) {
            die("Could not query the database:<br/>".
            $query." ".DB::errorMessage($result));
            }
        echo '<table border="1">';
        echo '<tr><th>City Name</th><th>Population</th><th>Country</th></tr>';
        while ($result_row=$result->fetchRow()) {
            echo '<tr><td>';
            echo $result_row[1]."</td><td>";
            echo $result_row[3]."</td><td>";
            echo $result_row[4]."</td></tr>";
            }
        echo '</table>';
        $connection->disconnect();
      
    }
    ?>
<html>
<head>
</head>
<body>
<?php
$search=htmlentities($_GET['search']);
$self=htmlentities($_SERVER['PHP_SELF']);
if ($search !=NULL) {
    echo "The search string is:".$search;
    query_db($search);
    }
else {
    echo ('
    <form action="'.$self.'" method="GET">
    <p>Search</p>
    <input type="text" name="search"/>
    <input type="submit" value="Go"/>
    </form>
    ');
}
?>
</body>
</html>

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List