Kane250 Posted September 1, 2008 Share Posted September 1, 2008 I was on here a while back geting help with my code and everything finally got sorted out. Now I was told by a friend that it doesn't work anymore. I checked and it does not. The page that runs the INSERT is just bypassing all of my validations and not inserting anything into the database...it's basically just reloading that page... Does anyone see anything wrong with this? It was working fine... Thanks! The code starts on this page (I took out all the extra html): <?php session_start(); $_SESSION['emailform'] = $_POST['email']; ?> <div id="emailform"> <form method="post" action="index.php"/> <input type='text' value="" name="email" /> </div> <div id="emailcheck"> <input type="submit" value="" class="button" onclick="wopen('mainsub.php', 'popup', 400, 375); return true;" onmouseover="this.className='button-over';" onmouseout="this.className='button';" /> </div> <?php if ($_POST) { $emailaddy = $_POST['email']; } ?> Then goes to a popup window where the bulk of the code runs here: <?php session_start(); ?> <?php //CONNECT TO DATABASE $dbhost = 'host'; $dbuser = 'user'; $dbpass = 'pw'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'marialist'; mysql_select_db($dbname); $duplicate = 0; print "<p>"; //IF THE SUBMIT BUTTON IS PRESSED, CHECK EACH POST FIELD FOR DATA & CONTINUE VALIDATION, OTHERWISE DISPLAY ERROR if (isset($_POST['submit'])) { if (!empty($_POST['email'])) { //HERE WE ARE DECLARING VARAIBLES TO SEE IF THE EMAIL ADDRESS IS ALREADY ENTERED INTO THE DATABASE $emailaddy = $_POST['email']; $doubleaddycheck = "SELECT * FROM emaillist WHERE email = '$emailaddy'"; $doubleaddycheck = mysql_query($doubleaddycheck); if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { print "Please enter a valid e-mail address<br />";} //USING THOSE VARIABLES TO CHECK THE DATABASE elseif (mysql_num_rows($doubleaddycheck) > 0) { $duplicate = 1; print "That e-mail address has already been added!<br />"; } else { $emailaddy = $_POST['email']; } } else { print "Please enter an e-mail address<br />"; } if (!empty($_POST['firstname'])) { $firstname = $_POST['firstname'];} else { print "Please enter a first name.<br />"; } if (!empty($_POST['lastname'])){ $lastname = $_POST['lastname'];} else { print "Please Enter a last name.<br />"; } if ((strlen($emailaddy)>0) && (strlen($firstname)>0) && (strlen($lastname)>0) && ($duplicate)<1) { $insertcontactdata = "INSERT INTO emaillist (email, firstname, lastname) VALUES ('$emailaddy', '$firstname', '$lastname')"; mysql_query($insertcontactdata); print "Welcome to the list<b> $firstname! </b><br />\n"; print "Your e-mail address: <b> $emailaddy </b>will be included in future e-mails."; } } print "</p>"; mysql_close($conn); ?> <form method="post" action="mainsub.php" /> <p> First name: <input type='text' value="" name="firstname" /><br /><br /> Last name: <input type='text' value="" name="lastname" /><br /><br /> E-Mail Address: <input type='text' value="<?PHP echo "{$_SESSION['emailform']}"; ?>" name = "email" /><br /></p> <br /> <input type='submit' value="Submit!" name="submit" /><br /> Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/ Share on other sites More sharing options...
JonnoTheDev Posted September 1, 2008 Share Posted September 1, 2008 Has the user upgraded their web browser. Your javascript may be out of date. Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-630849 Share on other sites More sharing options...
Kane250 Posted September 1, 2008 Author Share Posted September 1, 2008 No, this isnt a browser issue as I am using the same browser as before and it's not working. The popup comes up no problem, it's the php /mysql code not inserting data into the table, and I don't understand why this would randomly stop after it was working fine... Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631261 Share on other sites More sharing options...
Kane250 Posted September 2, 2008 Author Share Posted September 2, 2008 pleaseeeeee can someone take a quick look? I've gone over it over and over and cannot find anything :-( Surely there's some pro on here that can tell me I'm an idiot and show me what went wrong? Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631568 Share on other sites More sharing options...
corbin Posted September 2, 2008 Share Posted September 2, 2008 Run print_r() on $_POST on the second page. I think the POST values aren't being passed to the second window. Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631577 Share on other sites More sharing options...
Kane250 Posted September 2, 2008 Author Share Posted September 2, 2008 Run print_r() on $_POST on the second page. I think the POST values aren't being passed to the second window. It doesnt show anything with print_r(), however the only value being passed from page one to page two is the email address that is entered into the form, and that is working. The first and last name and email address are all actually submitted to the db from the second page... Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631589 Share on other sites More sharing options...
corbin Posted September 2, 2008 Share Posted September 2, 2008 Ah ok.... Sorry, mis-read the code. Didn't realize the form on that page was submitting to its self. So uh... What does the popup say? Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631592 Share on other sites More sharing options...
Kane250 Posted September 2, 2008 Author Share Posted September 2, 2008 I sent you a link you can try out. On the popup youre supposed to enter the rest of the info and after submitting, it's supposed to say "thanks, youve been added" Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631596 Share on other sites More sharing options...
corbin Posted September 2, 2008 Share Posted September 2, 2008 "Your e-mail address: a@lol.com will be included in future e-mails." It works. It's your JS that is messed up. It's checking for reloaded=1 in the url, and the form is submitting without that, so the JS is changing the page. Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631597 Share on other sites More sharing options...
Kane250 Posted September 2, 2008 Author Share Posted September 2, 2008 weird...ok cool, well thats reassuring! Unfortunately, I think if I take that reload=1 out of there, the email address will not carry over to the popup until the page has been reloaded once. Do you know what I'm talking about? I came across this issue before too. Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631603 Share on other sites More sharing options...
corbin Posted September 2, 2008 Share Posted September 2, 2008 You could simply make the form submit with the reloaded=1 on there: <form action="somepage.php?reloaded=1" method="POST"> I should mention, by the way, that this only works on POST forms. On a GET submitted form, you would have to use a hidden field. Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631606 Share on other sites More sharing options...
Kane250 Posted September 2, 2008 Author Share Posted September 2, 2008 wait, I'm sorry, I don't see now where that reloaded=1 is at...are you talking about the javascript code itself or somewhere else? first or second page? I'm going to try and take out the js and do what you said but I cant even see where to take it out from... Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631610 Share on other sites More sharing options...
corbin Posted September 2, 2008 Share Posted September 2, 2008 <form method="post" action="mainsub.php?reloaded=1" /> <p> First name: <input type='text' value="" name="firstname" /><br /><br /> Last name: <input type='text' value="" name="lastname" /><br /><br /> E-Mail Address: <input type='text' value="<?PHP echo "{$_SESSION['emailform']}"; ?>" name = "email" /><br /></p> <br /> <input type='submit' value="Submit!" name="submit" /><br /> Then you won't need to remove the javascript. Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631612 Share on other sites More sharing options...
Kane250 Posted September 2, 2008 Author Share Posted September 2, 2008 that actually makes the page load to a blank white page after doing that...thats why I was asking where you see the reloaded=1 is at. I thought I knew, but I think I was thinking of something else...and I did a search in my code and it cannot find it anywhere.. Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631615 Share on other sites More sharing options...
corbin Posted September 2, 2008 Share Posted September 2, 2008 Can you post your entire code, without the HTML parts shortened? Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631620 Share on other sites More sharing options...
Kane250 Posted September 2, 2008 Author Share Posted September 2, 2008 Absolutely. First Page: <?php session_start(); $_SESSION['emailform'] = $_POST['email']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>The Bubble: A New Musical Dot Comedy</title> <link rel="stylesheet" type="text/css" href="stylesheet.css" /> <script type="text/javascript"> image1 = new Image(); image1.src = "images/homeselect.gif"; image2 = new Image(); image2.src = "images/castcrewselect.gif"; image3 = new Image(); image3.src = "images/mediaselect.gif"; </script> <script type="text/javascript"> function wopen(url, name, w, h) { w += 20; h += -20; var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no'); win.resizeTo(w, h); win.focus(); } </script> </head> <body> <div id="newcontainer"> <div id="emailheader"> <div id="emailform"> <form method="post" action="castcrew.php"/> <input type='text' value="" name="email" /> <input type="submit" value="" class="button" onclick="wopen('mainsub.php', 'popup', 400, 375); return true;" onmouseover="this.className='button-over';" onmouseout="this.className='button';" /> </div> </div> <div id="newfullcontent"> </div> <div id="nav"> <a href="index.html" onmouseover="image1.src='images/homeselect.gif';" onmouseout="image1.src='images/home.gif';"> <img name="image1" src="images/home.gif" border="0"></a> <a href="castcrew.html"> <img src="images/castcrewselect.gif" border="0"></a> <a href="media.html" onmouseover="image3.src='images/mediaselect.gif';" onmouseout="image3.src='images/media.gif';"> <img name="image3" src="images/media.gif" border="0"></a> </div> </div> <?php //WHEN FORM IS POSTED, VALIDATE THE E-MAIL FORM. IF ALL IS OK, ADD THE EMAIL TO THE VARIABLE. if ($_POST) { $emailaddy = $_POST['email']; } ?> </body> </html> Popup Page: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Subscribe</title> <link rel="stylesheet" type="text/css" href="bubblesub.css" /> <script> var reloaded = false; var loc=""+document.location; loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):""; loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc; reloaded = loc!=""?(loc=="true"):reloaded; function reloadOnceOnly() { if (!reloaded) window.location.replace(window.location+"?reloaded=true"); } reloadOnceOnly(); </script> </head> <body> <?php //CONNECT TO DATABASE $dbhost = 'host'; $dbuser = 'user'; $dbpass = 'pw'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'bubblelist'; mysql_select_db($dbname); $duplicate = 0; print "<p>"; //IF THE SUBMIT BUTTON IS PRESSED, CHECK EACH POST FIELD FOR DATA & CONTINUE VALIDATION, OTHERWISE DISPLAY ERROR if (isset($_POST['submit'])) { if (!empty($_POST['email'])) { //HERE WE ARE DECLARING VARAIBLES TO SEE IF THE EMAIL ADDRESS IS ALREADY ENTERED INTO THE DATABASE $emailaddy = $_POST['email']; $doubleaddycheck = "SELECT * FROM bubbleemail WHERE email = '$emailaddy'"; $doubleaddycheck = mysql_query($doubleaddycheck); if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { print "Please enter a valid e-mail address<br />";} //AND HERE WE ARE USING THOSE VARIABLES TO CHECK THE DATABASE elseif (mysql_num_rows($doubleaddycheck) > 0) { $duplicate = 1; print "That e-mail address has already been added!<br />"; } else { $emailaddy = $_POST['email']; } } else { print "Please enter an e-mail address<br />"; } if (!empty($_POST['firstname'])) { $firstname = $_POST['firstname'];} else { print "Please enter a first name.<br />"; } if (!empty($_POST['lastname'])){ $lastname = $_POST['lastname'];} else { print "Please Enter a last name.<br />"; } if ((strlen($emailaddy)>0) && (strlen($firstname)>0) && (strlen($lastname)>0) && ($duplicate)<1) { $insertcontactdata = "INSERT INTO bubbleemail (email, firstname, lastname) VALUES ('$emailaddy', '$firstname', '$lastname')"; mysql_query($insertcontactdata); print "Welcome to the list<b> $firstname! </b><br />\n"; print "Your e-mail address: <b> $emailaddy </b>will be included in future e-mails."; } } print "</p>"; mysql_close($conn); ?> <form method="post" action="mainsub.php?reloaded=1" /> <p> First name: <input type='text' value="" name="firstname" /><br /><br /> Last name: <input type='text' value="" name="lastname" /><br /><br /> E-Mail Address: <input type='text' value="<?PHP echo "{$_SESSION['emailform']}"; ?>" name = "email" /><br /></p> <br /> <input type='submit' value="Submit!" name="submit" /><br /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631622 Share on other sites More sharing options...
Kane250 Posted September 2, 2008 Author Share Posted September 2, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-631849 Share on other sites More sharing options...
Kane250 Posted September 3, 2008 Author Share Posted September 3, 2008 ??? Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-632389 Share on other sites More sharing options...
corbin Posted September 4, 2008 Share Posted September 4, 2008 Hey sorry.... Hurricane left overs knocked out some stuff here, so I haven't been able to get on the Internet. Anyway, I would do it like this: <?php session_start(); //errrr.... You weren't checking if the POST variable was set or not... if($_POST) { $_SESSION['emailform'] = (isset($_POST['email'])) ? trim($_POST['email']) : null; } //You shouldn't have a DOCTYPE that's not at the very top.... Maybe I'm just paranoid ;p ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>The Bubble: A New Musical Dot Comedy</title> <link rel="stylesheet" type="text/css" href="stylesheet.css" /> <script type="text/javascript"> image1 = new Image(); image1.src = "images/homeselect.gif"; image2 = new Image(); image2.src = "images/castcrewselect.gif"; image3 = new Image(); image3.src = "images/mediaselect.gif"; </script> <script type="text/javascript"> function HandleEmail() { wopen('mainsub.php', 'email_popup', 400, 375); document.email_form.submit(); } function wopen(url, name, w, h) { w += 20; h += -20; var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no'); win.resizeTo(w, h); win.focus(); } </script> </head> <body> <div id="newcontainer"> <div id="emailheader"> <div id="emailform"> <form method="post" action="castcrew.php" target="email_popup" onsubmit="HandleEmail(); return false;" name="email_form"> <input type='text' value="" name="email" /> <input type="submit" value="" class="button" onmouseover="this.className='button-over';" onmouseout="this.className='button';" /> </form> </div> </div> <div id="newfullcontent"> </div> <div id="nav"> <a href="index.html" onmouseover="image1.src='images/homeselect.gif';" onmouseout="image1.src='images/home.gif';"> <img name="image1" src="images/home.gif" border="0"></a> <a href="castcrew.html"> <img src="images/castcrewselect.gif" border="0"></a> <a href="media.html" onmouseover="image3.src='images/mediaselect.gif';" onmouseout="image3.src='images/media.gif';"> <img name="image3" src="images/media.gif" border="0"></a> </div> </div> <?php //Why would you have this at the end of the page? You never use $emailaddy. //WHEN FORM IS POSTED, VALIDATE THE E-MAIL FORM. IF ALL IS OK, ADD THE EMAIL TO THE VARIABLE. //if ($_POST) { // $emailaddy = $_POST['email']; //} ?> </body> </html> <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Subscribe</title> <link rel="stylesheet" type="text/css" href="bubblesub.css" /> <script> var reloaded = false; var loc=""+document.location; loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):""; loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc; reloaded = loc!=""?(loc=="true"):reloaded; function reloadOnceOnly() { if (!reloaded) window.location.replace(window.location+"?reloaded=true"); } reloadOnceOnly(); </script> </head> <body> <?php $duplicate = 0; print "<p>"; //IF THE SUBMIT BUTTON IS PRESSED, CHECK EACH POST FIELD FOR DATA & CONTINUE VALIDATION, OTHERWISE DISPLAY ERROR if (isset($_POST['submit'])) { //I wouldn't connect to the DB unless you know you're going to need it. waste of time connecting before they submit. //CONNECT TO DATABASE $dbhost = 'host'; $dbuser = 'user'; $dbpass = 'pw'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'bubblelist'; mysql_select_db($dbname); if (!empty($_POST['email'])) { //HERE WE ARE DECLARING VARAIBLES TO SEE IF THE EMAIL ADDRESS IS ALREADY ENTERED INTO THE DATABASE $emailaddy = $_POST['email']; $doubleaddycheck = "SELECT * FROM bubbleemail WHERE email = '$emailaddy'"; $doubleaddycheck = mysql_query($doubleaddycheck); if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { print "Please enter a valid e-mail address<br />"; } elseif (mysql_num_rows($doubleaddycheck) > 0) { //AND HERE WE ARE USING THOSE VARIABLES TO CHECK THE DATABASE $duplicate = 1; print "That e-mail address has already been added!<br />"; } else { $emailaddy = $_POST['email']; } } else { print "Please enter an e-mail address<br />"; } if (!empty($_POST['firstname'])) { $firstname = $_POST['firstname'];} else { print "Please enter a first name.<br />"; } if (!empty($_POST['lastname'])){ $lastname = $_POST['lastname'];} else { print "Please Enter a last name.<br />"; } if ((strlen($emailaddy)>0) && (strlen($firstname)>0) && (strlen($lastname)>0) && ($duplicate)<1) { //unless your server has magic quotes on (which shouldn't be used), you need to be sanitizing SQL stuff.... $insertcontactdata = "INSERT INTO bubbleemail (email, firstname, lastname) VALUES ('".mysql_real_escape_string($emailaddy)."', '".mysql_real_escape_string($firstname)."', '".mysql_real_escape_string($lastname)."')"; if(mysql_query($insertcontactdata)) { print "Welcome to the list<b> $firstname! </b><br />\n"; print "Your e-mail address: <b> $emailaddy </b>will be included in future e-mails."; } } mysql_close($conn); } print "</p>"; ?> <form method="post" action="mainsub.php?reloaded=true" > <p> First name: <input type='text' value="" name="firstname" /><br /><br /> Last name: <input type='text' value="" name="lastname" /><br /><br /> E-Mail Address: <input type='text' value="<?PHP echo "{$_SESSION['emailform']}"; ?>" name = "email" /><br /></p> <br /> <input type='submit' value="Submit!" name="submit" /><br /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-634011 Share on other sites More sharing options...
Kane250 Posted September 4, 2008 Author Share Posted September 4, 2008 Thanks! I'll try this when I get home. The reaso I have $emailaddyon the first page is because I am using that variable to carry it over to the popup so that it is already filled in. I'll update about the results of this! Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-634018 Share on other sites More sharing options...
corbin Posted September 4, 2008 Share Posted September 4, 2008 Errrr.... PHP doesn't work like that. HTTP is a 'stateless' protocol, meaning one request is considered entirely unrelated to all previous ones (cookies provide a way to tell someone is the same client, and sessions are built on cookies [or GET variables]). GET, POST, COOKIE, and sessions are essentially the only ways to transfer data from one page to another. For example: page1.php $x = 5; page2.php //x isn't set on this page Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-634025 Share on other sites More sharing options...
Kane250 Posted September 4, 2008 Author Share Posted September 4, 2008 Oh I see, so you're saying that when I had it carry over, the code at the bottom of the first page wasn't contributing to that happening, but I was taking care of it on the second page entirely... ? Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-634095 Share on other sites More sharing options...
Kane250 Posted September 5, 2008 Author Share Posted September 5, 2008 Well...your code is cleaner definitely, and it does carry my email address over to the popup like I want, however when I submit all the info it is still reloading that page to a blank white page. This was the problem I was having before I posted the full code...It's obviously a php error...maybe I'm missing a semicolon ??? Looking through to see if I see anything Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-634211 Share on other sites More sharing options...
corbin Posted September 5, 2008 Share Posted September 5, 2008 Try: <?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Subscribe</title> <link rel="stylesheet" type="text/css" href="bubblesub.css" /> </head> <body> <?php $duplicate = 0; print "<p>"; //IF THE SUBMIT BUTTON IS PRESSED, CHECK EACH POST FIELD FOR DATA & CONTINUE VALIDATION, OTHERWISE DISPLAY ERROR if (isset($_POST['submit'])) { //I wouldn't connect to the DB unless you know you're going to need it. waste of time connecting before they submit. //CONNECT TO DATABASE $dbhost = 'host'; $dbuser = 'user'; $dbpass = 'pw'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'bubblelist'; mysql_select_db($dbname); if (!empty($_POST['email'])) { //HERE WE ARE DECLARING VARAIBLES TO SEE IF THE EMAIL ADDRESS IS ALREADY ENTERED INTO THE DATABASE $emailaddy = $_POST['email']; $doubleaddycheck = "SELECT * FROM bubbleemail WHERE email = '$emailaddy'"; $doubleaddycheck = mysql_query($doubleaddycheck); if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { print "Please enter a valid e-mail address<br />"; } elseif (mysql_num_rows($doubleaddycheck) > 0) { //AND HERE WE ARE USING THOSE VARIABLES TO CHECK THE DATABASE $duplicate = 1; print "That e-mail address has already been added!<br />"; } else { $emailaddy = $_POST['email']; } } else { print "Please enter an e-mail address<br />"; } if (!empty($_POST['firstname'])) { $firstname = $_POST['firstname'];} else { print "Please enter a first name.<br />"; } if (!empty($_POST['lastname'])){ $lastname = $_POST['lastname'];} else { print "Please Enter a last name.<br />"; } if ((strlen($emailaddy)>0) && (strlen($firstname)>0) && (strlen($lastname)>0) && ($duplicate)<1) { //unless your server has magic quotes on (which shouldn't be used), you need to be sanitizing SQL stuff.... $insertcontactdata = "INSERT INTO bubbleemail (email, firstname, lastname) VALUES ('".mysql_real_escape_string($emailaddy)."', '".mysql_real_escape_string($firstname)."', '".mysql_real_escape_string($lastname)."')"; if(mysql_query($insertcontactdata)) { print "Welcome to the list<b> $firstname! </b><br />\n"; print "Your e-mail address: <b> $emailaddy </b>will be included in future e-mails."; } } mysql_close($conn); } print "</p>"; ?> <form method="post" action="mainsub.php" > <p> First name: <input type='text' value="" name="firstname" /><br /><br /> Last name: <input type='text' value="" name="lastname" /><br /><br /> E-Mail Address: <input type='text' value="<?PHP echo "{$_POST['emailform']}"; ?>" name = "email" /><br /></p> <br /> <input type='submit' value="Submit!" name="submit" /><br /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-634272 Share on other sites More sharing options...
Kane250 Posted September 5, 2008 Author Share Posted September 5, 2008 YES! That worked! Thank You!! The email address doesn't carry over from the first page now, but I feel like that's a smaller problem to deal with Thanks a ton! Quote Link to comment https://forums.phpfreaks.com/topic/122163-my-code-randomly-stopped-workingwhat-gives/#findComment-634298 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.