NLCGraphics Posted August 28, 2008 Share Posted August 28, 2008 Hi, VER: PHP5.2.2 and mySql 5.0.45 I've been learning mySql and have a book and everything. Yep amazing but the question lies within the code of one of the tutorials. Making a newsletter subscription page. The problem is when I submit my form it comes up as an HTTP 500 Internal Server Error. I have a feeling it has to do with this part of the code somehow: $display_block=" <form method=\"POST\" action =\"".$_SERVER["PHP_SELF"]."\"> I don't like posting long code but I don't know where I'm going wrong, please take a look and see if everything looks ok, I copied it right from the book. ** EDIT: View issue here http://www.skywardz.com/manage.php Thanks, NLCGraphics <?php //set up a couple of functions function doDB(){ global $mysqli; //connect to server and select database; you may need it $mysqli = mysqli("mavedog21.startlogicmysql.com","sky77", "eman","testdb"); // if connection fail, stop script execution if(mysqli_connect_errno()){ printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } } function emailChecker ($email){ global $mysqli, $check_res; //check that email is not already in list $check_sql = "SELECT id FROM subscribers WHERE email ='".$email."'"; $check_res = mysqli_query ($mysqli, $check_sql) or die (mysqli_error($mysqli)); } //determine if they need to see the form or no if(!$_POST){ //they need to see the form, so create form block $display_block=" <form method=\"POST\" action =\"".$_SERVER["PHP_SELF"]."\"> <p><strong>Your Email Address:</strong><br/> <input type=\"text\" name=\"email\" size=\"40\"></p> <p><strong> Action:</strong><br/> Subscribe: <input name=\"action\" type=\"radio\" value=\"sub\" checked /> Unsubscribe: <input name=\"action\" type=\"radio\" value=\"unsub\"> <p><input type=\"submit\" name=\"submit\" value=\"Submit Form\"></p> </form>"; }else if ($_POST["action"]=="sub"){ //trying to subscribe; validate emil address if ($_POST["email"]==""){ header("Location: manage.php"); }else{ //connect to database doDB(); //checkthat email is in list emailChecker($_POST["email"]); //get number of results and do action if (mysqli_num_rows($check_res) < 1){ //free result mysqli_free_result($check_res); //add record $add_sql="INSERT INTO subscribers (email) VALUES('".$_POST["email"]."')"; $add_res= mysqli_query($mysqli, $add_sql) or die (mysqli_error($mysqli)); $display_block= "<p> Thank you for signing up</p>"; //close connection to MySql mysqli_close($mysqli); }else{ //print failure message $display_block="<p>You're already subscribed</p>"; } } }else if (($_POST) && ($_POST["action"]=="unsub")){ //trying to unsubscribe; validate email address if ($_POST["email"]==""){ header("Location: manage.php"); exit; }else{ //connect to database doDB(); $display_block = $_POST["email"]; //checkthat email is in list emailChecker($_POST["email"]); //get number of results and do action if (mysqli_num_rows($check_res) < 1){ //free result mysqli_free_result($check_res); //print failure message //$display_block="<p>Couldn't find your address!</p> No action was taken.</p>"; }else{ //get value of ID from result while($row=mysqli_fetch_array($check_res)){ $id=$row["id"]; } //unsubscribe the address $del_sql="DELETE FROM subscribers WHERE id='".$id."'"; $del_res=mysqli_query($mysqli, $del_sql) or die (mysqli_error($mysqli)); $display_block= "<p> You're now unsubscribed.</p>"; } mysqli_close($mysqli); } } ?> Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/ Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 tip: you can make things easier for yourself by consistently using single quotes inside HTML elements. that way you can use double-quoted strings in PHP without escaping every double-quote in your HTML elements. Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/#findComment-628194 Share on other sites More sharing options...
NLCGraphics Posted August 28, 2008 Author Share Posted August 28, 2008 When I use single quotes inside the double quotes the page does not even appear. I get an automatic error. I've tried a bunch of different ways with the quotes. this way so far works the best. At least it displays the page. The other wasy seem to display a blank page when loading. Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/#findComment-628213 Share on other sites More sharing options...
DarkWater Posted August 28, 2008 Share Posted August 28, 2008 Try adding these 2 lines to the top of your page: <?php ini_set('display_errors', 1); error_reporting(E_ALL); P.S: I know it's 3 lines, but the opening PHP tag was just for syntax highlighting. Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/#findComment-628232 Share on other sites More sharing options...
NLCGraphics Posted August 28, 2008 Author Share Posted August 28, 2008 Thanks for that! It told me line 11 was not complete.... mysqli != mysqli_connect.... I forgot the "_connect" part. Thanks again! I feel so much better. Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/#findComment-628235 Share on other sites More sharing options...
DarkWater Posted August 28, 2008 Share Posted August 28, 2008 Make sure to correct any other errors in there. Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/#findComment-628236 Share on other sites More sharing options...
DarkWater Posted August 29, 2008 Share Posted August 29, 2008 Read your PM. No I didn't really see any other errors, but I was just letting you know in case some did pop up. Does it still not work? Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/#findComment-628745 Share on other sites More sharing options...
NLCGraphics Posted August 29, 2008 Author Share Posted August 29, 2008 no other problems.... just new to this and thought you might have seen something coded a little backward or something. I love that error report. Thanks again. Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/#findComment-628750 Share on other sites More sharing options...
DarkWater Posted August 29, 2008 Share Posted August 29, 2008 No problem. Please mark this topic as solved. xD Link to comment https://forums.phpfreaks.com/topic/121769-solved-php-_serverquotphp_selfquot-and-mysql-question/#findComment-628756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.