xtoyduck Posted January 17, 2011 Share Posted January 17, 2011 Problem: My code is not functioning at all on my form. I would like to see why? Scripting Info: Using PHP and MySQL Using offline Server for testing(XAMPP) Using default Server name and login.(localhost,root,[NO PASSWORD]) Database name is reh_temp Table within database is named users 1 Value in table "users" called users Goal: My form has 3 inputs. 2-Text and 1-Submit. The 1st text input has the name of id. And the 2nd input has the name of table. In the PHP/MySQL part the values are inputed as follows: The one with name of "id" gets put into the table users under the users value. The one with name of "table" creates a new table named after what the user inputs The rest of the script is just Character Length checks, Exsistance of value checks, Match check, ect. Here's the code: <?php $connect1 = mysql_connect("localhost","root",""); if (!$connect) die('Could not connect to the database: ' . mysql_error()); $id = $_POST['id']; $table = $POST['table']; //Check for existance if (!$id) die('You need to type in a session name.'); else { if (!$table) die('You need to re-enter you session name.'); } //Check for existance in Database mysql_select_db("reh_temp", $connect1); $q_id = mysql_query("SELECT * FROM users WHERE users='$id'"); if (mysql_num_rows($q_id)==0) { //Check Character Length if (strlen($id)<4||strlen($table)<4) die('Please enter a session name that is more than 4 characters.'); else { //Check for Match if ($id==$table) { //Insert value into users table mysql_select_db("reh_temp", $connect1); $q_id_reg = mysql_query("INSERT INTO users VALUES ('$id')"); mysql_select_db("reh_temp", $connect1); $session_table = "CREATE TABLE $table ( password varchar(10) )"; die ('Thanks!'); } else die ('Your session names do not match!'); } } else die ('The session name you choose is already in use. Please choose a different one.'); { ?> <head> <title>ReH-0.1--Create a Session</title> </head> <body bgcolor="#575757"> <center> <font color="#ffffff">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="ReH-0.1.php" method="POST"> <input type="text" maxlength="10" size="10" name="id"><br> <font color="#ffffff">Please choose a session name.</font><br><br> <input type="text" maxlength="10" size="10" name="table"><br> <font color="#ffffff">Please re-enter you session name.</font><br><br> <input type="submit" value="Create Session"> </form> </center> </body> <?php } echo "I'm Working!"; ?> Any help and suggestions would help. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/ Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 What exactly do you mean by 'not functioning at all'? Blank screen? Error messages? Other? Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1160953 Share on other sites More sharing options...
Maq Posted January 17, 2011 Share Posted January 17, 2011 Could you please elaborate on "My code is not functioning at all on my form."? What happens? Are there any errors? Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1160954 Share on other sites More sharing options...
xtoyduck Posted January 17, 2011 Author Share Posted January 17, 2011 I mean it's not acting at all. I type in incorrect stuff that should not be allowed like under 4 characters. It does not reply with the "die('Your session name must more than 4 characters');" and just not storing the data. I've done all the checks and nothing is working. I've done PHP and MySQL before and this has never happened. I don't know if it's the way I coded it or am I putting the PHP coding on the wrong page. The action is "session_start" and method is "POST". Any reasons or help to get it working. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161068 Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 So does that mean you're getting a blank screen? You kind of have to help us help you, you know. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161072 Share on other sites More sharing options...
Muddy_Funster Posted January 17, 2011 Share Posted January 17, 2011 The action is "session_start" and method is "POST". Any reasons or help to get it working. are you trying to call SESSION_START() as a form action from your html form? If you are that may be part of the problem. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161073 Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 You may have a fatal error. Place these 2 lines directly after your opening <?php tag: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161083 Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 And another thing... You're using '$connect1' for the connection variable but checking the connection with '$connect'. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161084 Share on other sites More sharing options...
xtoyduck Posted January 18, 2011 Author Share Posted January 18, 2011 Still isn't running... I did both. With the error code and the $connect1 changed to $connect. Any other suggestions or fixes. And by the way what happens when I hit the submit button is absolutely nothing. It just removes the text from the text fields and is on the same page. It used to move to the "session_start.php" page. But now it's not. Also I'm not looking for session_start(). I know what that is I'm creating a "so-called" session. It's for a password converter, the session just creates a user and from that user creates a table based off the session name given it doesn't break the checks for existence. That's literally all I need this portion of the code to do is to add value of 1st text field to users under user table and create a new table based off what they name it. The checks are to make sure the name doesn't already exist, match each other, and makes sure that the name is between 4-10 characters. If someone can make this code better fine, but I was for sure this should work. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161119 Share on other sites More sharing options...
xtoyduck Posted January 18, 2011 Author Share Posted January 18, 2011 Okay I see why my "action" value wasn't taking me to the other page. I accidentally had the value as the same page. But when it goes to next page it is just a blank page with no "echo" for the error. Nor did it store the data. Sorry for the double-post. I just now found the Edit Message button. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161122 Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 Did you temporarily turn on error reporting? You may have a fatal error. Place these 2 lines directly after your opening <?php tag: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161132 Share on other sites More sharing options...
xtoyduck Posted January 18, 2011 Author Share Posted January 18, 2011 How do you turn that on? Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161147 Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 How do you turn that on? I've said it twice already. Please read this quote: You may have a fatal error. Place these 2 lines directly after your opening <?php tag: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161152 Share on other sites More sharing options...
xtoyduck Posted January 18, 2011 Author Share Posted January 18, 2011 But I've already did that and it didn't do a thing. I can always record video of everything I'm doing and what it looks like if that'd help. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161159 Share on other sites More sharing options...
crabfinger Posted January 18, 2011 Share Posted January 18, 2011 Upon further thought this reply was not correct tech help Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161160 Share on other sites More sharing options...
crabfinger Posted January 18, 2011 Share Posted January 18, 2011 did a little work to clean your code up. not sure why you want to create another table with one thing in it, why not just add a column to the users table. <html> <head> <title>ReH-0.1--Create a Session</title> </head> <body bgcolor="#575757"> <center> <?php try { // Connect and select $connect = mysql_connect("localhost","root",""); if(!$connect) { throw new Exception( mysql_error() ); } mysql_select_db( "reh_temp", $connect ); // verify post-data if( isset( $_POST['session'] ) && !empty( $_POST['session'] ) ) { if( strlen( $_POST['session'] ) < 4 ) { throw new Exception('Session must be longer than four characters'); } $session = mysql_real_escape_string($_POST['session']); } else { throw new Exception( 'Session Required' ); } if(isset($_POST['session_conf']) && !empty($_POST['session_conf'])) { if( strlen( $_POST['session_conf'] ) < 4 ) { throw new Exception('Session confirmation must be longer than four characters'); } $session_conf = mysql_real_escape_string($_POST['session_conf']); } else { throw new Exception( 'Session Confirmation Required' ); } // Query post data $query = mysql_query("SELECT * FROM users WHERE users='${session}'"); if( mysql_num_rows( $query ) != 0 ) { //Check for Match if ( $session != $session_conf ) { throw new Exception('Session does not match confirmation'); } //Insert value into users table if( !@mysql_query( "INSERT INTO users VALUES ( '${session}' )" ) ) { throw new Exception( mysql_error() ); } // if this executes the script is complete print '<font color="#0F0">Success</font>'; } catch(Exception $objException) { print '<font color="#f00">' . $obj->Exception->getMessage() . '</font><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 /> <form action="ReH-0.1.php" method="POST"> <label for="session" style="color: #fff;">Session Name: <input type="text" maxlength="10" size="10" name="session"></label><br /> <label for="session_conf" style="color: #fff;">Session Name Confirmation: <input type="text" maxlength="10" size="10" name="session_conf"></label><br /> <input type="submit" value="Create Session"> </form> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161169 Share on other sites More sharing options...
xtoyduck Posted January 18, 2011 Author Share Posted January 18, 2011 Tried your code and I get this: Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161586 Share on other sites More sharing options...
Pikachu2000 Posted January 18, 2011 Share Posted January 18, 2011 You can't access the script as file:///C:/Users/ etc. It must be parsed by the webserver via http://localhost/ . . . Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161594 Share on other sites More sharing options...
xtoyduck Posted January 19, 2011 Author Share Posted January 19, 2011 Oh I'm sorry. I totally forgot about making sure my files are in the right spot. I feel so stupid now. It's just been a while since I've used XAMPP and done PHP. It sound like it's been mostly my fault this whole time. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161714 Share on other sites More sharing options...
Maq Posted January 19, 2011 Share Posted January 19, 2011 Oh I'm sorry. I totally forgot about making sure my files are in the right spot. I feel so stupid now. It's just been a while since I've used XAMPP and done PHP. It sound like it's been mostly my fault this whole time. Just to clarify. It's not a matter of files being in the right spot. It's about having the web-server parsing your files rather than accessing them from your file system in the browser. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1161942 Share on other sites More sharing options...
xtoyduck Posted January 20, 2011 Author Share Posted January 20, 2011 Okay I've finally got my scripts to work, but on flaw I'd like to get solved. My echo is showing before from is filled out. Please correct me if my coding is out of format. The echo that is always up when I reload page is the "You must enter a Session Name" one. 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); //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> Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1162315 Share on other sites More sharing options...
Maq Posted January 20, 2011 Share Posted January 20, 2011 Please mark this as solved and create a new thread. It will allow for more people to help you. Quote Link to comment https://forums.phpfreaks.com/topic/224759-code-not-functioning/#findComment-1162500 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.