DeanWhitehouse Posted April 24, 2008 Share Posted April 24, 2008 I am trying to intergrate several forms, into one page. this is my code <?php /*Random Game Design: PHP Website Template/CMS Version 1 Copyright Dean Whitehouse, 2008*/ if(isset($_POST['check'])) { // Database Connection Information $dbhost = $_POST["dbhost"]; // Database Host $dbuser = $_POST["dbuser"]; // Database Username $dbpass = $_POST["dbpass"]; // Database Password $dbname = $_POST["dbname"]; // Database Name // Attempt to connect to the database using the user submitted form. $con = mysql_connect($dbhost, $dbuser, $dbpass); if (!$con) { die('Could not connect: ' . mysql_error()); } // Error, connection cannot be made if ($con) { include 'config_write.php'; echo "You have successfully connected with these details to '$dbname'. <br>Username - '$dbuser'<br> Password - '$dbpass'<br> Database Host - '$dbhost'<br>Please enter the table names you want, or if you want to use the preset names click continue. NOTE: Each table must be a different name. Please do not leave any blank spaces. <table align='center' bgcolor='#333333' width='300px' border='0'>"; ?> <form method='post' action=<?php $_SERVER['PHP_SELF']; ?>'> <tr><td> <font color='#FFFFFF'> User Details:</td><td> <input type='text' name='user' value='rgd_users'><br></td></tr> <tr><td><font color='#ffffff'>Forum Questions</td> <td><input type='text' name='forum_question' value='forum_question'></td></tr> <tr><td><font color='#ffffff'>Forum Answers</td> <td><input type='text' name='forum_answers' value='forum_answers'><br></td></tr> <tr><td></td><td><input type='submit' value='Continue' name='table_names'></td></tr> </font> </form> </table> <?php } else { echo 'Error connecting to database:' . mysql_error() . '\n'; // Database creation failed ?> <p>Welcome to the random game design website template. Please follow this set-up and then you can customise your site fully.<br>Plese only click this button once, as it will reset your progress.<form method='post' action="<?php $_SERVER['PHP_SELF']; ?>"><input type='submit' value='Start' name='start'></form> </p> <?php } // Close connection to the database mysql_close(); } if(isset($_POST['start'])) { echo ('Please enter the details used to connect to your MySql database.'); ?> <table align='center' bgcolor='#333333' width='300px' border='0'><form method='post' action="<?php $_SERVER['PHP_SELF']; ?>"> <tr><td> Database Host:</td><td> <input type='text' name='dbhost'><br></td></tr> <tr><td> Database Username:</td><td> <input type='text' name='dbuser'><br></td></tr> <tr><td> Database Password: </td><td> <input type='text' name='dbpass'><br></td></tr> <tr><td> Database Name: </td><td> <input type='text' name='dbname'><br></td></tr> <tr><td></td><td><input type='submit' value='Continue' name='check'> </td></tr></form> </table> <?php } else { ?> <p>Welcome to the random game design website template. Please follow this set-up and then you can customise your site fully.<br>Plese only click this button once, as it will reset your progress.<form method='post' action="<?php $_SERVER['PHP_SELF']; ?>"><input type='submit' value='Start' name='start'></form> </p> <?php } ?> ok, the first form on the list(which is the second one displayed) shows this underneath it <p>Welcome to the random game design website template. Please follow this set-up and then you can customise your site fully.<br>Plese only click this button once, as it will reset your progress.<form method='post' action="<?php $_SERVER['PHP_SELF']; ?>"><input type='submit' value='Start' name='start'></form> How can i fix it, i only want to show that if they haven't clicked start( i am planning on adding sessions for security) could i use them to do it? Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Author Share Posted April 24, 2008 anyone , this is just the part that isn't working properly if(isset($_POST['check'])) { // Database Connection Information $dbhost = $_POST["dbhost"]; // Database Host $dbuser = $_POST["dbuser"]; // Database Username $dbpass = $_POST["dbpass"]; // Database Password $dbname = $_POST["dbname"]; // Database Name // Attempt to connect to the database using the user submitted form. $con = mysql_connect($dbhost, $dbuser, $dbpass); if (!$con) { die('Could not connect: ' . mysql_error()); } // Error, connection cannot be made if ($con) { include 'config_write.php'; echo "You have successfully connected with these details to '$dbname'. <br>Username - '$dbuser'<br> Password - '$dbpass'<br> Database Host - '$dbhost'<br>Please enter the table names you want, or if you want to use the preset names click continue. NOTE: Each table must be a different name. Please do not leave any blank spaces. "; ?> <table align='center' bgcolor='#333333' width='300px' border='0'> <form method='post' action=<?php $_SERVER['PHP_SELF']; ?>'> <tr><td> <font color='#FFFFFF'> User Details:</td><td> <input type='text' name='user' value='rgd_users'><br></td></tr> <tr><td><font color='#ffffff'>Forum Questions</td> <td><input type='text' name='forum_question' value='forum_question'></td></tr> <tr><td><font color='#ffffff'>Forum Answers</td> <td><input type='text' name='forum_answers' value='forum_answers'><br></td></tr> <tr><td></td><td><input type='submit' value='Continue' name='table_names'></td></tr> </font> </form> </table> <?php } else { echo 'Error connecting to database:' . mysql_error() . '\n'; // Database creation failed ?> <p>Welcome to the random game design website template. Please follow this set-up and then you can customise your site fully.<br>Plese only click this button once, as it will reset your progress.<form method='post' action="<?php $_SERVER['PHP_SELF']; ?>"><input type='submit' value='Start' name='start'></form> </p> <?php } // Close connection to the database mysql_close(); } else { ?> <p>Welcome to the random game design website template. Please follow this set-up and then you can customise your site fully.<br>Plese only click this button once, as it will reset your progress.<form method='post' action="<?php $_SERVER['PHP_SELF']; ?>"><input type='submit' value='Start' name='start'></form> </p> <?php } any help would be really good, the problem is this else { ?> <p>Welcome to the random game design website template. Please follow this set-up and then you can customise your site fully.<br>Plese only click this button once, as it will reset your progress.<form method='post' action="<?php $_SERVER['PHP_SELF']; ?>"><input type='submit' value='Start' name='start'></form> </p> <?php } shows all the time Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Wait, why are you letting them make the connection details through a form? Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Author Share Posted April 24, 2008 its for a CMS system, and this is part of the install files. So they can connect through to there database. And i am adding sessions to help protect the pages, and also an IP session that will be set when it is first run so only the person with that ip can access it Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 You're making a CMS system that you plan to distribute to others? You know that you're going to have to write these database connection parameters to file, correct? Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Author Share Posted April 24, 2008 yes to the both, i am plaaning on adding securtity to all the important files. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Give us the whole script. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Author Share Posted April 24, 2008 the one at the top is Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Put this at the top of your script: print_r($_POST); And tell me what it outputs AFTER you post the form. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Author Share Posted April 24, 2008 ok, after the database details form it prints this Array ( [dbhost] => *** [dbuser] => *** [dbpass] => *** [dbname] => **** [check] => Continue ) with detials init but i have hidden these on the above version and on the second form it prints this Array ( [user] => rgd_users [forum_question] => forum_question [forum_answers] => forum_answers [table_names] => Continue ) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Try doing this: Remove these lines: if (!$con) { die('Could not connect: ' . mysql_error()); } // Error, connection cannot be made Add exit(); after this: <td><input type='text' name='forum_answers' value='forum_answers'><br></td></tr> <tr><td></td><td><input type='submit' value='Continue' name='table_names'></td></tr> </font> </form> </table> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Author Share Posted April 24, 2008 ok, that works i think, there is no way to be sure. BTW was does exit(); do??? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Kill the script at that point, so it doesn't go on to display the same form again. =) Quote Link to comment 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.