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
https://forums.phpfreaks.com/topic/153170-solved-syntax-error-help/
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

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 }
  }
}
?>

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.

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++;
}
}
?>

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 ?

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.