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:54

Read SICP.

No, really.

is there anything obviously wrong i'm doing?
The thing you are obviously doing wrong is writing horrible code. This particular segment of code happens to have a bug in it, but that is not your problem. Your problem is that the mess you've made makes locating the bug a pain in the ass. You should learn to structure your code right fucking now, webfaggotry can wait.

The best way to accomplish this is by forgeting everything you think you know about programming and reading SICP. You won't believe me, but that's your loss. Have a nice life as a terrible programmer.

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