Hello,
I'm having this same problem.
I want to make a shoutbox but I get this error in my page.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
This is my code.
<?php
// You just need to configure these 4 variables to match your server.
$db_host = "localhost"; // mySQL database host
$db_user = "www_eod1"; // mySQL database user
$db_password = "somepassword"; // mySQL database password
$db_name = "www_eod1"; // the name of your mySQL database
// If a user has submitted a post, we want to :
// 1. Validate it
// 2. Strip unwanted html
// 3. Make sure messages and names aren't too long
// 4. Add it to our database.
if($_POST['submit']) {
// 1. Validate it, by checking all the form inputs were filled in
if(!$_POST['author']) {
echo 'Error ! : Geen naam ingevuld!';
die;
}
if(!$_POST['eml']) {
echo 'Error ! : Geen email ingevuld!';
die;
}
if(!$_POST['message']) {
echo 'Error ! : Geen bericht ingevuld!';
die;
}
// 2. Strip unwanted HTML
// Look up the strip_tags() function at
// http://www.php.net/manual/en/function.strip-tags.php for more info
$message = strip_tags($_POST['message'], '');
$eml = strip_tags($_POST['eml'], '');
$author = strip_tags($_POST['author'], '');
// 3. Make sure messages and names aren't too long
// We will use the strlen() function to count the length.
$message_length = strlen($message);
$author_length = strlen($author);
if($message_length > 150) {
echo "Error ! : Je bericht was te lang, je kan maximaal 150 karakters gebruiken!";
die;
}
if($author_length > 150) {
echo "Error ! : Je naam was te lang, je kan maximaal 150 karakters gebruiken";
die;
}
// 4. Add it to our database.
// If the script hasn't died yet due to an error in the inputted data
// we need to add the data to the database
// Lets connect to our database.
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
// Select the database.
mysql_select_db($db_name) or die(mysql_error());
// Lets define the date format we want to enter to our database
// go here for more details
// http://www.php.net/manual/en/function.date.php
$date = date("h:i A dS M");
// This will produce 11:02 25th Aug
// Set the query as $query
$query = "INSERT INTO shoutbox (message, author, eml, date, ip)
VALUES ('$message','$author','$eml','$date','$_SERVER[REMOTE_ADDR]')";
mysql_query($query);
mysql_close();
// Show thanks message and take them back to the main shoutbox
echo "<head><meta http-equiv='refresh' content='2;url=protected.php?voorstellen'></head><center><p> <p>Bedankt voor je bericht!";
// If they haven't submitted a post, we want to :
// 1. Show the latest shouts
// 2. Show the shout post form
} else {
// 1. Show the latest shouts
// Lets connect to our database.
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
// Select the database.
mysql_select_db($db_name) or die(mysql_error());
// Set the query as $query, and get the last 10 posts.
$query = "SELECT message, author, eml, date, ip
FROM shoutbox order by id DESC LIMIT 100";
$result = mysql_query($query);
echo "<TABLE>";
while(($r = mysql_fetch_array($result)))
{
// To modify the appearance, edit this :
echo "<body bgcolor='1e1e1e' text='white' link='orange' vlink='orange' alink='orange'><TR>
<TD><font size='2'>
Gepost om $r[date] door <A HREF='mailto:$r[eml]'>
$r[author]</A></font></TD>
</TR>
<TR>
<TD><font size='1'>$r[message]</font></TD>
</TR>
<TR>
<TD><HR></TD>
</TR>";
}
echo "</TABLE>";
// 2. Show the shout post form
?>
<?php
}
?>
The problem is at line 77 (almoste at the bottom :p )
Could someone plz help me :o
Regards