Web Hosting Talk







View Full Version : php my ...


danbob185
06-24-2005, 07:23 AM
Parse error: syntax error, unexpected T_ELSE in c:\program files\apache group\Apache\htdocs\rapidrepair.php on line 78

I keep getting this error in the following script. I know it's a little untidy but I'm very new at this. Also I maxed out the length of the entry?

Please help....

<php if (isset($_GET['addentry'])):
?>
<p align="center" />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="radio" name="rapid" value="RR001A" />
<input type="radio" name="rapid" value="RR002A" />
<input type="submit" value="submit" /></form>
<?php else:
$dbcnx = @mysql_connect('localhost', 'root', '**********');
if (!$dbcnx) {
exit('<p class="top" />Unable to connect to the ' .
'database server at this time.');
}
if (!@mysql_select_db('rr')) {
exit('<p class="top" />Can't connect to database.');
}
if (isset($_POST['code'])) {
$code = $_POST['code'];
$sql = "INSERT INTO stats SET
code='$code',
repairdate=CURDATE()";
if (@mysql_query($sql)) {
echo '<p class="top" />Entry added';
} else {
echo '<p class="top" />Error, please try again: ' .
mysql_error();
}
}
echo '<p class="top" /><a href="' . $_SERVER['PHP_SELF'] . '?addentry=1">New Entry</a>';
endif;
?>

insanelymacintosh
06-24-2005, 08:15 AM
Which line is line 78?

danbob185
06-24-2005, 08:30 AM
</form>

I had to condense it a bit to post it but the line is just </form>

Pheaton
06-24-2005, 09:13 AM
Well first of all, your not using php syntax for your if statements. If statements go like so:

if (condition) {
// your php code
} else {
// your other php code
}


Try this code. I cleaned it up a bit for you.

<?php if (isset($_GET['addentry'])) { ?>
<p align="center" />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="radio" name="rapid" value="RR001A" />
<input type="radio" name="rapid" value="RR002A" />
<input type="submit" value="submit" /></form>
<? } else {
$dbcnx = @mysql_connect('localhost', 'root', '**********');
if (!$dbcnx) {
exit('<p class="top" />Unable to connect to the ' .
'database server at this time.');
}
if (!@mysql_select_db('rr')) {
exit('<p class="top" />Can\\'t connect to database.');
}
if (isset($_POST['code'])) {
$code = $_POST['code'];
$sql = "INSERT INTO stats SET code='$code', repairdate=CURDATE()";
if (@mysql_query($sql)) {
echo '<p class="top" />Entry added';
} else {
echo '<p class="top" />Error, please try again: ' .
mysql_error();
}
}
echo '<p class="top" /><a href="' . $_SERVER['PHP_SELF'] . '?addentry=1">New Entry</a>';
}
?>

Note that the following line should have a backslash before the ' in Can't, but the php bb code on the forums isnt recognizing it for some reason.

exit('<p class="top" />Can\'t connect to database.');

danbob185
06-24-2005, 09:45 AM
Thank you soooooooo much!

I suppose I'll catch on eventually, but atleast I can make sense of the answer.

Pheaton
06-24-2005, 10:57 AM
No problem. :D

Burhan
06-25-2005, 02:01 AM
Well first of all, your not using php syntax for your if statements. If statements go like so:

The syntax he is using is valid. Read Alternative syntax to control structures (http://www.php.net/manual/en/control-structures.alternative-syntax.php) in the manual :)

Pheaton
06-25-2005, 08:53 AM
Originally posted by fyrestrtr
The syntax he is using is valid. Read Alternative syntax to control structures (http://www.php.net/manual/en/control-structures.alternative-syntax.php) in the manual :)


Hmm, I didn't know what. I've never seen it used anywhere. Thanks for letting me know. :)

VolkNet
06-25-2005, 03:36 PM
Interesting...

Is there any sort of advantage to using that type? Thanks.

Burhan
06-27-2005, 02:44 AM
No, there is no advantage. Its just a personal preference. Although what he (the op) was doing is mixing and matching, which is never a good idea.