mikebyrne Posted November 27, 2007 Share Posted November 27, 2007 I've got the following code to send the user a confirmation email upon registration but when the user clisck on the link, instead of getting a messege, I just get a blank screen????? <?php include('config.php'); // Passkey that got from link $passkey=$_GET['passkey']; $tbl_name1="temp_users"; // Retrieve data from table where row matchs this passkey $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'"; $result1=mysql_query($sql1); // If successfully queried if($result1){ // Count how many row has this passkey $count=mysql_num_rows($result1); // if found the passkey in the database, retrieve data from table "temp_users" if($count==1){ $rows=mysql_fetch_array($result1); $name=$_POST['name']; $address=$_POST['address']; $address1=$_POST['address1']; $address2=$_POST['address2']; $address3=$_POST['address3']; $address4=$_POST['address4']; $county=$_POST['county']; $zip=$_POST['zip']; $telephone=$_POST['telephone']; $email=$_POST['email']; $username=$_POST['username']; $password=$_POST['password']; $tbl_name2="users"; // Insert data that retrieves from "temp_users" into table "users" $sql2="INSERT INTO $tbl_name2(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password',)"; $result2=mysql_query($sql2); } // if not found passkey, display message "Wrong Confirmation code" else { echo "Wrong Confirmation code"; } // if successfully moved data from table"temp_users" to table "users" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db" if($result2){ echo "Your account has been activated"; // Delete information of this user from table "temp_users" that has this passkey $sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'"; $result3=mysql_query($sql3); } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 Its pretty hard to tell what your code is doing because of the distinct lack of indentation, but I can tell you now your $sql2 query looks malformed. Try changing it to... $sql2="INSERT INTO $tbl_name2 (name, address, address1, address2, address3, address4, county, zip, telephone, email, username, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password',)"; Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 27, 2007 Author Share Posted November 27, 2007 No, still getting the blank screen Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 27, 2007 Share Posted November 27, 2007 keep this at top and run your code error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 27, 2007 Author Share Posted November 27, 2007 I just had this way working last week but with less fields etc. I'll definatly look at you idea once I get this test up and running I've changed two lines in the config.php to $sql2="INSERT INTO $tbl_name2 (name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password',)"; $result=mysql_query($sql2) or die(mysql_error()); And I'm now getting the 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 1 Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 27, 2007 Share Posted November 27, 2007 If I'm not mistaken, password is a MySQL reserved keyword/function. Always use backticks (`) on table names and field names, single quote (') on values. That way, MySQL will recognize it as a field name, and not a keyword/function. <?php $sql2="INSERT INTO `$tbl_name2` (`name`, `address`, `address1`, `address2`, `address3`, `address4`, `county`, `zip`, `telephone`, `email`, `username`, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password',)"; $result=mysql_query($sql2) or die(mysql_error()); PhREEEk Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 27, 2007 Share Posted November 27, 2007 Yes PhREEEk is right and I see one extra comma after $password remove that and try. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 27, 2007 Share Posted November 27, 2007 n~ link=topic=169393.msg747698#msg747698 date=1196154340] Yes PhREEEk is right and I see one extra comma after $password remove that and try. Good catch... guess you have to scroll ALL the way over sometimes... lol PhREEEk Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 27, 2007 Author Share Posted November 27, 2007 I've fixed it to $sql2="INSERT INTO `$tbl_name2` (`name`, `address`, `address1`, `address2`, `address3`, `address4`, `county`, `zip`, `telephone`, `email`, `username`, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result=mysql_query($sql2) or die(mysql_error()); But getting a blank screen after I click on the email link Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 27, 2007 Share Posted November 27, 2007 Where is the email link, i don't see any email link in your code ??? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 27, 2007 Author Share Posted November 27, 2007 <?php include('config.php'); // table name $tbl_name=temp_users; // Random confirmation code $confirm_code=md5(uniqid(rand())); // values sent from form $name=$_POST['name']; $address=$_POST['address']; $address1=$_POST['address1']; $address2=$_POST['address2']; $address3=$_POST['address3']; $address4=$_POST['address4']; $county=$_POST['county']; $zip=$_POST['zip']; $telephone=$_POST['telephone']; $email=$_POST['email']; $username=$_POST['username']; $password=$_POST['password']; // Insert data into database $sql="INSERT INTO $tbl_name(confirm_code, name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$confirm_code', '$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result=mysql_query($sql)or die(mysql_error()); // if suceesfully inserted data into database, send confirmation link to email if($result){ // ---------------- SEND MAIL FORM ---------------- // send e-mail to ... $to=$email; // Your subject $subject="Your confirmation link here"; // From $header="from: postmaster@localhost <postmaster@localhost>"; // Your message $message="Your Comfirmation link \r\n"; $message.="Click on this link to activate your account \r\n"; $message.="http://localhost/confirm.php?passkey=$confirm_code"; // send email $sentmail = mail($to,$subject,$message,$header); } // if not found else { echo "Not found your email in our database"; } // if your email succesfully sent if($sentmail){ echo "Your Confirmation link Has Been Sent To Your Email Address."; } else { echo "Cannot send Confirmation link to your e-mail address"; } ?> This all seems to work fine its the confirm.php I'm having trouble with Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 27, 2007 Author Share Posted November 27, 2007 Still getting a blank screen when I click on the email link!!!! Cant figure whats wrong, Its driving me mental!!!! Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 27, 2007 Share Posted November 27, 2007 First you keep double quote in this table name $tbl_name="temp_users"; and change your query as PHP_PhREEEk posted above (with all that single quote and backticks) and try running it again. I don't see any other errors in your code... Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 27, 2007 Author Share Posted November 27, 2007 My confirm.php looks like this but I'm still getting the blank screen <?php include('config.php'); // Passkey that got from link $passkey=$_GET['passkey']; $tbl_name="temp_users"; // Retrieve data from table where row matchs this passkey $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'"; $result1=mysql_query($sql1); // If successfully queried if($result1){ // Count how many row has this passkey $count=mysql_num_rows($result1); // if found the passkey in the database, retrieve data from table "temp_users" if($count==1){ $rows=mysql_fetch_array($result1); $name=$_POST['name']; $address=$_POST['address']; $address1=$_POST['address1']; $address2=$_POST['address2']; $address3=$_POST['address3']; $address4=$_POST['address4']; $county=$_POST['county']; $zip=$_POST['zip']; $telephone=$_POST['telephone']; $email=$_POST['email']; $username=$_POST['username']; $password=$_POST['password']; $tbl_name2="users"; // Insert data that retrieves from "temp_users" into table "users" $sql2="INSERT INTO `$tbl_name2` (`name`, `address`, `address1`, `address2`, `address3`, `address4`, `county`, `zip`, `telephone`, `email`, `username`, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result=mysql_query($sql2) or die(mysql_error()); } // if not found passkey, display message "Wrong Confirmation code" else { echo "Wrong Confirmation code"; } // if successfully moved data from table"temp_users" to table "users" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db" if($result2){ echo "Your account has been activated"; // Delete information of this user from table "temp_users" that has this passkey $sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'"; $result3=mysql_query($sql3); } } ?> Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 27, 2007 Share Posted November 27, 2007 Try this some modifications I did, if($count > 0) you had kept ==1, if you are sure query will return only 1 result then keep urs <?php include('config.php'); // Passkey that got from link ## added here if (isset($_GET['passkey'])) { $passkey=$_GET['passkey']; } else { echo "Error here :: PASSKEY NOT FOUND "; } ## table name $tbl_name="temp_users"; // Retrieve data from table where row matchs this passkey $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'"; $result1=mysql_query($sql1) or die(mysql_error()); // If successfully queried if($result1) { // Count how many row has this passkey $count=mysql_num_rows($result1); ## again addeded here echo "I HAVE REACHED HERE, RESULT WAS SUCCESSFUL AND TOTAL ROWS ".$count; ## // if found the passkey in the database, retrieve data from table "temp_users" ## ARE YOU SURE YOU ARE GETTING ONLY ONE RESULTS if($count > 0) // i changed here......... { $rows=mysql_fetch_array($result1); $name=$_POST['name']; $address=$_POST['address']; $address1=$_POST['address1']; $address2=$_POST['address2']; $address3=$_POST['address3']; $address4=$_POST['address4']; $county=$_POST['county']; $zip=$_POST['zip']; $telephone=$_POST['telephone']; $email=$_POST['email']; $username=$_POST['username']; $password=$_POST['password']; $tbl_name2="users"; // Insert data that retrieves from "temp_users" into table "users" $sql2="INSERT INTO `$tbl_name2` (`name`, `address`, `address1`, `address2`, `address3`, `address4`, `county`, `zip`, `telephone`, `email`, `username`, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result2=mysql_query($sql2) or die(mysql_error()); } // if not found passkey, display message "Wrong Confirmation code" else { echo "Wrong Confirmation code"; } // if successfully moved data from table"temp_users" to table "users" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db" if($result2) { echo "Your account has been activated"; // Delete information of this user from table "temp_users" that has this passkey $sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'"; $result3=mysql_query($sql3) or die(mysql_error()); } } ?> Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 28, 2007 Author Share Posted November 28, 2007 I got the 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 'WHERE confirm_code ='9a5d8c0aa8c6f6badbe553fd575a415e'' at line 1 Quote Link to comment Share on other sites More sharing options...
shedokan Posted November 28, 2007 Share Posted November 28, 2007 can you show the whole mysql query? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 28, 2007 Author Share Posted November 28, 2007 $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'"; Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 28, 2007 Share Posted November 28, 2007 Change this line and check $sql1="SELECT * FROM $tbl_name1 WHERE `confirm_code`={$passkey}"; Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted November 28, 2007 Author Share Posted November 28, 2007 now getting Unknown column 'f1f3f1a24c29e436cfe913ac05c4c504' in 'where clause' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.