Hey I'm trying to make a guest book as a mini project...
but I've already run into some serious trouble regarding mysql commands so I am trying to use a script someone gave me before and obviously it doesn't work right lol...
here it is:
<?php
/ Connecting, selecting database /
$link = mysql_connect("localhost", "root", "omitted")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("guest") or die("Could not select database");
$username = $_POST['name'];
$message = $_POST['message'];
/ Performing SQL query /
$query = "INSERT INTO guest VALUES ('$username', '$message')";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/ Printing results in HTML /
echo "<table>\n";
LINE 16: while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
/ Free resultset /
LINE 26: mysql_free_result($result);
/ Closing connection /
mysql_close($link);
?>
I was hoping that this would add the user and their message to a table I have made...but that's not the case...
It connects to the database but it says that:
Connected successfully
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/htdocs/guest.php on line 16
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /usr/local/htdocs/guest.php on line 26
I have marked where the lines are on the code.
Thanks,
DF