Unexpected T_IF error doesn't make sense :(
Posted: Sun Jun 26, 2011 8:11 am
Hi, I am creating a very simple CMS, and I'm adding a function to give the user the ability to call the subjects anything , such as "Subject1" €Subject2* %&Subject3!?=#, e.t.c without breaking the code.
But when I execute the code it just returns an error that says:
PHP Parse error: syntax error, unexpected T_IF in - on line 9
Here is my code:
I have looked it through up and down, but simply can't find the error, so I was wondering if some of you guys could seek it out for me 
Thanks a million in advance
------------------------------------------------------------------------------------
Don't know it this will help you, but the function is used by another document which contains this code:
But when I execute the code it just returns an error that says:
PHP Parse error: syntax error, unexpected T_IF in - on line 9
Here is my code:
Code: Select all
function mysql_prep( $value ) {
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e PHP >= v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work.
if( $magic_quotes_active ) { $value = stripslashes($value); }
$value = mysql_real_escape_string($value);
} else { // before php v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes($value); }
// if magic quotes are active, then slashes already exist
}
return $value;
}Thanks a million in advance
------------------------------------------------------------------------------------
Don't know it this will help you, but the function is used by another document which contains this code:
Code: Select all
<?php require_once('include/dbConnection.php'); ?>
<?php require_once('include/functions.php'); ?>
<?php
$menu_name = mysql_prep($_POST['menu_name']);
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
?>
<?php
$query = "INSERT INTO subjects (
menu_name, position, visible
) VALUES (
'{$menu_name}', {$position}, {$visible}
)";
$result = mysql_query($query, $connection);
if($result) {
// SUCCESS
header("Location: content.php");
exit;
} else {
// Display error message
echo "<p>Subject creation failed</p>";
echo "<p>" . mysql_error() . "</p>";
}
?>
<?php
mysql_close($connection);
?>