Jump to content

[SOLVED] Syntax error help


jamesxg1

Recommended Posts

i have a problem guys.

 

this is the code

<?php session_start();

include 'Database/Connection.php';
include 'Database/Utility.php';

isloggedin();
accessneeded("C");

if (isset($_POST['Add'])) {

$holder = mysql_real_escape_string($_POST['holder']);
$firstname = mysql_real_escape_string($_POST['firstname']);
$firstname        = ereg_replace(" ", "", $firstname); 
$lastname = mysql_real_escape_string($_POST['lastname']);
$lastname        = ereg_replace(" ", "", $lastname); 
$address = mysql_real_escape_string($_POST['address']);
$postcode = mysql_real_escape_string($_POST['postcode']);
$email = mysql_real_escape_string($_POST['email']);
$email       = ereg_replace(" ", "", $email); 
$pnumber = mysql_real_escape_string(intval($_POST['pnumber']));
$pnumber        = ereg_replace(" ", "", $pnumber); 
$number          = mysql_real_escape_string($_POST['txtNumber']);

if($holder && $firstname && $lastname && $address && $postcode && $email && $pnumber){
$_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^`{|}~]+";
$_host = "([-0-9A-Z]+\.)+";
$_tlds = "([0-9A-Z]){2,4}$/i";

if( !preg_match($_name."@".$_host.$_tlds,$email) ){
	echo "<div align=\"center\">The email you entered is of invalid format.</div>";
      	include("ContactControl.php?contact=Add");
      	die();
}

if (md5($number) == $_SESSION['image_random_value']) {

$sql = sprintf("INSERT INTO `contacts` (`holder`, `firstname`, `lastname`, `address`, `postcode`, `email`, `pnumber`) VALUES('$holder', '$firstname', '$lastname', '$address', '$postcode', '$email', '$pnumber')");
mysql_query($sql) or die(mysql_error());
header('Location: ContactControl.php?contact=Overview');
}

if ($_GET['contact'] == "Add") {

?> 
  <form method="POST" action="ContactControl.php?contact=Add">
<p>
 <b>First Name:</b><br><input type="text" name="firstname" size="20" maxlength="255" />
 </p>
<p>
 <b>Last Name:</b><br><input type="text" name="lastname" size="20" maxlength="255" />
 </p>

<p>
 <b>Address:</b><br><textarea rows="5" cols="40" name="address" id="$address"></textarea>
 </p>

<p>
 <b>Postcode:</b><br><input type="text" name="postcode" size="20" maxlength="255" />
 </p>
<p>
 <b>Email:</b><br><input type="text" name="email" size="20" maxlength="255" />
 </p>
<p>
 <b>Phone Number:</b><br><input type="text" name="pnumber" size="20" maxlength="255" />
 </p>

<p><img src="Security/SecureSubmit.php"></p>

<p><b>Security Code:</b><br><input name="txtNumber" type="text" id="txtNumber" value="" /></p>
<p>
<br><input type="hidden" name="holder" size="20" maxlength="255" value="<?php print $_SESSION['userid'] ?>"/>
 </p>
    <p align="center">
    <input type="submit" name="Add" value="Submit" /> 
     <input type="reset" name="reset" value="Reset Form">
    </p>
  </form>
<?php
}
}
}

if ($_GET['contact'] == "Overview") {

$count = 0;
$query = mysql_query(sprintf("SELECT * FROM contacts WHERE holder = '$_SESSION['userid']'")) or die(mysql_error()); 
while ($row = mysql_fetch_object($query)) { 
if ($count!=0){echo "<br>";}
print "First Name: <font color=red>$row->firstname<br>";
print "Last Name: <font color=red>$row->lastname<br>";
print "Address: <font color=red>$row->address<br>";
print "Postcode: <font color=red>$row->postcode<br>"; 
print "Email: <font color=red>$row->email<br>";
print "Phone Number: <font color=red>$row->pnumber<br>";
$count++;
}
}
?>

 

i get this

 

Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\family\ContactControl.php on line 80

 

but i delete the whole bottom of the code and it is still there. :S

Link to comment
Share on other sites

One thing to remember with PHP is the error can actualy be on the previous line or a line much earlier.

 

Which is line 80?

 

<?php session_start();

include 'Database/Connection.php';
include 'Database/Utility.php';

isloggedin();
accessneeded("C");

if (isset($_POST['Add'])) {

$holder = mysql_real_escape_string($_POST['holder']);
$firstname = mysql_real_escape_string($_POST['firstname']);
$firstname        = ereg_replace(" ", "", $firstname); 
$lastname = mysql_real_escape_string($_POST['lastname']);
$lastname        = ereg_replace(" ", "", $lastname); 
$address = mysql_real_escape_string($_POST['address']);
$postcode = mysql_real_escape_string($_POST['postcode']);
$email = mysql_real_escape_string($_POST['email']);
$email       = ereg_replace(" ", "", $email); 
$pnumber = mysql_real_escape_string(intval($_POST['pnumber']));
$pnumber        = ereg_replace(" ", "", $pnumber); 
$number          = mysql_real_escape_string($_POST['txtNumber']);

if($holder && $firstname && $lastname && $address && $postcode && $email && $pnumber){
$_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^`{|}~]+";
$_host = "([-0-9A-Z]+\.)+";
$_tlds = "([0-9A-Z]){2,4}$/i";

if( !preg_match($_name."@".$_host.$_tlds,$email) ){
	echo "<div align=\"center\">The email you entered is of invalid format.</div>";
      	include("ContactControl.php?contact=Add");
      	die();
}

if (md5($number) == $_SESSION['image_random_value']) {

$sql = sprintf("INSERT INTO `contacts` (`holder`, `firstname`, `lastname`, `address`, `postcode`, `email`, `pnumber`) VALUES('$holder', '$firstname', '$lastname', '$address', '$postcode', '$email', '$pnumber')");
mysql_query($sql) or die(mysql_error());
header('Location: ContactControl.php?contact=Overview');
}

if ($_GET['contact'] == "Add") {

?> 
  <form method="POST" action="ContactControl.php?contact=Add">
<p>
 <b>First Name:</b><br><input type="text" name="firstname" size="20" maxlength="255" />
 </p>
<p>
 <b>Last Name:</b><br><input type="text" name="lastname" size="20" maxlength="255" />
 </p>

<p>
 <b>Address:</b><br><textarea rows="5" cols="40" name="address" id="$address"></textarea>
 </p>

<p>
 <b>Postcode:</b><br><input type="text" name="postcode" size="20" maxlength="255" />
 </p>
<p>
 <b>Email:</b><br><input type="text" name="email" size="20" maxlength="255" />
 </p>
<p>
 <b>Phone Number:</b><br><input type="text" name="pnumber" size="20" maxlength="255" />
 </p>

<p><img src="Security/SecureSubmit.php"></p>

<p><b>Security Code:</b><br><input name="txtNumber" type="text" id="txtNumber" value="" /></p>
<p>
<br><input type="hidden" name="holder" size="20" maxlength="255" value="<?php print $_SESSION['userid'] ?>"/>
 </p>
    <p align="center">
    <input type="submit" name="Add" value="Submit" /> 
     <input type="reset" name="reset" value="Reset Form">
    </p>
  </form>
<?php
}
}
}
?>

 

ithe the second * } * out of the bottom three

Link to comment
Share on other sites

If you indented your code properly, it would be easy to ensure that every opening bracket was being closed. In your posted code however, there's 10 pairs of brackets that seem fine. I think the error could be in one of the included files.

Link to comment
Share on other sites

I've reformatted it and make a couple minor changes...

<?php
session_start();

include 'Database/Connection.php';
include 'Database/Utility.php';

isloggedin();
accessneeded("C");

if (isset($_POST['Add'])) {

  $holder     = mysql_real_escape_string($_POST['holder']);
  $firstname  = mysql_real_escape_string($_POST['firstname']);
  $firstname  = ereg_replace(" ", "", $firstname); 
  $lastname   = mysql_real_escape_string($_POST['lastname']);
  $lastname   = ereg_replace(" ", "", $lastname); 
  $address    = mysql_real_escape_string($_POST['address']);
  $postcode   = mysql_real_escape_string($_POST['postcode']);
  $email      = mysql_real_escape_string($_POST['email']);
  $email      = ereg_replace(" ", "", $email); 
  $pnumber    = mysql_real_escape_string(intval($_POST['pnumber']));
  $pnumber    = ereg_replace(" ", "", $pnumber); 
  $number     = mysql_real_escape_string($_POST['txtNumber']);

  if($holder && $firstname && $lastname && $address && $postcode && $email && $pnumber) {
    $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^`{|}~]+";
    $_host = "([-0-9A-Z]+\.)+";
    $_tlds = "([0-9A-Z]){2,4}$/i";
     
    if( !preg_match($_name."@".$_host.$_tlds,$email) ){
      echo "<div align=\"center\">The email you entered is of invalid format.</div>";
         include("ContactControl.php?contact=Add");
         die();
    }

    if (md5($number) == $_SESSION['image_random_value']) {

      $sql = "INSERT INTO `contacts` (`holder`, `firstname`, `lastname`, `address`, `postcode`, `email`, `pnumber`) VALUES('$holder', '$firstname', '$lastname', '$address', '$postcode', '$email', '$pnumber')";
      mysql_query($sql) or die(mysql_error());
      header('Location: ContactControl.php?contact=Overview');
    }

    if ($_GET['contact'] == "Add") { ?>
      <form method="POST" action="ContactControl.php?contact=Add">
      <p><b>First Name:</b><br><input type="text" name="firstname" size="20" maxlength="255" /></p>
      <p><b>Last Name:</b><br><input type="text" name="lastname" size="20" maxlength="255" /></p>

      <p><b>Address:</b><br><textarea rows="5" cols="40" name="address" id="$address"></textarea></p>

      <p><b>Postcode:</b><br><input type="text" name="postcode" size="20" maxlength="255" /></p>
      <p><b>Email:</b><br><input type="text" name="email" size="20" maxlength="255" /></p>
      <p><b>Phone Number:</b><br><input type="text" name="pnumber" size="20" maxlength="255" /></p>

      <p><img src="Security/SecureSubmit.php" /></p>

      <p><b>Security Code:</b><br><input name="txtNumber" type="text" id="txtNumber" value="" /></p>
      <p><br><input type="hidden" name="holder" size="20" maxlength="255" value="<?php print $_SESSION['userid']; ?>"/></p>
      <p align="center">
      <input type="submit" name="Add" value="Submit" />
      <input type="reset" name="reset" value="Reset Form" />
      </p>
      </form>
    <?php }
  }
}
?>

Link to comment
Share on other sites

I've just checked all the quotes etc. and I'm also thinking the problem is in one of the includes.

 

Try removing everything inside that file so it's just like this and try it again:

<?php
session_start();

include 'Database/Connection.php';
include 'Database/Utility.php';

isloggedin();
accessneeded("C")?>

 

If you get the error still it's the includes.

Link to comment
Share on other sites

I've just checked all the quotes etc. and I'm also thinking the problem is in one of the includes.

 

Try removing everything inside that file so it's just like this and try it again:

<?php
session_start();

include 'Database/Connection.php';
include 'Database/Utility.php';

isloggedin();
accessneeded("C")?>

 

If you get the error still it's the includes.

 

the includes are all ok as i use them on every page in my server and i have the script working (kinda) you see i have no errors but it also isnt displaying anything any ideas or reason for this :S ?

 

<?php
session_start();

include 'Database/Connection.php';
include 'Database/Utility.php';

isloggedin();
accessneeded("C");

if (isset($_POST['Add'])) {

  $holder     = mysql_real_escape_string($_POST['holder']);
  $firstname  = mysql_real_escape_string($_POST['firstname']);
  $firstname  = ereg_replace(" ", "", $firstname); 
  $lastname   = mysql_real_escape_string($_POST['lastname']);
  $lastname   = ereg_replace(" ", "", $lastname); 
  $address    = mysql_real_escape_string($_POST['address']);
  $postcode   = mysql_real_escape_string($_POST['postcode']);
  $email      = mysql_real_escape_string($_POST['email']);
  $email      = ereg_replace(" ", "", $email); 
  $pnumber    = mysql_real_escape_string(intval($_POST['pnumber']));
  $pnumber    = ereg_replace(" ", "", $pnumber); 
  $number     = mysql_real_escape_string($_POST['txtNumber']);

  if($holder && $firstname && $lastname && $address && $postcode && $email && $pnumber) {
    $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^`{|}~]+";
    $_host = "([-0-9A-Z]+\.)+";
    $_tlds = "([0-9A-Z]){2,4}$/i";
     
    if( !preg_match($_name."@".$_host.$_tlds,$email) ){
      echo "<div align=\"center\">The email you entered is of invalid format.</div>";
         include("ContactsControl.php?contact=Add");
         die();
    }

    if (md5($number) == $_SESSION['image_random_value']) {

      $sql = "INSERT INTO `contacts` (`holder`, `firstname`, `lastname`, `address`, `postcode`, `email`, `pnumber`) VALUES('$holder', '$firstname', '$lastname', '$address', '$postcode', '$email', '$pnumber')";
      mysql_query($sql) or die(mysql_error());
      header('Location: ContactsControl.php?contact=Overview');
    }

    if ($_GET['contact'] == "Add") { 
?>
      <form method="POST" action="ContactControl.php?contact=Add">
      <p><b>First Name:</b><br><input type="text" name="firstname" size="20" maxlength="255" /></p>
      <p><b>Last Name:</b><br><input type="text" name="lastname" size="20" maxlength="255" /></p>

      <p><b>Address:</b><br><textarea rows="5" cols="40" name="address" id="$address"></textarea></p>

      <p><b>Postcode:</b><br><input type="text" name="postcode" size="20" maxlength="255" /></p>
      <p><b>Email:</b><br><input type="text" name="email" size="20" maxlength="255" /></p>
      <p><b>Phone Number:</b><br><input type="text" name="pnumber" size="20" maxlength="255" /></p>

      <p><img src="Security/SecureSubmit.php" /></p>

      <p><b>Security Code:</b><br><input name="txtNumber" type="text" id="txtNumber" value="" /></p>
      <p><br><input type="hidden" name="holder" size="20" maxlength="255" value="<?php print $_SESSION['userid']; ?>"/></p>
      <p align="center">
      <input type="submit" name="Add" value="Submit" />
      <input type="reset" name="reset" value="Reset Form" />
      </p>
      </form>
    <?php
}
  }
}

if ($_GET['contact'] == "Overview") {

$userid = $_SESSION['userid'];

$count = 0;
$query = mysql_query(sprintf("SELECT * FROM contacts WHERE holder = '$userid'")) or die(mysql_error()); 
while ($row = mysql_fetch_object($query)) { 
if ($count!=0){echo "<br>";}
print "First Name: <font color=red>$row->firstname<br>";
print "Last Name: <font color=red>$row->lastname<br>";
print "Address: <font color=red>$row->address<br>";
print "Postcode: <font color=red>$row->postcode<br>"; 
print "Email: <font color=red>$row->email<br>";
print "Phone Number: <font color=red>$row->pnumber<br>";
$count++;
}
}
?>

Link to comment
Share on other sites

It just means that 'contact' isn't a key in the $_GET array. I.e. contact is not set in the URL. Shouldn't cause any trouble though.

 

hiya,

 

well for some reason no matter what url i use be it contact=Overview OR contact=Add none of them work :S

 

any ideas why ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.