Support Forums
PHP error on page submit - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: PHP error on page submit (/showthread.php?tid=22224)



PHP error on page submit - kaosjon - 09-17-2011

Hi, i am trying to create a registration page for my website, however when i test it and click the submit button i get this error,

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2"

I have tried everything to try and fix this but cannot do it.

Anyone have any ideas,

Heres my code

PHP Code:
<?php
// Code only runs if submit button is pressed
if (isset ($_POST['firstname'])){
     
$firstname $_POST['firstname'];
  
$lastname $_POST['lastname'];
     
$username $_POST['username'];
  
$email $_POST['email'];
  
$password $_POST['password'];
  
$cpassword $_POST['cpassword'];
  
$paypal_email $_POST['paypal_email'];
  
$country $_POST['country'];
     
$kingdom_name $_POST['kingdom_name'];
  
$kingdom_motto $_POST['kingdom_motto'];
     
$referal $_POST['referal'];
  
$newsletter $_POST['newsletter'];

  include_once 
"connect_to_mysql.php";
  
$emailCHecker mysql_real_escape_string($email);
     
$emailCHecker eregi_replace("`"""$emailCHecker);
     
$usernameCHecker mysql_real_escape_string($username);
     
$usernameCHecker eregi_replace("`"""$usernameCHecker);
  
// Database duplicate e-mail check setup for use below in the error handling if else conditionals
  
$sql_email_check mysql_query("SELECT email FROM user_info WHERE email='$emailCHecker'");
  
$email_check mysql_num_rows($sql_email_check); 
     
$sql_username_check mysql_query("SELECT username FROM user_info WHERE username='$usernameCHecker'");
  
$username_check mysql_num_rows($sql_username_check); 

  
// Error handling for missing data
  
if ((!$firstname) || (!$lastname) || (!$username) || (!$email) || (!$password) || (!$cpassword) || (!$paypal_email) || (!$kingdom_name) || (!$kingdom_motto)) { 

  
$errorMsg 'ERROR: You did not submit the following required information:<br /><br />';

  if(!
$firstname){ 
  
$errorMsg .= ' * Firstname<br />';
  } 
     if(!
$lastname){ 
  
$errorMsg .= ' * Lastname<br />';
  } 
     if(!
$username){ 
  
$errorMsg .= ' *Username<br />';
  } 
  if(!
$email){ 
  
$errorMsg .= ' * Email<br />';
  }     
     if(!
$password){ 
  
$errorMsg .= ' * Password<br />';  
  }
     if(!
$cpassword){ 
  
$errorMsg .= ' * Confirmation Password<br />';  
  } 
     if(!
$paypal_email){ 
  
$errorMsg .= ' * Paypal Email<br />';  
  } 
     if(!
$kingdom_name){ 
  
$errorMsg .= ' * Kingdom Name<br />';  
  }
     if(!
$kingdom_motto){ 
  
$errorMsg .= ' * Kingdom Password<br />';  
  }            

  } else if (
$password != $cpassword) {
    
$errorMsg 'ERROR: Your Password fields below do not match<br />';         
  } else if (
$email_check 0){ 
    
$errorMsg "<u>ERROR:</u><br />Your Email address is already in use inside our database. Please use another.<br />";
     } else if (
$username_check 0){ 
    
$errorMsg "<u>ERROR:</u><br />Username selected is already in use. Please choose another.<br />"

  } else { 
// Error handling is ended

  // Add MD5 Hash to the password
  
$password md5($password); 

  
// Add user info into the database table
  
$sql mysql_query("INSERT INTO user_info (firstname, lastname, username, email, password, sign_up_date) 
  VALUES('
$firstname','$lastname','$username','$email','$password', now()")  
  or die (
mysql_error());

  
$id mysql_insert_id();

  
mkdir("members/$id"0755);    

   include_once 
'msgToUser.php'

   exit();

   } 
// Close else

} else { // if the form is not posted with variables, place default empty variables so no warnings or errors show

      
$errorMsg "";
      
$firstname "";
  
$lastname "";
      
$username "";
      
$email "";
      
$password "";
      
$cpassword "";
      
$paypal_email "";
      
$kingdom_name "";
      
$kingdom_motto "";
      
$referal "";
}

?>



RE: PHP error on page submit - Fragma - 09-17-2011

The error is on line 2?? So remove the comment??


RE: PHP error on page submit - AceInfinity - 09-17-2011

Code:
to use near '' at line 2

I'm not seeing """ anywhere in line 1, 2, or 3. Are you sure you have saved this version and checked it, or are you viewing the wrong PHP file or? (something else?)


RE: PHP error on page submit - Gaijin - 09-17-2011

You've forgot one ")" after now()...
Code:
mysql_query("INSERT INTO user_info (firstname, lastname, username, email, password, sign_up_date)
  VALUES('$firstname','$lastname','$username','$email','$password', now())")

I think that is the error you're looking for.

(09-17-2011, 05:20 AM)Fragma Wrote: The error is on line 2?? So remove the comment??

It's not the second line of the source,it's the second line of the SQL command... (You have an error in your SQL syntax; )


RE: PHP error on page submit - AceInfinity - 09-17-2011

(09-17-2011, 05:53 PM)Gaijin Wrote: You've forgot one ")" after now()...
Code:
mysql_query("INSERT INTO user_info (firstname, lastname, username, email, password, sign_up_date)
  VALUES('$firstname','$lastname','$username','$email','$password', now())")

I think that is the error you're looking for.

It's not the second line of the source,it's the second line of the SQL command... (You have an error in your SQL syntax; )

That's where the " was... I keep forgetting the code blocks don't display the whole text, you have to use the scroll bar, so sometimes I select their code, and it's only the visible part at the top of the scrolled code box lol. And that's the reason why I wish this forum added a select all function to the php and code boxes like on my forum.


RE: PHP error on page submit - Gaijin - 09-17-2011

(09-17-2011, 06:54 PM)Ace Wrote: That's where the " was... I keep forgetting the code blocks don't display the whole text, you have to use the scroll bar, so sometimes I select their code, and it's only the visible part at the top of the scrolled code box lol. And that's the reason why I wish this forum added a select all function to the php and code boxes like on my forum.

Yea, lol, and not only that, these SQL errors are sometimes real pain.
I myself often mistake them for PHP syntax errors. o.O



RE: PHP error on page submit - +Awesome - 09-18-2011

It must have solved by now ? So pls close.


RE: PHP error on page submit - AceInfinity - 09-18-2011

(09-18-2011, 01:47 AM)Calculus Wrote: It must have solved by now ? So pls close.

I think the original poster should decide if he wants it closed