BrettHartel Posted December 3, 2012 Share Posted December 3, 2012 (edited) Thank you to everyone who is taking the time to read my post and help me. Brief - I want the user to enter their eMail into the form and submit it to signup.php; the PHP file will do the following: Generate a random User_ID that is 16 characters long. Check the database to make sure the Unque_ID does not exist. If it does exists the script will generate another random User_ID and attempt again . If it does NOT exist the PHP script will continue. Check the database to make sure the eMail does not exists. If it does exists the fuction will not create a new account and displays "eMail already exists." If it does NOT exists then the script will continue. The PHP script will add the informtion to the table named "eMail" as a new entry. I keep getting this error: Parse error: syntax error, unexpected T_FUNCTION in /home/diamon79/public_html/signup.php on line 12 Line 12 is function generateRandomString($User_ID = 16) { The form to submit content: <form action="signup.php" method="post"> eMail: <input type="text" name="eMail"> <input type="submit"> </form> The PHP script the form is posted to: <?php $con = mysql_connect("localhost","*********","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("diamon79_mysql", $con); $eMail == '$_POST[eMail]' function generateRandomString($User_ID = 16) { return substr(str_shuffle("0123456789"), 0, $User_ID); } $searchquery = "SELECT * FROM eMail WHERE `Column_A` = '$User_ID'"; $searchresult = mysql_query($searchquery) or die(mysql_error()); if (mysql_num_rows($searchresult) == 0) { eMailCheck(); } // no rows found else { generateRandomString($User_ID = 16); } function eMailCheck() $searcheMailquery = "SELECT * FROM eMail WHERE `Column_B` = '$eMail'"; $searcheMailresult = mysql_query($searcheMailquery) or die(mysql_error()); if (mysql_num_rows($searcheMailresult) == 0) { PostInformation(); } // no rows found else { echo "eMail already exists"; } function PostInformation() $sql="INSERT INTO eMail (User_ID, eMail) VALUES ('$User_ID','$_POST[eMail]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?> I downloaded Notepad++ to be able to debug the script, but I cannot figure out how to use it properly so I am posting here. Thank you. Brett Hartel Edited December 3, 2012 by BrettHartel Quote Link to comment https://forums.phpfreaks.com/topic/271564-parse-error-while-trying-to-verify-unique-email/ Share on other sites More sharing options...
requinix Posted December 3, 2012 Share Posted December 3, 2012 (edited) Oh boy. 1. You posted your database credentials on a public forum. 2. I doubt your password actually contains a newline character in it. 3. == means comparison, = means assignment. Your $eMail line is using the wrong one. 4. When you set $eMail you put single quotes around $_POST. Variables do not work in single-quoted strings. Get rid of the quotes entirely and put two around the "eMail" array key instead. 5a. In generateRandomString() why is the variable called $User_ID? 5b. You give a default of 16 but the string you're shuffling only has 10 digits. 5c. User IDs should not be randomly generated. 6. For $searchquery you never set the value of $User_ID. 7. You call eMailCheck() without giving it any arguments. You need to tell it what email to check. 8. You call generateRandomString() but all you do is assign $User_ID=16. 9. The function definition of eMailCheck() needs {}s around the body of the code. 10. It also doesn't have any parameters for code to pass in the email. Variables like $eMail from outside the function are not available inside the function. 11. See points #4, #7 (needs the user ID), #9, and #10 (which applies to $User_ID and $con) for PostInformation() too. Edited December 3, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/271564-parse-error-while-trying-to-verify-unique-email/#findComment-1397340 Share on other sites More sharing options...
BrettHartel Posted December 4, 2012 Author Share Posted December 4, 2012 (edited) WOW! Thanks for the help! Now I get this error: Error: Query was empty Here is the updated script with requinix's help: <?php $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("diamon79_mysql", $con);[/u] [u]function generateRandomString($Generate_ID = 16) { return substr(str_shuffle("01234567890123456789"), 0, $Generate_ID); }[/u] [u]$searchquery = "SELECT * FROM eMail WHERE `User_ID` = '$Generate_ID'";[/u] [u]$searchresult = mysql_query($searchquery) or die(mysql_error());[/u] [u]if (mysql_num_rows($searchresult) == 0) { $User_Id = $Generate_ID; eMailCheck(); } // no rows found else { generateRandomString(); }[/u] [u]function eMailCheck() { $eMail = "$_POST[eMail]"; return $eMail; } $searcheMailquery = "SELECT * FROM eMail WHERE `eMail` = '$eMail'";[/u] [u]$searcheMailresult = mysql_query($searcheMailquery) or die(mysql_error()); if (mysql_num_rows($searcheMailresult) == 0) { PostInformation(); } // no rows found else { echo "eMail already exists"; } function PostInformation() { $sql="INSERT INTO eMail (User_D, eMail) VALUES ('$User_ID','$_POST[eMail]')"; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?> Edited December 4, 2012 by BrettHartel Quote Link to comment https://forums.phpfreaks.com/topic/271564-parse-error-while-trying-to-verify-unique-email/#findComment-1397348 Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2012 Share Posted December 4, 2012 I hope you changed your database password in addition to editing it out of your post. Google indexes these pages usually within a couple minutes. If you haven't changed it yet, go do it right now. Quote Link to comment https://forums.phpfreaks.com/topic/271564-parse-error-while-trying-to-verify-unique-email/#findComment-1397350 Share on other sites More sharing options...
BrettHartel Posted December 4, 2012 Author Share Posted December 4, 2012 I hope you changed your database password in addition to editing it out of your post. Google indexes these pages usually within a couple minutes. If you haven't changed it yet, go do it right now. Thank you I have changed my password. Quote Link to comment https://forums.phpfreaks.com/topic/271564-parse-error-while-trying-to-verify-unique-email/#findComment-1397351 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.