Hello,
I'm new too the PHP language, we learn it at our school. We're working on a guestbook, but it has to be as they showed us. We have strict rules to make it, and that's where i get stuck. We have to fill in the blanks, i guess you could say. And I don't get it working, and since the teacher is sick this week and we have holiday next week, I won't see my teacher to ask him, so instead I ask it here.
(I'm sorry if my English is not too good, by the way )
Here you have the code:
(My databases connection is working)
----------------------index.php---------------------
<?php
include ('connection.php');
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
include ('verwerkbericht.php');
}
?>
<html><head></head><body>
<?php
$foutmelding = mysql_error();
if(!empty($foutmelding))
echo '<p>' . $foutmelding . '</p>';
include ('toonberichten.php');
?>
<form action="index.php" method="POST">
<h3>Nieuw bericht toevoegen</h3>
<p>Naam:<br /><input type="text" name="naam" /></p>
<p>Bericht:<br /><textarea name="bericht"></textarea></p>
<input type="submit" name="verzendknop" value="verzenden"/>
</form>
</body></html>
------------toonberichten.php---------------(in English: showmessages.php)
<?php
$query = "SELECT naam, bericht, datum FROM gastenboek ORDER BY datum DESC";
$result = mysql_query($query);
echo '<table>';
while($row = mysql_fetch_array($result))
{
$naam=$row['naam'];
echo "de naam: $naam";
}
echo '</table>';
?>
----------------verwerkbericht.php--------------------(in English: something like addmessage.php
<?php
$foutmelding = '';
// $naam = (isset($_POST['naam']))'';
// $bericht = (isset($_POST['bericht']));
// $email = (isset($_POST['email']))
if(empty($naam))
$foutmelding = 'Vul een naam in.';
if(empty($bericht))
$foutmelding = 'Vul een bericht in.';
if (empty($error))
{
$datum = date('Y-m-d');
$query = 'INSERT INTO gastboek (naam, bericht, datum) VALUES (\'' . $naam . '\'. \'' . $bericht . '\'. \'' . $datum . '\');';
return $query;
?>
If you need the example we have been given, tell me, but i don't think it's usefull to you because the explanation is dutch..
What am i doing wrong? The error i get is this:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\wamp\www\wp22\gastenboek\toonberichten.php on line 8
(it's about this part in toonberichten.php: while($row = mysql_fetch_array($result))
{
$naam=$row['naam'];
echo "de naam: $naam";
}
)
I hope you guys can help me.