Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP error on page submit
#1
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 "";
}

?>
Reply
#2
The error is on line 2?? So remove the comment??
Reply
#3
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?)
Reply
#4
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; )
Reply
#5
(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.
Reply
#6
(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
Reply
#7
It must have solved by now ? So pls close.
Reply
#8
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 943 07-27-2020, 11:26 PM
Last Post: tk-hassan
  [PHP] Very Basic Login Page BreShiE 17 7,946 07-11-2013, 05:57 AM
Last Post: 1n9i9c7om ツ
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,671 10-10-2011, 01:00 PM
Last Post: Greyersting
  [TUT] PHP Password Protected Page PurpleHaze 23 6,995 05-20-2011, 02:56 AM
Last Post: stephen5565
  PHP DISABLE HTML ON MEMBERS PAGE Leprechaun Coder 8 2,481 05-14-2011, 09:44 PM
Last Post: Leprechaun Coder

Forum Jump:


Users browsing this thread: 3 Guest(s)