Jump to content

Little Error


Joshua F

Recommended Posts

Error:

Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\Mpz Scripts\admin\pages1.php on line 109

 

Code:

<?php
  if(isset($_SESSION['admin2'])){
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
  if($_POST['username'] == "" || $_POST['password1'] == "" || $_POST['password2'] == "" || $_POST['mail'] == "" || $_POST['day'] == "" || $_POST['month'] == "" || $_POST['year'] == "" || $_POST['country'] == "-1")
  { 
  echo "<center>You have left 1 or more boxes empty!</center>";
  } else {
    $rrr = mysql_query('SELECT * FROM pages WHERE sn=\'' . realEscape($_POST['sn']) . '\'') ;
    if(mysql_num_rows($rrr) > 0) {
    } echo '<p class="info" id="error"><span class="info_inner">CHECKING DATABASE: Error, Short Name is taken.</span></p>'; 
    } else {
    echo '<p class="info" id="success"><span class="info_inner">CHECKING DATABASE: Scucess, Short Name is not taken.</span></p>';
        mysql_query("INSERT INTO ". $prefix ."users (uname, pass, banned, ip, dob, country, mail, rights, ipbanned, hide_mail) VALUES ('". realEscape($_POST['username']) ."', '". encrypt($_POST['password1']) ."', '0', '". $_SERVER['REMOTE_ADDR'] ."', '". realEscape($_POST['day']) ."/". realEscape($_POST['month']) ."/". realEscape($_POST['year']) ."', '". realEscape($_POST['country']) ."', '". realEscape($_POST['mail']) ."', '0', '0', '". (int)($_POST['hide_mail'] != NULL) ."')");
        }
        }
    } else { echo '<p class="info" id="error"><span class="info_inner">ERROR: Sessions Error, Not Logged In.</span></p>'; } 
    ?>

Link to comment
https://forums.phpfreaks.com/topic/212639-little-error/
Share on other sites

You have if's and else's all over the place. If you indent your code correctly it becomes easier to notice where you open and close if statements. You actually open an if statement and close it straight away, which is probably causing the problem. You could also join the first two statements so it is:

 

if(isset($_SESSION['admin2']) && $_SERVER['REQUEST_METHOD'] == 'POST'){

If you take a look here:

if(mysql_num_rows($rrr) > 0) {
    } echo '<p class="info" id="error"><span class="info_inner">CHECKING DATABASE: Error, Short Name is taken.</span></p>';

You are opening the if statement then closing it straight away, then trying to use an else on it which is probably throwing it all off.

Link to comment
https://forums.phpfreaks.com/topic/212639-little-error/#findComment-1107742
Share on other sites

The bracket that is messing up your code is at the beginning of this line:

 

} echo '<p class="info" id="error"><sp...

 

Remove it and it should parse fine.

look at the line above it..

    if(mysql_num_rows($rrr) > 0) {
    } echo '<p class="info" id="error"><sp

Link to comment
https://forums.phpfreaks.com/topic/212639-little-error/#findComment-1107743
Share on other sites

The bracket that is messing up your code is at the beginning of this line:

 

} echo '<p class="info" id="error"><sp...

 

Remove it and it should parse fine.

look at the line above it..

    if(mysql_num_rows($rrr) > 0) {
    } echo '<p class="info" id="error"><sp

 

If you actually read the code you can see that the bracket I pointed out is not cooperative with the code.  Removing the bracket at the end of the code may make it parse correctly (or maybe not), but it certainly won't make the code do what he is intending.

Link to comment
https://forums.phpfreaks.com/topic/212639-little-error/#findComment-1107744
Share on other sites

Fixed, but when I try to insert it into the database it doesn't do it. It says it did, but it doesn't.

 

Here's my new code.

 

<?php
  if(isset($_SESSION['admin2'])){
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
  if($_POST['name'] == "" || $_POST['sn'] == "" || $_POST['content'] == "")
  { 
  echo '<p class="info" id="warning"><span class="info_inner">You left one or more fields blank.</span></p>';
  } else {
    $rrr = mysql_query('SELECT * FROM pages WHERE sn=\'' . realEscape($_POST['sn']) . '\'') ;
    if(mysql_num_rows($rrr) > 0) {
echo '<p class="info" id="error"><span class="info_inner">CHECKING DATABASE: Error, Short Name is taken.</span></p>'; 
} else {
echo '<p class="info" id="success"><span class="info_inner">CHECKING DATABASE: Scucess, Short Name is not taken.</span></p>';
    mysql_query("INSERT INTO pages (name, sn, content, date, update) VALUES ('". realEscape($_POST['name']) ."', '". encrypt($_POST['sn']) ."', '". encrypt($_POST['content']) ."', NOW(), NOW())");
	}
	}
	}
} else { echo '<p class="info" id="error"><span class="info_inner">ERROR: Sessions Error, Not Logged In.</span></p>'; } 
?>

Link to comment
https://forums.phpfreaks.com/topic/212639-little-error/#findComment-1107747
Share on other sites

You can't use update as a field name in MySQL, as it's a reserved word. If you surround it with those inverted ticks (`) then it should work, however it is recommended you select a different name for your field. Like date_update or something.

Link to comment
https://forums.phpfreaks.com/topic/212639-little-error/#findComment-1107752
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.