BrettHartel Posted December 4, 2012 Share Posted December 4, 2012 Thank you for the help thus far everyone! I have updated my code with the help of reqinix. Now I have this error: Error: Query was empty 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. 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); function generateRandomString($Generate_ID = 16) { return substr(str_shuffle("01234567890123456789"), 0, $Generate_ID); } $searchquery = "SELECT * FROM eMail WHERE `User_ID` = '$Generate_ID'"; $searchresult = mysql_query($searchquery) or die(mysql_error()); if (mysql_num_rows($searchresult) == 0) { $User_Id = $Generate_ID; eMailCheck(); } // no rows found else { generateRandomString(); } function eMailCheck() { $eMail = "$_POST[eMail]"; return $eMail; } $searcheMailquery = "SELECT * FROM eMail WHERE `eMail` = '$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_D, eMail) VALUES ('$User_ID','$_POST[eMail]')"; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/ Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 1 and 2 can be solved with the php function uniqid(); I see no reason why it needs to be 16 characters long (only 3 longer than what uniqid will create). Unless you can explain it. 3. $result = mysql_query(SELECT * FROM table WHERE email = '$email'); if(mysql_num_rows($result) != "0") { echo "Email exists in the database."; } else { // execute the rest } 4. I don't think I even need to explain it... Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397362 Share on other sites More sharing options...
BrettHartel Posted December 4, 2012 Author Share Posted December 4, 2012 Sorry to confuse you SocialCloud. I am confused about why I keep receiving the error "Error: Query was empty". I am new to PHP and Im not sure where I went wrong. The four points were just to allow the reader to know what I was trying to do. For your comment about #3, is my code incorrect? Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397365 Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 I assumed those were possible errors you were having. Oh well. Do you know which query is empty? Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397369 Share on other sites More sharing options...
BrettHartel Posted December 4, 2012 Author Share Posted December 4, 2012 LOL! That is my problem. I have no idea how to know what query is empty or the steps to figure it out. Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397372 Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 You could always remove the or die(mysql_error()); and replace one by one to see. Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397374 Share on other sites More sharing options...
BrettHartel Posted December 4, 2012 Author Share Posted December 4, 2012 I tried removing the "or die..." but I kept getting the same error. Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397386 Share on other sites More sharing options...
PFMaBiSmAd Posted December 4, 2012 Share Posted December 4, 2012 The query is empty because the php variable, $sql, being put into the mysql_query() statement, near the end of your posted code, doesn't exist in the program scope where the mysql_query() statement is at. Your PostInformation() function definition ends immediately after the assignment statement for the $sql variable. It should end after the echo "1 record added"; statement. Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397388 Share on other sites More sharing options...
BrettHartel Posted December 4, 2012 Author Share Posted December 4, 2012 Thank you PFMaBiSmAd! I am confused on how to end the statment after the echo. Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397389 Share on other sites More sharing options...
PFMaBiSmAd Posted December 4, 2012 Share Posted December 4, 2012 For a function definition, the statements between the opening and closing braces { ... } are the code for that function definition. function PostInformation() { // statements that are part of this function definition go here... } You would need to move the closing } down so that it is after all the statements you intended to be inside that function definition. Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397391 Share on other sites More sharing options...
BrettHartel Posted December 4, 2012 Author Share Posted December 4, 2012 Thank You! Link to comment https://forums.phpfreaks.com/topic/271568-error-query-was-empty-while-verifying-unique-email/#findComment-1397406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.