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

Pages: 1-

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 5:31

shitshitshit how do i format my code like everyone else is doing? is it [code]?

Name: Anonymous 2008-11-16 5:45

Sagesage!

Name: Anonymous 2008-11-16 5:56

>>2
Hey, I wanted to flame you for not using [m][code][/m] tags.

Name: Anonymous 2008-11-16 6:06

>>4

zurrhurrhurr

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>

Name: Anonymous 2008-11-16 6:07

>>4
Hey, I wanted to flame you for not using [#] tags.

Name: Anonymous 2008-11-16 6:08

Well that was exciting.

Name: Anonymous 2008-11-16 6:08

>>7

What are you even

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.

Name: Anonymous 2008-11-16 7:17

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

On the contrary, that is the best reason to kill you.

Name: Anonymous 2008-11-16 7:41

>>10

Alright, now that we've cleared up what my problem is, could you tell me what the specific problem with the code is that is making it not function correctly?

P.S. I'm following an example in a book.

Name: Anonymous 2008-11-16 10:26

1) Use SELECT *. It's fast.
2) Use mysql_fetch_assoc() and print_r() for debugging.
3) Read SICP
4) Also, Back to /pr/, please.

Name: Anonymous 2008-11-16 11:28

Copy and paste oriented programming.

Name: Anonymous 2008-11-16 12:29

>>6
Everything I have to say has been covered by >>10.

Name: Anonymous 2008-11-16 12:31

Why do you think it's better to bother all of us than to insert a few debugging statements?  It's obvious you're not interested in learning anything, so please take this to a more amateur board.

http://7chan.org/pr/ would be a good start.

Name: Anonymous 2010-12-17 1:35

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2013-04-09 18:26


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