0

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 ') VALUES('corey','gibson','Cambodia','ab','bragg creek','t0l0k0','corey_g' at line 1

$sql = mysql_query("INSERT INTO myMembers (firstname, lastname, country, province, city, postal_code, email, acp_reg, rank_medical, rank_fire, nok_firstname, nok_lastname, nok_country, nok_province, nok_city, nok_postal_code, nok_phone, password, sign_up_date,)
VALUES('$firstname','$lastname','$country','$province','$city','$postal_code','$email1','$acp_reg','$rank_medical','$rank_fire','$nok_firstname','$nok_lastname','$nok_country','$nok_province','$nok_city','$nok_postal_code','$nok_phone','$db_password', now()")
or die (mysql_error());

$id = mysql_insert_id();

Does anyone have any idea what I am doing wrong?
I am new to php, so my debug skills are rather limited.
Thanks

4
Contributors
19
Replies
20
Views
7 Years
Discussion Span
Last Post by phpbeginners
0

you have an extra comma for one

$sql = mysql_query("INSERT INTO myMembers (firstname, lastname, country, province, city, postal_code, email, acp_reg, rank_medical, rank_fire, nok_firstname, nok_lastname, nok_country, nok_province, nok_city, nok_postal_code, nok_phone, password, sign_up_date)
VALUES('$firstname','$lastname','$country','$province','$city','$postal_code','$email1','$acp_reg','$rank_medical','$rank_fire','$nok_firstname','$nok_lastname','$nok_country','$nok_province','$nok_city','$nok_postal_code','$nok_phone','$db_password', now()")
or die (mysql_error());

$id = mysql_insert_id();
0

So i fixed the comma after sign up date, and now 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

0

Still the same error

$firstname = mysql_real_escape_string($firstname);
     $lastname = mysql_real_escape_string($lastname);
     $country = mysql_real_escape_string($country);
     $province = mysql_real_escape_string($province);
     $city = mysql_real_escape_string($city);
     $postal_code = mysql_real_escape_string($postal_code);
     $email1 = mysql_real_escape_string($email1);
     $acp_reg = mysql_real_escape_string($acp_reg);
     $rank_medical = mysql_real_escape_string($rank_medical);
	 $rank_fire = mysql_real_escape_string($rank_fire);
     $nok_firstname = mysql_real_escape_string($nok_firstname);
     $nok_lastname = mysql_real_escape_string($nok_lastname);
     $nok_country = mysql_real_escape_string($nok_country);
     $nok_province = mysql_real_escape_string($nok_province);
     $nok_city = mysql_real_escape_string($nok_city);
     $nok_postal_code = mysql_real_escape_string($nok_postal_code);
	 $nok_phone = mysql_real_escape_string($nok_phone);
     $pass1 = mysql_real_escape_string($pass1);
	 
  	 $firstname = eregi_replace("`", "", $firstname);
     $lastname = eregi_replace("`", "", $lastname);
     $country = eregi_replace("`", "", $country);
     $province = eregi_replace("`", "", $province);
     $city = eregi_replace("`", "", $city);
     $postal_code = eregi_replace("`", "", $postal_code);
     $email1 = eregi_replace("`", "", $email1);
     $acp_reg = eregi_replace("`", "", $acp_reg);
     $rank_medical = eregi_replace("`", "", $rank_medical);
	 $rank_fire = eregi_replace("`", "", $rank_fire);
     $nok_firstname = eregi_replace("`", "", $nok_firstname);
     $nok_lastname = eregi_replace("`", "", $nok_lastname);
     $nok_country = eregi_replace("`", "", $nok_country);
     $nok_province = eregi_replace("`", "", $nok_province);
     $nok_city = eregi_replace("`", "", $nok_city);
     $nok_postal_code = eregi_replace("`", "", $nok_postal_code);
	 $nok_phone = eregi_replace("`", "", $nok_phone);
     $pass1 = eregi_replace("`", "", $pass1);
	 
	 
     // Add MD5 Hash to the password variable
     $db_password = md5($pass1); 

     // Add user info into the database table for the main site table
     $sql = mysql_query
	 
	 ("INSERT INTO myMembers (firstname, lastname, country, province, city, postal_code, email, acp_reg, rank_medical, rank_fire, nok_firstname, nok_lastname, nok_country, nok_province, nok_city, nok_postal_code, nok_phone, password, sign_up_date)
							  
		VALUES('$firstname', '$lastname', '$country', '$province', '$city', '$postal_code', '$email1', '$acp_reg', '$rank_medical', '$rank_fire', '$nok_firstname', '$nok_lastname', '$nok_country', '$nok_province', '$nok_city', '$nok_postal_code', '$nok_phone', '$db_password', now()")  
	 
     or die (mysql_error());
 
     $id = mysql_insert_id();
0

make this change and tell me what it echos for the SQL

It's a good habbit to get in to to put your sql in a string. that way you can echo it out, debug it, or copy/paste into a mysql client

$sqlstr ="INSERT INTO myMembers (firstname, lastname, country, province, city, postal_code, email, acp_reg, rank_medical, rank_fire, nok_firstname, nok_lastname, nok_country, nok_province, nok_city, nok_postal_code, nok_phone, password, sign_up_date) VALUES ('$firstname', '$lastname', '$country', '$province', '$city', '$postal_code', '$email1', '$acp_reg', '$rank_medical', '$rank_fire', '$nok_firstname', '$nok_lastname', '$nok_country', '$nok_province', '$nok_city', '$nok_postal_code', '$nok_phone', '$db_password', now()";
echo $sql;
$sql = mysql_query($sqlstr);
0

ok so im getting an

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\RMES Website\php\register.php on line 273

which I can only assume because I have no mail settings set up becuase this is an intranet site.

As well I am no longer getting an error message for the insert to sql; however, nothing gets entered into my database.

<?php
// Created BY Adam Khoury @ www.developphp.com

// let's initialize vars to be printed to page in the HTML section so our script does not return errors 
// they must be initialized in some server environments
$errorMsg = "";
$firstname = "";
$lastname = "";
$country = "";
$province = "";
$city = "";
$postal_code = "";
$email1 = "";
$email2 = "";
$acp_reg = "";
$rank_medical = "";
$rank_fire = "";
$nok_firstname = "";
$nok_lastname = "";
$nok_country = "";
$nok_province = "";
$nok_city = "";
$nok_postal_code = "";
$nok_phone = "";
$pass1 = "";
$pass2 = "";

// This code runs only if the form submit button is pressed
if (isset ($_POST['firstname'])){
	
	/* Example of cleaning variables in a loop
	$vars = "";
	foreach ($_POST as $key => $value) {
       $value = stripslashes($value);
       $vars .= "$key = $value<br />";
    }
    print "$vars";
    exit();
	*/
     $firstname = $_POST['firstname'];
     $lastname = $_POST['lastname'];
     $country = $_POST['country'];
     $province = $_POST['province'];
     $city = $_POST['city'];
     $postal_code = $_POST['postal_code'];
     $email1 = $_POST['email1'];
     $email2 = $_POST['email2'];
	 $acp_reg = $_POST['acp_reg'];
     $rank_medical = $_POST['rank_medical'];
	 $rank_fire = $_POST['rank_fire'];
     $nok_firstname = $_POST['nok_firstname'];
     $nok_lastname = $_POST['nok_lastname'];
     $nok_country = $_POST['nok_country'];
     $nok_province = $_POST['nok_province'];
     $nok_city = $_POST['nok_city'];
     $nok_postal_code = $_POST['nok_postal_code'];
	 $nok_phone= $_POST['nok_phone'];
     $pass1 = $_POST['pass1'];
     $pass2 = $_POST['pass2'];
     $humancheck = $_POST['humancheck'];


     $firstname = stripslashes($firstname);
     $lastname = stripslashes($lastname);
     $country = stripslashes($country);
     $province = stripslashes($province);
     $city = stripslashes($city);
     $postal_code = stripslashes($postal_code);
     $email1 = stripslashes($email1);
     $email2 = stripslashes($email2);
	 $acp_reg = stripslashes($acp_reg);
     $rank_medical = stripslashes($rank_medical);
	 $rank_fire = stripslashes($rank_fire);
     $nok_firstname = stripslashes($nok_firstname);
     $nok_lastname = stripslashes($nok_lastname);
     $nok_country = stripslashes($nok_country);
     $nok_province = stripslashes($nok_province);
     $nok_city = stripslashes($nok_city);
     $nok_postal_code = stripslashes($nok_postal_code);
	 $nok_phone = stripslashes($nok_phone);
     $pass1 = stripslashes($pass1);
     $pass1 = stripslashes($pass1);
	 
	 $firstname = strip_tags($firstname);
     $lastname = strip_tags($lastname);
     $country = strip_tags($country);
     $province = strip_tags($province);
     $city = strip_tags($city);
     $postal_code = strip_tags($postal_code);
     $email1 = strip_tags($email1);
     $email2 = strip_tags($email2);
	 $acp_reg = strip_tags($acp_reg);
     $rank_medical = strip_tags($rank_medical);
	 $rank_fire = strip_tags($rank_fire);
     $nok_firstname = strip_tags($nok_firstname);
     $nok_lastname = strip_tags($nok_lastname);
     $nok_country = strip_tags($nok_country);
     $nok_province = strip_tags($nok_province);
     $nok_city = strip_tags($nok_city);
     $nok_postal_code = strip_tags($nok_postal_code);
	 $nok_phone = strip_tags($nok_phone);
     $pass1 = strip_tags($pass1);
     $pass1 = strip_tags($pass1);
	 
     // Connect to database
     include_once "scripts/connect_to_mysql.php";
     $emailCHecker = mysql_real_escape_string($email1);
	 $emailCHecker = eregi_replace("`", "", $emailCHecker);
     // Database duplicate e-mail check setup for use below in the error handling if else conditionals
     $sql_email_check = mysql_query("SELECT email FROM myMembers WHERE email='$emailCHecker'");
     $email_check = mysql_num_rows($sql_email_check); 

     // Error handling for missing data
     if ((!$firstname) || (!$lastname) || (!$country) || (!$province) || (!$city) || (!$postal_code) || (!$email1) || (!$email2) || (!$acp_reg) || (!$rank_medical) || (!$rank_fire) ||  (!$nok_firstname) || (!$nok_lastname) || (!$nok_country) || (!$nok_province) || (!$nok_city) || (!$nok_postal_code) ||  (!$nok_phone) || (!$pass1) || (!$pass2)) { 

     $errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';
  
     if(!$firstname){ 
       $errorMsg .= ' * First Name<br />';
     } 
	 if(!$lastname){ 
       $errorMsg .= ' * Last Name<br />';
     } 
     if(!$country){ 
       $errorMsg .= ' * Country<br />';
     } 	
	 if(!$province){ 
       $errorMsg .= ' * Provice<br />';      
     }
	 if(!$city){ 
       $errorMsg .= ' * City<br />';        
     } 
	 if(!$postal_code){ 
       $errorMsg .= ' * Postal Code<br />';        
     } 		
	 if(!$email1){ 
       $errorMsg .= ' * Email Address<br />';      
     }
	 if(!$email2){ 
       $errorMsg .= ' * Confirm Email Address<br />';        
     } 	
	 if(!$acp_reg){ 
       $errorMsg .= ' * ACP Registration<br />';        
     } 		
	 if(!$rank_medical){ 
       $errorMsg .= ' * Medical Rank<br />';      
     }
	 if(!$rank_fire){ 
       $errorMsg .= ' * Fire Rank<br />';        
     }
	 if(!$nok_firstname){ 
       $errorMsg .= ' * NOK First Name<br />';
     } 
	 if(!$nok_lastname){ 
       $errorMsg .= ' * NOK Last Name<br />';
     } 
     if(!$nok_country){ 
       $errorMsg .= ' * NOK Country<br />';
     } 	
	 if(!$nok_province){ 
       $errorMsg .= ' * NOK Provice<br />';      
     }
	 if(!$nok_city){ 
       $errorMsg .= ' * NOK City<br />';        
     } 
	 if(!$nok_postal_code){ 
       $errorMsg .= ' * NOK Postal Code<br />';        
     }
	 if(!$nok_phone){ 
       $errorMsg .= ' * NOK Phone<br />';        
     }
	 if(!$pass1){ 
       $errorMsg .= ' * Login Password<br />';      
     }
	 if(!$pass2){ 
       $errorMsg .= ' * Confirm Login Password<br />';        
     } 	
	
     } else if ($email1 != $email2) {
              $errorMsg = 'ERROR: Your Email fields below do not match<br />';
     } else if ($pass1 != $pass2) {
              $errorMsg = 'ERROR: Your Password fields below do not match<br />';
     } else if ($humancheck != "") {
              $errorMsg = 'ERROR: The Human Check field must be cleared to be sure you are human<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 { // Error handling is ended, process the data and add member to database
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	 $firstname = mysql_real_escape_string($firstname);
     $lastname = mysql_real_escape_string($lastname);
     $country = mysql_real_escape_string($country);
     $province = mysql_real_escape_string($province);
     $city = mysql_real_escape_string($city);
     $postal_code = mysql_real_escape_string($postal_code);
     $email1 = mysql_real_escape_string($email1);
     $acp_reg = mysql_real_escape_string($acp_reg);
     $rank_medical = mysql_real_escape_string($rank_medical);
	 $rank_fire = mysql_real_escape_string($rank_fire);
     $nok_firstname = mysql_real_escape_string($nok_firstname);
     $nok_lastname = mysql_real_escape_string($nok_lastname);
     $nok_country = mysql_real_escape_string($nok_country);
     $nok_province = mysql_real_escape_string($nok_province);
     $nok_city = mysql_real_escape_string($nok_city);
     $nok_postal_code = mysql_real_escape_string($nok_postal_code);
	 $nok_phone = mysql_real_escape_string($nok_phone);
     $pass1 = mysql_real_escape_string($pass1);
	 
  	 $firstname = eregi_replace("`", "", $firstname);
     $lastname = eregi_replace("`", "", $lastname);
     $country = eregi_replace("`", "", $country);
     $province = eregi_replace("`", "", $province);
     $city = eregi_replace("`", "", $city);
     $postal_code = eregi_replace("`", "", $postal_code);
     $email1 = eregi_replace("`", "", $email1);
     $acp_reg = eregi_replace("`", "", $acp_reg);
     $rank_medical = eregi_replace("`", "", $rank_medical);
	 $rank_fire = eregi_replace("`", "", $rank_fire);
     $nok_firstname = eregi_replace("`", "", $nok_firstname);
     $nok_lastname = eregi_replace("`", "", $nok_lastname);
     $nok_country = eregi_replace("`", "", $nok_country);
     $nok_province = eregi_replace("`", "", $nok_province);
     $nok_city = eregi_replace("`", "", $nok_city);
     $nok_postal_code = eregi_replace("`", "", $nok_postal_code);
	 $nok_phone = eregi_replace("`", "", $nok_phone);
     $pass1 = eregi_replace("`", "", $pass1);
	 
	 
     // Add MD5 Hash to the password variable
     $db_password = md5($pass1); 

     // Add user info into the database table for the main site table
    $sqlstr ="INSERT INTO myMembers (firstname, lastname, country, province, city, postal_code, email, acp_reg, rank_medical, rank_fire, nok_firstname, 	  nok_lastname, nok_country, nok_province, nok_city, nok_postal_code, nok_phone, password, sign_up_date) 
	VALUES ('$firstname', '$lastname', '$country', '$province', '$city', '$postal_code', '$email1', '$acp_reg', '$rank_medical', '$rank_fire', '$nok_firstname', '$nok_lastname', '$nok_country', '$nok_province', '$nok_city', '$nok_postal_code', '$nok_phone', '$db_password', now()";
echo $sql;

$sql = mysql_query($sqlstr); 
	 
   
 
     $id = mysql_insert_id();
	 
	 // Create directory(folder) to hold each user's files(pics, MP3s, etc.)		
     mkdir("http://localhost/RMES%20Website/php/members/$id", 0755);	

    //!!!!!!!!!!!!!!!!!!!!!!!!!    Email User the activation link    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    $to = "$email1";
										 
    $from = "admin@localhost";
    $subject = "Complete yourdomain registration";
    //Begin HTML Email Message
    $message = "Hi $firstname,

   Complete this step to activate your login identity at yourdomain.

   Click the line below to activate when ready.

  http://localhost/activation.php?id=$id&sequence=$db_password
   If the URL above is not an active link, please copy and paste it into your browser address bar

   Login after successful activation using your:  
   E-mail Address: $email1 
   Password: $pass1

   See you on the site!
   you@yourdomain.com";
   //end of message
	$headers  = "From: $from\r\n";
    $headers .= "Content-type: text\r\n";

    mail($to, $subject, $message, $headers);
	
   $msgToUser = "<h2>One Last Step - Activate through Email</h2><h4>OK $firstname, one last step to verify your email identity:</h4><br />
   In a moment you will be sent an Activation link to your email address.<br /><br />
   <br />
   <strong><font color=\"#990000\">VERY IMPORTANT:</font></strong> 
   If you check your email with your host providers default email application, there may be issues with seeing the email contents.  If this happens to you and you cannot read the message to activate, download the file and open using a text editor. If you still cannot see the activation link, contact site admin and briefly discuss the issue.<br /><br />
   ";


   include_once 'msgToUser.php'; 

   exit();

   } // Close else after duplication checks

} else { // if the form is not posted with variables, place default empty variables
	  
	  $errorMsg = "Fields marked with an [ * ] are required";
      $firstname = "";
$lastname = "";
$country = "";
$province = "";
$city = "";
$postal_code = "";
$email1 = "";
$email2 = "";
$acp_reg = "";
$rank_medical = "";
$rank_fire = "";
$nok_firstname = "";
$nok_lastname = "";
$nok_country = "";
$nok_province = "";
$nok_city = "";
$nok_postal_code = "";
$nok_phone = "";
$pass1 = "";
$pass2 = "";
}

?>
0

So I solved the mail problem, however I still can't get it to insert my values into the database

0

The problem with communicating the error to the caller remains, ... Also, the most likely errors from a batch of dynamic SQL are probably syntax errors. ... you have to somehow handle T-SQL errors in your client code too.....


Thanks and mybe it can helps

0

How do I know where to start looking if it isn't giving me anymore actual errors.
It's just not inserting the values into the DB

The problem with communicating the error to the caller remains, ... Also, the most likely errors from a batch of dynamic SQL are probably syntax errors. ... you have to somehow handle T-SQL errors in your client code too.....


Thanks and mybe it can helps

0

you start by dumbing it down. Make a small sql insert statement and run it manually. or run the whole thing in a mysql client or phpmyadmin and it shoudl tell you which line. or post here what that echo $sql; line spits out.

Edited by kireol: n/a

0

So i can insert data into my db via phpmyadmin, but even a simple sql insert statment wont insert any data into the table.
in phpmyadmin all I see is

Showing rows 0 - 0 (1 total, Query took 0.0003 sec)

0

ok so this is my current php code, minus the inputs.

I can get a small test script to write to the datebase, however I still can't get this code to write.


It is still not throwing any errors, it's just not working.

This is my test script

<?php 
$dbhost = 'localhost'; 
$dbuser = '*****'; 
$dbpass = '******'; 

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql'); 

$dbname = '****'; 
mysql_select_db($dbname); 

$sql = "INSERT INTO mymembers (firstname, email) VALUES ('$name', '$email1')"; 

mysql_query($sql); 

$id = mysql_insert_id();

?>
<?php
// Created BY Adam Khoury @ www.developphp.com
// connect to your MySQL database here using the 
// script we made in the previous step of this lesson

// let's initialize vars to be printed to page in the HTML section so our script does not return errors 
// they must be initialized in some server environments
$errorMsg = "";
$firstname = "";
$lastname = "";
$country = "";
$province = "";
$city = "";
$postal_code = "";
$email1 = "";
$email2 = "";
$acp_reg = "";
$rank_medical = "";
$rank_fire = "";
$nok_firstname = "";
$nok_lastname = "";
$nok_country = "";
$nok_province = "";
$nok_city = "";
$nok_postal_code = "";
$nok_phone = "";
$pass1 = "";
$pass2 = "";

// This code runs only if the form submit button is pressed
if (isset ($_POST['firstname'])){
	
	/* Example of cleaning variables in a loop
	$vars = "";
	foreach ($_POST as $key => $value) {
       $value = stripslashes($value);
       $vars .= "$key = $value<br />";
    }
    print "$vars";
    exit();
	*/
     $firstname = $_POST['firstname'];
     $lastname = $_POST['lastname'];
     $country = $_POST['country'];
     $province = $_POST['province'];
     $city = $_POST['city'];
     $postal_code = $_POST['postal_code'];
     $email1 = $_POST['email1'];
     $email2 = $_POST['email2'];
	 $acp_reg = $_POST['acp_reg'];
     $rank_medical = $_POST['rank_medical'];
	 $rank_fire = $_POST['rank_fire'];
     $nok_firstname = $_POST['nok_firstname'];
     $nok_lastname = $_POST['nok_lastname'];
     $nok_country = $_POST['nok_country'];
     $nok_province = $_POST['nok_province'];
     $nok_city = $_POST['nok_city'];
     $nok_postal_code = $_POST['nok_postal_code'];
	 $nok_phone= $_POST['nok_phone'];
     $pass1 = $_POST['pass1'];
     $pass2 = $_POST['pass2'];
     $humancheck = $_POST['humancheck'];


     $firstname = stripslashes($firstname);
     $lastname = stripslashes($lastname);
     $country = stripslashes($country);
     $province = stripslashes($province);
     $city = stripslashes($city);
     $postal_code = stripslashes($postal_code);
     $email1 = stripslashes($email1);
     $email2 = stripslashes($email2);
	 $acp_reg = stripslashes($acp_reg);
     $rank_medical = stripslashes($rank_medical);
	 $rank_fire = stripslashes($rank_fire);
     $nok_firstname = stripslashes($nok_firstname);
     $nok_lastname = stripslashes($nok_lastname);
     $nok_country = stripslashes($nok_country);
     $nok_province = stripslashes($nok_province);
     $nok_city = stripslashes($nok_city);
     $nok_postal_code = stripslashes($nok_postal_code);
	 $nok_phone = stripslashes($nok_phone);
     $pass1 = stripslashes($pass1);
     $pass1 = stripslashes($pass1);
	 
	 $firstname = strip_tags($firstname);
     $lastname = strip_tags($lastname);
     $country = strip_tags($country);
     $province = strip_tags($province);
     $city = strip_tags($city);
     $postal_code = strip_tags($postal_code);
     $email1 = strip_tags($email1);
     $email2 = strip_tags($email2);
	 $acp_reg = strip_tags($acp_reg);
     $rank_medical = strip_tags($rank_medical);
	 $rank_fire = strip_tags($rank_fire);
     $nok_firstname = strip_tags($nok_firstname);
     $nok_lastname = strip_tags($nok_lastname);
     $nok_country = strip_tags($nok_country);
     $nok_province = strip_tags($nok_province);
     $nok_city = strip_tags($nok_city);
     $nok_postal_code = strip_tags($nok_postal_code);
	 $nok_phone = strip_tags($nok_phone);
     $pass1 = strip_tags($pass1);
     $pass1 = strip_tags($pass1);
	 
     // Connect to database
     include_once "scripts/connect_to_mysql.php";
     $emailCHecker = mysql_real_escape_string($email1);
	 $emailCHecker = eregi_replace("`", "", $emailCHecker);
     // Database duplicate e-mail check setup for use below in the error handling if else conditionals
     $sql_email_check = mysql_query("SELECT email FROM myMembers WHERE email='$emailCHecker'");
     $email_check = mysql_num_rows($sql_email_check); 

     // Error handling for missing data
     if ((!$firstname) || (!$lastname) || (!$country) || (!$province) || (!$city) || (!$postal_code) || (!$email1) || (!$email2) || (!$rank_fire) ||  (!$pass1) || (!$pass2)) { 

     $errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';
  
     if(!$firstname){ 
       $errorMsg .= ' * First Name<br />';
     } 
	 if(!$lastname){ 
       $errorMsg .= ' * Last Name<br />';
     } 
     if(!$country){ 
       $errorMsg .= ' * Country<br />';
     } 	
	 if(!$province){ 
       $errorMsg .= ' * Provice<br />';      
     }
	 if(!$city){ 
       $errorMsg .= ' * City<br />';        
     } 
	 if(!$postal_code){ 
       $errorMsg .= ' * Postal Code<br />';        
     } 		
	 if(!$email1){ 
       $errorMsg .= ' * Email Address<br />';      
     }
	 if(!$email2){ 
       $errorMsg .= ' * Confirm Email Address<br />';
	 }
	 if(!$rank_fire){ 
       $errorMsg .= ' * Fire Rank<br />';        
     }
	 if(!$pass1){ 
       $errorMsg .= ' * Login Password<br />';      
     }
	 if(!$pass2){ 
       $errorMsg .= ' * Confirm Login Password<br />';        
     } 	
	
     } else if ($email1 != $email2) {
              $errorMsg = 'ERROR: Your Email fields below do not match<br />';
     } else if ($pass1 != $pass2) {
              $errorMsg = 'ERROR: Your Password fields below do not match<br />';
     } else if ($humancheck != "") {
              $errorMsg = 'ERROR: The Human Check field must be cleared to be sure you are human<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 { // Error handling is ended, process the data and add member to database
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	 $firstname = mysql_real_escape_string($firstname);
     $lastname = mysql_real_escape_string($lastname);
     $country = mysql_real_escape_string($country);
     $province = mysql_real_escape_string($province);
     $city = mysql_real_escape_string($city);
     $postal_code = mysql_real_escape_string($postal_code);
     $email1 = mysql_real_escape_string($email1);
     $acp_reg = mysql_real_escape_string($acp_reg);
     $rank_medical = mysql_real_escape_string($rank_medical);
	 $rank_fire = mysql_real_escape_string($rank_fire);
     $nok_firstname = mysql_real_escape_string($nok_firstname);
     $nok_lastname = mysql_real_escape_string($nok_lastname);
     $nok_country = mysql_real_escape_string($nok_country);
     $nok_province = mysql_real_escape_string($nok_province);
     $nok_city = mysql_real_escape_string($nok_city);
     $nok_postal_code = mysql_real_escape_string($nok_postal_code);
	 $nok_phone = mysql_real_escape_string($nok_phone);
     $pass1 = mysql_real_escape_string($pass1);
	 
  	 $firstname = eregi_replace("`", "", $firstname);
     $lastname = eregi_replace("`", "", $lastname);
     $country = eregi_replace("`", "", $country);
     $province = eregi_replace("`", "", $province);
     $city = eregi_replace("`", "", $city);
     $postal_code = eregi_replace("`", "", $postal_code);
     $email1 = eregi_replace("`", "", $email1);
     $acp_reg = eregi_replace("`", "", $acp_reg);
     $rank_medical = eregi_replace("`", "", $rank_medical);
	 $rank_fire = eregi_replace("`", "", $rank_fire);
     $nok_firstname = eregi_replace("`", "", $nok_firstname);
     $nok_lastname = eregi_replace("`", "", $nok_lastname);
     $nok_country = eregi_replace("`", "", $nok_country);
     $nok_province = eregi_replace("`", "", $nok_province);
     $nok_city = eregi_replace("`", "", $nok_city);
     $nok_postal_code = eregi_replace("`", "", $nok_postal_code);
	 $nok_phone = eregi_replace("`", "", $nok_phone);
     $pass1 = eregi_replace("`", "", $pass1);
	 
	 
     // Add MD5 Hash to the password variable
     $db_password = md5($pass1); 

     // Add user info into the database table for the main site table
    
$sql = "INSERT INTO mymembers (firstname, lastname, country, province, city, postal_code, email, acp_reg, rank_medical, rank_fire, nok_firstname, 	  nok_lastname, nok_country, nok_province, nok_city, nok_postal_code, nok_phone, password, sign_up_date) VALUES ('$firstname', '$lastname', '$country', '$province', '$city', '$postal_code', '$email1', '$acp_reg', '$rank_medical', '$rank_fire', '$nok_firstname', '$nok_lastname', '$nok_country', '$nok_province', '$nok_city', '$nok_postal_code', '$nok_phone', '$db_password', now())"; 

mysql_query($sql); 


     $id = mysql_insert_id();
	 
	 // Create directory(folder) to hold each user's files(pics, MP3s, etc.)		
     mkdir("http://localhost/RMES%20Website/php/members/$id", 0755);	

    //!!!!!!!!!!!!!!!!!!!!!!!!!    Email User the activation link    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    $to = "$email1";
										 
    $from = "admin@localhost";
    $subject = "Complete yourdomain registration";
    //Begin HTML Email Message
    $message = "Hi $firstname,

   Complete this step to activate your login identity at yourdomain.

   Click the line below to activate when ready.

  http://localhost/activation.php?id=$id&sequence=$db_password
   If the URL above is not an active link, please copy and paste it into your browser address bar

   Login after successful activation using your:  
   E-mail Address: $email1 
   Password: $pass1

   See you on the site!
   you@yourdomain.com";
   //end of message
	$headers  = "From: $from\r\n";
    $headers .= "Content-type: text\r\n";

    mail($to, $subject, $message, $headers);
	
   $msgToUser = "<h2>One Last Step - Activate through Email</h2><h4>OK $firstname, one last step to verify your email identity:</h4><br />
   In a moment you will be sent an Activation link to your email address.<br /><br />
   <br />
   <strong><font color=\"#990000\">VERY IMPORTANT:</font></strong> 
   If you check your email with your host providers default email application, there may be issues with seeing the email contents.  If this happens to you and you cannot read the message to activate, download the file and open using a text editor. If you still cannot see the activation link, contact site admin and briefly discuss the issue.<br /><br />
   ";


   include_once 'msgToUser.php'; 

   exit();

   } // Close else after duplication checks

} else { // if the form is not posted with variables, place default empty variables
	  
	  $errorMsg = "Fields marked with an [ * ] are required";
      $firstname = "";
$lastname = "";
$country = "";
$province = "";
$city = "";
$postal_code = "";
$email1 = "";
$email2 = "";
$acp_reg = "";
$rank_medical = "";
$rank_fire = "";
$nok_firstname = "";
$nok_lastname = "";
$nok_country = "";
$nok_province = "";
$nok_city = "";
$nok_postal_code = "";
$nok_phone = "";
$pass1 = "";
$pass2 = "";
}

?>
0

This is the code that made the table structure

<?php
/* 
Created By Adam Khoury @ www.delopphp.com
-----------------------March 2009-----------------------
*/
// connect to your MySQL database here using the 
// script we made in the previous step of this lesson
require_once "connect_to_mysql.php";
// Tell ourselves on screen if we have connected
print "Success in database CONNECTION.....<br />";
// Create the members main table in your new database
$result = "CREATE TABLE myMembers (
id int(11) NOT NULL auto_increment,
firstname varchar(255) NOT NULL, 
lastname varchar(255) NOT NULL, 
address1 varchar(255) NOT NULL, 
address2 varchar(255) NOT NULL, 
province varchar(255) NOT NULL, 
city varchar(255) NOT NULL, 
postal_code varchar(255) NOT NULL, 
phone varchar(255) NOT NULL, 
acp_reg varchar(255) NOT NULL, 
rank_fire enum('0','1','2','3','4','5','6','7') NOT NULL default '7', 
rank_medical enum('0','1','2','3','4','5','6') NOT NULL default '6', 
nok_firstname varchar(255) NOT NULL, 
nok_lastname varchar(255) NOT NULL, 
nok_address1 varchar(255) NOT NULL, 
nok_address2 varchar(255) NOT NULL, 
nok_province varchar(255) NOT NULL, 
nok_city varchar(255) NOT NULL, 
nok_postal_code varchar(255) NOT NULL, 
nok_phone varchar(255) NOT NULL, 
email varchar(255) NOT NULL, 
password varchar(255) NOT NULL,
sign_up_date date NOT NULL default '0000-00-00',
last_log_date date NOT NULL default '0000-00-00',
bio_body text NULL,
account_type enum('a','b','c') NOT NULL default 'a',
email_activated enum('0','1') NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY email (email)
) ";
if (mysql_query($result)){
print "Success in TABLE creation!......
<br /><br /><b>That completes the table setup, now delete the file <br />
named 'create_Table.php' and you are ready to move on. Let us go!</b>";
} else {
print "no TABLE created. You have problems in the system already, backtrack and debug!";
}
exit();
?>

Edited by dhrider: n/a

0

try this:

$sql = 'INSERT INTO `myMembers` (`firstname`,`lastname`,`address1`,`address2`,`province`,`city`,`postal_code`,`phone`,`acp_reg`,`nok_firstname`,`nok_lastname`,`nok_address1`,`nok_address2`,`nok_province`,`nok_city`,`nok_postal_code`,`nok_phone`,`email`,`password`,`sign_up_date`,`last_log_date`,`bio_body`,`website`,`youtube`,`account_type`,`email_activated`) VALUES (\'a\',\'b\',\'c\',\'d\',\'e\',\'f\',\'g\',\'1\',\'1\',\'a\',\'b\',\'c\',\'d\',\'e\',\'f\',\'g\',\'h\',\'a\',\'a\',\'2009-12-08\',\'2009-12-08\',\'hello\',\'www.google.com\',\'www.youtube.com\',\'b\',\'1\')';

if success you can remove the \' just put ' ' in the value list.


here's the EXPORT in phpmyadmin

INSERT INTO `myMembers` (`firstname`, `lastname`, `address1`, `address2`, `province`, `city`, `postal_code`, `phone`, `acp_reg`, `rank_fire`, `rank_medical`, `nok_firstname`, `nok_lastname`, `nok_address1`, `nok_address2`, `nok_province`, `nok_city`, `nok_postal_code`, `nok_phone`, `email`, `password`, `sign_up_date`, `last_log_date`, `bio_body`, `website`, `youtube`, `account_type`, `email_activated`) VALUES
('a', 'b', 'c', 'd', 'e', 'f', 'g', '1', '1', '7', '6', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'b@hotmail.com', 'a', '2009-12-08', '2009-12-08', 'hello', 'www.google.com', 'www.youtube.com', 'b', '1')

Make Sure there is no Duplicate in your email address because that is a "UNIQUE" key in your table

the above commands work in my phpmyadmin.. you can follow that format..make sure there is no duplicate in email fields

Edited by phpbeginners: n/a

0

It just does the same thing as the previous statements.

Doesn't run an error, just doesn't insert anything to the table.

0

Got this working, thanks guys

$sql = "INSERT INTO myMembers (`firstname`, `lastname`, `address1`, `address2`, `province`, `city`, `postal_code`, `phone`, `acp_reg`, `rank_fire`, `rank_medical`, `nok_firstname`, `nok_lastname`, `nok_address1`, `nok_address2`, `nok_province`, `nok_city`, `nok_postal_code`, `nok_phone`, `email`, `password`, `sign_up_date`, `last_log_date`, `bio_body`, `account_type`, `email_activated`) VALUES ('$firstname', '$lastname', 'c', 'd', '$province', '$city', '$postal_code', '1', '$acp_reg', '$rank_fire', '$rank_medical', '$nok_firstname', '$nok_lastname', 'c', 'd', '$nok_province', '$nok_city', '$nok_postal_code', 'h', '$email1', '$db_password', '2009-12-08', '2009-12-08', 'hello', 'b', '1')";
0

next time also here's the technique in your database $sql =

put die($sql) to see what you are updating on the table the result is this one in your screen.

INSERT INTO myMembers (`firstname`, `lastname`, `address1`, `address2`, `province`, `city`, `postal_code`, `phone`, `acp_reg`, `rank_fire`, `rank_medical`, `nok_firstname`, `nok_lastname`, `nok_address1`, `nok_address2`, `nok_province`, `nok_city`, `nok_postal_code`, `nok_phone`, `email`, `password`, `sign_up_date`, `last_log_date`, `bio_body`, `account_type`, `email_activated`) VALUES ('$firstname', '$lastname', 'c', 'd', '$province', '$city', '$postal_code', '1', '$acp_reg', '$rank_fire', '$rank_medical', '$nok_firstname', '$nok_lastname', 'c', 'd', '$nok_province', '$nok_city', '$nok_postal_code', 'h', '$email1', '$db_password', '2009-12-08', '2009-12-08', 'hello', 'b', '1')

copy that command and run in your SQL in phpmyadmin or NaviCat

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.