If else statement fout , §end miserie
Parse error: syntax error, unexpected '}' in C:\wamp\www\a\news.php on line 109
Uitleg over hoe ik tewerk ging:
Dit deel dient om een comment te adden op een newspost
1)Eerste If clause: is er op de submit knop gedrukt, maw zijn er gegevens ingevoert
2)gegevens ophalen ff controleren of ze ingevult zijn etc
3)a. Foutmelding geven
3)b. Gegevens ingeven
______________________________________
______________________________________
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php if (isset($_POST['submit'])) {
$naam = nl2br($_POST["naam"]);
$email = nl2br($_POST["email"]);
$nid = $_POST["nid"];
$reactie = nl2br($_POST["reactie"]);
if ($reactie=="")
{ $error=$error."<table cellspacing='0' width='90%'><tr><td align='center'>Please fill in the comment form.</td></tr></table>\n"; }
else { }
if ($naam=="")
{ $error=$error."<table cellspacing='0' width='90%'><tr><td align='center'>Please fill in the comment form.</td></tr></table>\n"; }
else { }
if ($email=="")
{ $error=$error."<table cellspacing='0' width='90%'><tr><td align='center'>Please fill in the comment form.</td></tr></table>\n"; }
else { }
if ($error) { ?>
$naam = nl2br($_POST["naam"]);
$email = nl2br($_POST["email"]);
$nid = $_POST["nid"];
$reactie = nl2br($_POST["reactie"]);
if ($reactie=="")
{ $error=$error."<table cellspacing='0' width='90%'><tr><td align='center'>Please fill in the comment form.</td></tr></table>\n"; }
else { }
if ($naam=="")
{ $error=$error."<table cellspacing='0' width='90%'><tr><td align='center'>Please fill in the comment form.</td></tr></table>\n"; }
else { }
if ($email=="")
{ $error=$error."<table cellspacing='0' width='90%'><tr><td align='center'>Please fill in the comment form.</td></tr></table>\n"; }
else { }
if ($error) { ?>
<table border="1" cellspacing='0' style='border-collapse: collapse;' cellpadding='0' cellspacing='0' width='90%'>
<tr>
<td><strong>Comments:</strong></td>
</tr>
<tr>
<td></td>
</tr>
</table>
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
}else{
$query="INSERT INTO newsreacties (nid, naam, email, reactie) VALUES ('$id', '$naam', '$email', '$reactie');";
mysql_query($query) or die(mysql_error());
?>
}else{
$query="INSERT INTO newsreacties (nid, naam, email, reactie) VALUES ('$id', '$naam', '$email', '$reactie');";
mysql_query($query) or die(mysql_error());
?>
<table border="0" cellspacing='0' style='border-collapse: collapse;' cellpadding='0' cellspacing='0' width='90%'>
<tr>
<td><strong>Comments:</strong></td>
</tr>
<tr>
<td align='center'>Comment added succesfull, $naam !<br><a href=''>Click here</a> to go back to the newspost.
</td>
</tr>
</table>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
}
}else{
echo "<form action='' method='post'>\n";
echo "<table border='0' bordercolor='#000000' cellspacing='0' style='border-collapse: collapse;' cellpadding='0' cellspacing='0' width='90%'>\n";
echo " <tr>\n";
echo " <td><strong>Comments:</strong></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>\n";
echo " <table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
echo " <tr>\n";
echo " <td width='120' valign='top'>Name:</td>\n";
echo " <td width='250'> <input name='naam' type='text id='naam' size="20">\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td width='120' valign='top'>Email:</td>\n";
echo " <td width='250'> <input name='email' type='text id='naam' size="50">\n";
echo " </tr>\n";
echo " <td width='120' valign='top'>Comments:</td>\n";
echo " <td width='250'><textarea name='reactie' rows='4' cols='50'></textarea></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " <center><input type='hidden' value='$id' name='nid'><input type='submit' value='Add' name='submit'> <input type='reset' value='Reset' name='reset'></center>\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "<br><br><center><a href='index.php?page=news'>Go back</a></center>";
}
}
}else{
echo "<form action='' method='post'>\n";
echo "<table border='0' bordercolor='#000000' cellspacing='0' style='border-collapse: collapse;' cellpadding='0' cellspacing='0' width='90%'>\n";
echo " <tr>\n";
echo " <td><strong>Comments:</strong></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>\n";
echo " <table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
echo " <tr>\n";
echo " <td width='120' valign='top'>Name:</td>\n";
echo " <td width='250'> <input name='naam' type='text id='naam' size="20">\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td width='120' valign='top'>Email:</td>\n";
echo " <td width='250'> <input name='email' type='text id='naam' size="50">\n";
echo " </tr>\n";
echo " <td width='120' valign='top'>Comments:</td>\n";
echo " <td width='250'><textarea name='reactie' rows='4' cols='50'></textarea></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " <center><input type='hidden' value='$id' name='nid'><input type='submit' value='Add' name='submit'> <input type='reset' value='Reset' name='reset'></center>\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "<br><br><center><a href='index.php?page=news'>Go back</a></center>";
}
ik heb dat zojuist voor je gedaan, en de } van de allereerste if die helemaal op het eind moet ontbreekt.
overigens is het niet verplicht om altijd een else te gebruiken, dus die else { } bij de 2e, 3e en 4e if kun je gerust weghalen.
ook zag ik een if en twee else achter elkaar staan. ik weet niet of dat goed gaat, over het algemeen gebruik je dan if, elsif, else
Aha bedankt, ik heb de hele tijd zitten zoeken naar het php equivalent van de elseif in Basic, maar dat is dus elsif :D (sorry het heeft niks met dit topic te maken)