Coders2018 Posted July 8, 2010 Share Posted July 8, 2010 Hi, I'm developing a soccer league table, for a project I've decided to do. I'm trying to give people a friendly error message when they visit my add_team.php page directly. At the moment if they were to directly type for example http://www.example.com/league_project/add_team.php into the URL bar then it would automatically add a row into my "TeamName" field in the database but without specifying the football team name. You select the football team name by visiting the team_selection.htm file. I just want to make sure that no-one can add blank rows into the "TeamName" field. Here is my current PHP code for the add_team.php file: <html> <head> <title>Team Successfully Added</title> </head> <body> <center> <form action="view_teams.php" method="post"> <?php // Database Connection Information $username = "USERNAME"; $password = "PASSWORD"; $database = "DATABASE_NAME"; // Variables passed from the HTML Form $team_name = $_POST['Team_Name']; // Connect to the database mysql_connect(localhost, $username, $password); @mysql_select_db($database) or die ("Unable to connect to the database provided"); // Insert Team into database $addteam = mysql_query("INSERT INTO Teams (TeamName) VALUES ('$_POST[Team_Name]')"); if(!isset($team_name)){ echo "You have not selected a team to be added to the database"; } // Display on the screen confirmation of the team that's been added. if($addteam == True) { echo "<center>The team you requested $team_name have been added to the database"; } else { echo "<center>The team $team_name could not be added to the database</center>"; } mysql_close(); ?> <input type="submit" name="View_Teams" value="View Teams"> </form> </body> </html> Any help as usual is appreciated. Link to comment https://forums.phpfreaks.com/topic/207172-isset-page-problem/ Share on other sites More sharing options...
Pikachu2000 Posted July 8, 2010 Share Posted July 8, 2010 If the required form hasn't been submitted, send them to it. if( !iiset($_POST['submit']) ) { header('Location: team_selection.htm'); exit(); } Link to comment https://forums.phpfreaks.com/topic/207172-isset-page-problem/#findComment-1083230 Share on other sites More sharing options...
Coders2018 Posted July 9, 2010 Author Share Posted July 9, 2010 I'm sorry that hasn't worked for me. I'm trying to give them a user friendly message if they happen visit the script directly. If they fill in the form and submit it then reach the script that is fine as it will add the team they requested. I just don't want loads of blank rows under my database field. Link to comment https://forums.phpfreaks.com/topic/207172-isset-page-problem/#findComment-1083473 Share on other sites More sharing options...
while1 Posted July 9, 2010 Share Posted July 9, 2010 There's a little typo on Pikachu2000's code. Replace "iiset" with "isset" and $_POST['submit'] with $_POST['View_Teams']. Link to comment https://forums.phpfreaks.com/topic/207172-isset-page-problem/#findComment-1083478 Share on other sites More sharing options...
Coders2018 Posted July 9, 2010 Author Share Posted July 9, 2010 Thanks. I've now managed to fix this issue. I took the code you edited and then I edited it again so that it looked like this: if( !isset($_POST['Team_Name']) ) { echo "You never chose a team to enter into the league."; exit(); } Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/207172-isset-page-problem/#findComment-1083491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.