xtoyduck Posted January 21, 2011 Share Posted January 21, 2011 Having problems with my script echo without form being completed yet. Any help would be appreciated. The echo that is outputting early is "You must enter a Session Name". <html> <head> <title>ReH-0.1--Create a Session</title> </head> <body bgcolor="575757"> <center> <?php $error = "Could not connect to the database"; mysql_connect('localhost','root','') or die ($error); mysql_select_db('temp') or die ($error); //Set Variables $id = $_POST['id']; $table = $POST['table']; //Check for exsistence if (!$id or !$table) { echo "<font color='#ff0000'>You must enter a Session Name</font>"; } else { echo "Congrats!"; } ?> <h2 style="color:#fff">ReH-0.1 Password Encryption</h2><br><br> <font color="#fff">Before encrypting your password, a session must be started. We need you to enter a personal session name that you will remember so that you password is protected by this session.</font><br><br> <form action="session_start.php" method="POST"> <label for="id" style="color: #fff;">Session Name: <input type="text" maxlength="10" size="10" name="id"></label><br><br> <label for="table" style="color: #fff;">Session Name Confirmation: <input type="text" maxlength="10" size="10" name="table"></label><br><br> <input type="submit" value="Create Session"> </form> </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/225139-form-echo-problem/ Share on other sites More sharing options...
ruddie Posted January 21, 2011 Share Posted January 21, 2011 You are saying that there is no form yet. Which means the post variables will be NULL or false. Then your if statements simply checks if either of them is false, which they are. Meaning it will output "You must enter a Session name" I do not see a problem here really? Also, this kind of code should normally be placed in in a seperate file, next to your index.php file.. then the form will direct you towards this file, and in this seperate file, if you use $_POST['id'] you will get the form's "id" field. So.. any more questions? Link to comment https://forums.phpfreaks.com/topic/225139-form-echo-problem/#findComment-1162869 Share on other sites More sharing options...
xtoyduck Posted January 21, 2011 Author Share Posted January 21, 2011 But when the form loads for the first time. The echo statement is not suppose to output unless they do not type in anything in either field upon hitting the submit button. Link to comment https://forums.phpfreaks.com/topic/225139-form-echo-problem/#findComment-1163093 Share on other sites More sharing options...
BlueSkyIS Posted January 21, 2011 Share Posted January 21, 2011 only validate the data if the form is submitted if ($_SERVER['REQUEST_METHOD'] == "POST") { //Set Variables $id = $_POST['id']; $table = $POST['table']; // etc... Link to comment https://forums.phpfreaks.com/topic/225139-form-echo-problem/#findComment-1163101 Share on other sites More sharing options...
xtoyduck Posted January 21, 2011 Author Share Posted January 21, 2011 Okay it fixed my problem, but caused another Now I can't even get my echo to pop up. It just takes me to my "session_start.php" page without leaving the error echo. Here's the code: <html> <head> <title>ReH-0.1--Create a Session</title> </head> <body bgcolor="575757"> <center> <?php $error = "Could not connect to the database"; mysql_connect('localhost','root','') or die ($error); mysql_select_db('temp') or die ($error); if ($_SERVER['REQUEST_METHOD'] == "POST") { //Set Variables $id = $_POST['id']; $table = $_POST['table']; //Check for existense if (!$id or !$table) { echo "You must enter a session name to continue"; } else { echo "Thank You!"; } } else { echo "Sorry, but the request to grab data has failed"; ?> <h2 style="color:#fff">ReH-0.1 Password Encryption</h2><br><br> <font color="#fff">Before encrypting your password, a session must be started. We need you to enter a personal session name that you will remember so that you password is protected by this session.</font><br><br> <form action="session_start.php" method="POST"> <label for="id" style="color: #fff;">Session Name: <input type="text" maxlength="10" size="10" name="id"></label><br><br> <label for="table" style="color: #fff;">Session Name Confirmation: <input type="text" maxlength="10" size="10" name="table"></label><br><br> <input type="submit" value="Create Session"> </form> </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/225139-form-echo-problem/#findComment-1163128 Share on other sites More sharing options...
BlueSkyIS Posted January 21, 2011 Share Posted January 21, 2011 looks like the if is missing a closing bracket after the else } else { echo "Sorry, but the request to grab data has failed"; } // missing Link to comment https://forums.phpfreaks.com/topic/225139-form-echo-problem/#findComment-1163130 Share on other sites More sharing options...
xtoyduck Posted January 21, 2011 Author Share Posted January 21, 2011 Still didn't fix it...Do I need to add stuff other than the html of the "session_start.php" to make it output the echo? Link to comment https://forums.phpfreaks.com/topic/225139-form-echo-problem/#findComment-1163328 Share on other sites More sharing options...
jsparrow Posted January 21, 2011 Share Posted January 21, 2011 Under your set variables you have: //Set Variables $id = $_POST['id']; $table = $POST['table']; Fix the $table variable to $_POST['table']; Link to comment https://forums.phpfreaks.com/topic/225139-form-echo-problem/#findComment-1163337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.