fout in script
in mijn eerste php-scriptje zit een fout waar ik al een tijd mijn hoofd op breek, maar die ik er niet uit krijg. Kan iemand me helpen?
Het gaat om het simpel toevoegen van nieuwsitems aan een website, in de vorm van een weblog. Dit is de code:
_________________________________________
toevoegen van item via form:
<form method="POST" action="addentry.php">
<input type="text" name="entrytitle">
<textarea cols="60" rows="6" name="entrytext"></textarea<input type="password" cols="10" rows="1" name="password"></textarea>
<input type="submit" name="submit" value="Voeg toe">
_________________________________________
addentry.php (login en passwords vervangen door ****)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
if ($HTTP_POST_VARS['submit']) {
mysql_connect("localhost","*****","*****");
mysql_select_db("ltcnieuw");
$entrytitle=$HTTP_POST_VARS['entrytitle'];
$entrytext=$HTTP_POST_VARS['entrytext'];
$password='*********';
$query ="INSERT INTO weblog (entrytitle,entrytext)";
$query.=" VALUES ('$entrytitle','$entrytext')";
$result=mysql_query($query);
if ($result)
echo "<b>Het item is toegevoegd!</b>";
else echo "<b>ERROR: niet mogelijk om een item toe te voegen.</b>"; } ?>
if ($HTTP_POST_VARS['submit']) {
mysql_connect("localhost","*****","*****");
mysql_select_db("ltcnieuw");
$entrytitle=$HTTP_POST_VARS['entrytitle'];
$entrytext=$HTTP_POST_VARS['entrytext'];
$password='*********';
$query ="INSERT INTO weblog (entrytitle,entrytext)";
$query.=" VALUES ('$entrytitle','$entrytext')";
$result=mysql_query($query);
if ($result)
echo "<b>Het item is toegevoegd!</b>";
else echo "<b>ERROR: niet mogelijk om een item toe te voegen.</b>"; } ?>
________________________________________
Uitlezen van entries:
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
<?php mysql_connect("localhost","********","*****"); mysql_select_db("racketnieuw");
$query ="SELECT entrytitle, entrytext,";
$query.=" DATE_FORMAT(entrydate, '%M %d, %Y') AS date";
$query.=" FROM weblog ORDER BY entrydate DESC LIMIT 10";
$result=mysql_query($query);
while (list($entrytitle,$entrytext,$entrydate) = mysql_fetch_row($result))
{ echo "<dt><b>$entrytitle ($entrydate)</b></dt>";
echo "<dd>$entrytext</dd>"; } ?>
$query ="SELECT entrytitle, entrytext,";
$query.=" DATE_FORMAT(entrydate, '%M %d, %Y') AS date";
$query.=" FROM weblog ORDER BY entrydate DESC LIMIT 10";
$result=mysql_query($query);
while (list($entrytitle,$entrytext,$entrydate) = mysql_fetch_row($result))
{ echo "<dt><b>$entrytitle ($entrydate)</b></dt>";
echo "<dd>$entrytext</dd>"; } ?>
Het toevoegen van de items aan de database gaat goed, maar bij het uitlezen van de items gaat het fout. De volgende error verschijnt:
Parse error: parse error, unexpected T_ELSE in /srv/rackets/www/www.ltcrackets.nl/content.php on line 38
Kan iemand me helpen? Het zal wel een simpele oplossing zijn, maar ik zie 'm niet!
Alvast bedankt!
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
if ($HTTP_POST_VARS['submit']) {
mysql_connect("localhost","*****","*****");
mysql_select_db("ltcnieuw");
$entrytitle=$HTTP_POST_VARS['entrytitle'];
$entrytext=$HTTP_POST_VARS['entrytext'];
$password='*********';
$query ="INSERT INTO weblog (entrytitle,entrytext)";
$query.=" VALUES ('$entrytitle','$entrytext')";
$result=mysql_query($query);
if ($result)
echo "<b>Het item is toegevoegd!</b>";
else{
echo "<b>ERROR: niet mogelijk om een item toe te voegen.</b>"; }} ?>
if ($HTTP_POST_VARS['submit']) {
mysql_connect("localhost","*****","*****");
mysql_select_db("ltcnieuw");
$entrytitle=$HTTP_POST_VARS['entrytitle'];
$entrytext=$HTTP_POST_VARS['entrytext'];
$password='*********';
$query ="INSERT INTO weblog (entrytitle,entrytext)";
$query.=" VALUES ('$entrytitle','$entrytext')";
$result=mysql_query($query);
if ($result)
echo "<b>Het item is toegevoegd!</b>";
else{
echo "<b>ERROR: niet mogelijk om een item toe te voegen.</b>"; }} ?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
mysql_connect("localhost","racket01","racket01");
mysql_select_db("ltcnieuw");
$query ="SELECT entrytitle, entrytext";
$query.="DATE_FORMAT(entrydate, '%M %d, %Y') AS date";
$query.="FROM weblog ORDER BY entrydate DESC LIMIT 10";
$result=mysql_query($query);
while (list($entrytitle,$entrytext,$entrydate) = mysql_fetch_row($result))
{echo "<dt><b>$entrytitle ($entrydate)</b></dt>";
echo "<dd>$entrytext</dd>";
}
?>
mysql_connect("localhost","racket01","racket01");
mysql_select_db("ltcnieuw");
$query ="SELECT entrytitle, entrytext";
$query.="DATE_FORMAT(entrydate, '%M %d, %Y') AS date";
$query.="FROM weblog ORDER BY entrydate DESC LIMIT 10";
$result=mysql_query($query);
while (list($entrytitle,$entrytext,$entrydate) = mysql_fetch_row($result))
{echo "<dt><b>$entrytitle ($entrydate)</b></dt>";
echo "<dd>$entrytext</dd>";
}
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
<?php
mysql_connect("localhost","racket01","racket01");
mysql_select_db("ltcnieuw");
$sql = "SELECT entrytitle, entrytext DATE_FORMAT(entrydate, '%M %d, %Y') AS date FROM weblog ORDER BY entrydate DESC LIMIT 10";
$res = mysql_query($sql) or die (mysql_error());
while($list = mysql_fetch_object($res))
{
echo "<dt><b>" . $list->entrytitle . "</b></dt>";
echo "<dd>" . $list->entrytext . "</dd>";
}
?>
mysql_connect("localhost","racket01","racket01");
mysql_select_db("ltcnieuw");
$sql = "SELECT entrytitle, entrytext DATE_FORMAT(entrydate, '%M %d, %Y') AS date FROM weblog ORDER BY entrydate DESC LIMIT 10";
$res = mysql_query($sql) or die (mysql_error());
while($list = mysql_fetch_object($res))
{
echo "<dt><b>" . $list->entrytitle . "</b></dt>";
echo "<dd>" . $list->entrytext . "</dd>";
}
?>