Jump to content

SQL unexpected error


abch624

Recommended Posts

I have an sql statement in a php file, when the code reaches this line then it give me an error

"Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\join.php on line 131"....

$sql = "UPDATE venue SET name='$_POST['venu_name']',
   							address1='$_POST['address']',
						city='$_POST['city'],
						postcode='$_POST['postcode']',
						telephone='$_POST['telephone']',
						fax='$_POST['fax']',
						email='$_POST['email']',
						contactname='$_POST['contactname']'
						WHERE venueid='$_POST['$result3']'";

Please any help...

Link to comment
https://forums.phpfreaks.com/topic/75955-sql-unexpected-error/
Share on other sites

Use concatenations the single quotes in the index's are messing it up

<?php
//example
city='".$_POST['city']."'
?>

Tried doesnt work

 

I thought of just putting all the code

The code that generates the error:

<?php
include $_SERVER['DOCUMENT_ROOT'].'/mini.php';
include $_SERVER['DOCUMENT_ROOT'].'/layout.php';

switch($_REQUEST['req']){
case "process":

   // Validate all required fields were posted
   if(!$_POST['venu_name'] ||
      !$_POST['address'] ||
      !$_POST['city'] ||
      !$_POST['postcode'] ||
      !$_POST['telephone'] ||
      !$_POST['fax'] ||
      !$_POST['email'] ||
      !$_POST['contactname']){
        
         $error = true;
         $errors .= "<strong>Form Input Errors:".
                    "</strong>\n\n";
        
         if(!$_POST['venu_name']){
            $errors .= "Missing Venu Name\n";
         }
        
         if(!$_POST['address']){
            $errors .= "Missing Address\n";
         }
       
         if(!$_POST['city']){
            $errors .= "Missing City Name\n";
            $email_error = true;
         }
        
         if(!$_POST['postcode']){
            $errors .= "Missing Post Code".
                       "Verification\n";
            $email_error = true;
         }
        
         if(!$_POST['telephone']){
            $errors .= "Missing Telephone Number\n";
         }
        
         if(!$_POST['fax']){
            $errors .= "Missing Fax Number\n";
            $password_error = true;
         }
        
         if(!$_POST['email']){
            $errors .= "Missing Email\n";
            $password_error = true;
         }
        
         if(!$_POST['contactname']){
            $errors .= "Missing Contact Name\n";
         }
   }
  
   // If both emails were posted, validate they match.
   if($email_error == false){
         if($_POST['email_address'] !=
                  $_POST['email_address2']){
            $error = true;
            $errors .= "Email addresses do not match!\n\n";
            $email_error = true;
         }
   }
  
  /*
   // If both passwords were posted, validate they match.
   if($password_error == false){
         if($_POST['password'] != $_POST['password2']){
            $error = true;
            $errors .= "Passwords do not match!\n\n";
            $password_error = true;
         }
   }
   
   if($email_error == false){
      // Verify if email address has been used already.
      $ecount = mysql_result(mysql_query("SELECT COUNT(*)
                     AS ecount FROM members
                     WHERE email_address =
                     '{$_POST['email_address']}'"),0);
    
      // If email exists, generate error and message.  
      if($ecount > 0){
         $error = true;
         $errors .= "This email address has already ".
                    "been used ".
                    "please choose another.\n\n";
      }
   }

   // Verify if username already exists.
   $ucount = mysql_result(mysql_query("SELECT COUNT(*)
                  AS ucount FROM members
                  WHERE username =
                  '{$_POST['username']}'"),0);

   // If username exists, generate error and message.  
   if($ucount > 0){
      $error = true;
      $errors .= "Username already exists, ".
                 "please choose another.\n\n";
   }
  
   // If $error is TRUE, then include the signup form
   // and display the errors we found.
  */
  
   if($error == true){
      $errors = nl2br($errors);
      include $_SERVER['DOCUMENT_ROOT'].
              '/sign_up.html';
      footer();
      exit();
   }
  
   
   $user="root";
$host="localhost";
$password="";
$database="venudatabase";
   
   $cxn = mysqli_connect($host,$user,$password,$database)
       or die ("couldn't connect to the database");

   // All checks have passed, insert user in database
   $sql = "UPDATE venue SET name='$_POST['venu_name']',
   							address1='$_POST['address']',
						city='$_POST['city'],
						postcode='$_POST['postcode']',
						telephone='$_POST['telephone']',
						fax='$_POST['fax']',
						email='$_POST['email']',
						contactname='$_POST['contactname']'
						WHERE venueid='$_POST['$result3']'";

$result = mysqli_query($cxn,$sql) or die ("NO");


if($result == true) {
myheader("Thanks");
include $_SERVER['DOCUMENT_ROOT'].
              '/thanks.html';
footer();
}



   // All checks have passed, insert user in database
  
   // Email user
  
   // Email Admin
  
   // That's it! Done!
break;   

      default:
  $myheader("Welcome");
      include $_SERVER['DOCUMENT_ROOT'].
              '/sign_up.html';
  $footer();
   break;
}
?>

 

Help....

Link to comment
https://forums.phpfreaks.com/topic/75955-sql-unexpected-error/#findComment-384463
Share on other sites

Change

<?php
   // All checks have passed, insert user in database
   $sql = "UPDATE venue SET name='$_POST['venu_name']',
   							address1='$_POST['address']',
						city='$_POST['city'],
						postcode='$_POST['postcode']',
						telephone='$_POST['telephone']',
						fax='$_POST['fax']',
						email='$_POST['email']',
						contactname='$_POST['contactname']'
						WHERE venueid='$_POST['$result3']'";
?>

To

<?php  // All checks have passed, insert user in database
   $sql = "
   							UPDATE venue 
   							SET name='".$_POST['venu_name']."',
   							address1='".$_POST['address']."',
						city='".$_POST['city']."',
						postcode='".$_POST['postcode']."',
						telephone='".$_POST['telephone']."',
						fax='".$_POST['fax']."',
						email='".$_POST['email']."',
						contactname='".$_POST['contactname']."'
						WHERE venueid='".$_POST['$result3']."'";
?>

Link to comment
https://forums.phpfreaks.com/topic/75955-sql-unexpected-error/#findComment-384469
Share on other sites

Change

<?php
   // All checks have passed, insert user in database
   $sql = "UPDATE venue SET name='$_POST['venu_name']',
   							address1='$_POST['address']',
						city='$_POST['city'],
						postcode='$_POST['postcode']',
						telephone='$_POST['telephone']',
						fax='$_POST['fax']',
						email='$_POST['email']',
						contactname='$_POST['contactname']'
						WHERE venueid='$_POST['$result3']'";
?>

To

<?php  // All checks have passed, insert user in database
   $sql = "
   							UPDATE venue 
   							SET name='".$_POST['venu_name']."',
   							address1='".$_POST['address']."',
						city='".$_POST['city']."',
						postcode='".$_POST['postcode']."',
						telephone='".$_POST['telephone']."',
						fax='".$_POST['fax']."',
						email='".$_POST['email']."',
						contactname='".$_POST['contactname']."'
						WHERE venueid='".$_POST['$result3']."'";
?>

 

Perfect!!!

Thanks m8 working now, I missed out a ".....

Thanks

Link to comment
https://forums.phpfreaks.com/topic/75955-sql-unexpected-error/#findComment-384473
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.