pinochio Posted September 21, 2009 Share Posted September 21, 2009 I need to create a guestbook that will check for User Name duplicates and then will store in .txt file <html xmlns="http://www.w3.org/1999/xhtml"> <!-- Created on: 9/15/2009 --> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <title></title> </head> <body> <?php error_reporting(E_ALL); function validateName($GuestName) { if (strpos($GuestName, " ") !== FALSE) return true; else return false; } function validateEmail($GuestEmail) { //validation emaIL if ((strpos($GuestEmail, "@") !== FALSE) && (strpos($GuestEmail, ".") !== FALSE)) return true; else return false; } function checkForDuplicates($GuestbookUser) // function check for duplicates. { $myFile = "./GuestbookFile.txt"; $fh = fopen($myFile, 'r'); if(filesize($myFile)>0) { $theData = fread($fh, filesize($myFile)); fclose($fh); $entries = explode("*", $theData); $i = 0; foreach ($entries as $entry) { $data = explode(",", $entry); if($data[0] == $GuestbookUser) { echo $data[0]; return true; } echo $i++; } } return false; } $GuestName = $_POST["GuestName"]; //else if (validateName($_POST["GuestName"]) == FALSE) if (validateName($_POST["GuestName"]) == FALSE) echo "<p> Your name is not valid. There is no space in between. Click BACK button and type a valid name.</p>"; else echo "<p>$GuestName</p>"; $GuestEmail = $_POST["GuestEmail"]; if (validateEmail($_POST["GuestEmail"]) == FALSE) echo "<p>Your email address is not valid. Click BACK button and type a valid email.</p>"; else echo "<p>$GuestEmail</p>"; $GuestbookUser = $_POST["GuestName"] && $_POST["GuestEmail"]; //checking for duplicates {mistake here} if (checkforduplicates($GuestbookUser) == true) //function is here but it is still not working echo "<p>Your name is used in our guestbook. Please click your browsers BACK button to return and enter different name.</p>"; else { $GuestbookFile = fopen("./GuestbookFile.txt", "r+");//writes data into a file variable for txt file fwrite($GuestbookFile, $GuestName.",".$GuestEmail."*"); fclose($GuestbookFile); } ?> </body> </html> and this is what i got after entering user name which was "first time user " Alex Mick [email protected] mjgx shxc Your name is used in our guestbook. Please click your browsers BACK button to return and enter different name Quote Link to comment https://forums.phpfreaks.com/topic/175044-debugging-problems/ Share on other sites More sharing options...
DavidAM Posted September 21, 2009 Share Posted September 21, 2009 $GuestbookUser = $_POST["GuestName"] && $_POST["GuestEmail"]; //checking for duplicates {mistake here} && is a logical operator NOT concatenation (? I've never been able to spell that!). Try $GuestbookUser = $_POST["GuestName"] . "," . $_POST["GuestEmail"]; //checking for duplicates {mistake here} Quote Link to comment https://forums.phpfreaks.com/topic/175044-debugging-problems/#findComment-922572 Share on other sites More sharing options...
pinochio Posted September 21, 2009 Author Share Posted September 21, 2009 thanks, but this is what i got after i changed everything: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in c:\program files\apache group\Apache\htdocs\CT\signguestbook.php on line 25 Quote Link to comment https://forums.phpfreaks.com/topic/175044-debugging-problems/#findComment-922603 Share on other sites More sharing options...
ozestretch Posted September 22, 2009 Share Posted September 22, 2009 Made comments in code <html xmlns="http://www.w3.org/1999/xhtml"> <!-- Created on: 9/15/2009 --> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <title></title> </head> <body> <?php error_reporting(E_ALL); function validateName($GuestName) { if (strpos($GuestName, " ") != FALSE) return true; else return false; } function validateEmail($GuestEmail) { //validation emaIL if ((strpos($GuestEmail, "@") != FALSE) && (strpos($GuestEmail, ".") != FALSE)) return true; else return false; } function checkForDuplicates($GuestbookUser) // function check for duplicates. var = email only { $myFile = "./GuestbookFile.txt"; $fh = fopen($myFile, 'r'); if(filesize($myFile)>0) { $theData = fread($fh, filesize($myFile)); fclose($fh); $entries = explode("*", $theData); $i = 0; foreach ($entries as $entry) { $data = explode(",", $entry); // since your exploding (My Name,[email protected]) - only check data[1] if($data[1] == $GuestbookUser ) // CHANGED - from data[0] - checking for the actual email only { echo $data[1]; return true; } echo $i++; } } return false; } $GuestName = $_POST["GuestName"]; //else if (validateName($_POST["GuestName"]) == FALSE) if (validateName($GuestName) == FALSE) echo "<p> Your name is not valid. There is no space in between. Click BACK button and type a valid name.</p>"; else echo "<p>$GuestName</p>"; $GuestEmail = $_POST["GuestEmail"]; if (validateEmail($GuestEmail) == FALSE) echo "<p>Your email address is not valid. Click BACK button and type a valid email.</p>"; else echo "<p>$GuestEmail</p>"; //$GuestbookUser = $GuestName.",".$GuestEmail; //checking for duplicates {mistake here} if (checkforduplicates($GuestEmail) == true) //function is here but it is still not working - CHANGED submit email only echo "<p>Your name is used in our guestbook. Please click your browsers BACK button to return and enter different name.</p>"; else { $GuestbookFile = fopen("./GuestbookFile.txt", "r+");//writes data into a file variable for txt file fwrite($GuestbookFile, $GuestName.",".$GuestEmail."*"); fclose($GuestbookFile); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/175044-debugging-problems/#findComment-922860 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.