View Single Post
09-30-2009, 08:30 PM
#4
46Bit is offline 46Bit
Status: Member
Join date: Mar 2009
Location: Yorkshire
Expertise: Web Development
Software:
 
Posts: 275
iTrader: 10 / 100%
 

46Bit is on a distinguished road

Send a message via MSN to 46Bit Send a message via Skype™ to 46Bit

  Old

Originally Posted by Patrick View Post
Change:

Code:
$result = mysql_query($sql, $connection);
To:

Code:
$res = mysql_query($sql, $connection);
And:

Code:
while ($myRow = mysql_fetch_array($result)) {
To:

Code:
while ($myRow = mysql_fetch_array($res)) {
Erm, that won't achieve anything...

Anyway, here's a version that's fixed in various places, and has some minor code changes that I'd personally consider more best practices.
PHP Code:
<html>
<head>
<title>Lab 4</title>
</head>
<body>
<?
$connection 
mysql_connect("HOST_HERE""USER_HERE""PASSWORD_HERE") or die ("Kunde inte an****a!");

mysql_select_db("DB_NAME_HERE"$connection);

$input $_POST['revealThis'];

if (
$input == 'debattartiklar') {
    
$sql "SELECT * FROM debatt";
} elseif (
$input == 'eva') {
    
$sql "SELECT * FROM debatt, sports WHERE forfattare='Eva Svensson'";
} else {
    echo 
"Du valde inget alternativ, vänligen välj ett";
}
    
$result mysql_query($sql$connection);

while (
$myRow mysql_fetch_assoc($result)) {
        echo 
"<h3 style=\"line-height:1.5em; margin:0; padding:0;\">{$myRow['rubrik']}</h3>";
        echo 
"<strong>{$myRow['ingress']}</strong><br />";
        echo 
"{$myRow['brodtext']}<br />";
        echo 
"{$myRow['forfattare']}{$myRow['datum']}<br /><br />";
}

mysql_close($connection);

?>
</body>
</html>
Also take a look into mysqli instead of mysql.

Reply With Quote