timmykins02 Posted May 4, 2012 Share Posted May 4, 2012 So I have to add data into my database for Olympic records for a school project. I have the sql statements and everything, but it will only enter the athlete's name and country into the table. My code is <html> <head> <title> CSS </title> <style type="text/css"> p {font-family:arial; font-size:10pt;} body {margin: 0; padding: 0; text-align: center;} a:link {text-decoration: none} a:visited {text-decoration: overline; color:purple;} a:active {text-decoration: underline;} a:hover {text-decoration: line-through ; color:pink} input:hover {background: aqua; color:black} input:active { background: lime ; color: black; } input:focus { background: yellow; color: black; } .button {border: 1px dotted ; background:red; padding: 2px;} .button:hover {border: 2px dotted;background: url('submitbackground.jpg') no-repeat top left; } #main {margin: 0 auto; text-align: left; width: 800px;} #nav {clear: both; border: 1px solid; background-color:lightgreen; padding: 10px; width:auto; height: 8%;} #div1 {border: 1px solid; background-color:lightblue; padding: 10px; float: left; width:20%; height:92%;} #div2 {border: 1px solid; background-image: url('monkey.jpg'); background-repeat:no-repeat; background-position:center bottom ; padding: 10px; float:left; width:74.5%; height:92%;} </style> </head> <body> <?php session_start () ; print_r ($_REQUEST) ; if ($_SESSION['admin'] == 2) { echo " sorry" ; } else { echo $_SESSION['admin']; if(isset($_POST['athname'])){ $athname= $_POST['athname'] ; } if(isset($_POST['country'])){ $country = $_POST['country']; } if(isset($_POST['medal'])){ $medal= $_POST ['medal']; } if(isset($_POST['venueyear'])){ $venueyear= $_POST ['venueyear']; } if(isset($_POST['venuecity'])){ $venuecity= $_POST ['venuecity']; } if(isset($_POST['venuecountry'])){ $venuecountry= $_POST ['venuecountry']; } if(isset($_POST['event'])){ $event= $_POST ['event']; } if(isset($_POST['gender'])){ $gender= $_POST ['gender']; } echo "<div id='main'> " ; echo"<div id='nav'>"; echo"</div>" ; echo "<div id='div1'>" ; echo "<a href='index.php'>home</a><br/>" ; echo "<a href='search.php'>Search</a><br/>" ; echo "<a href='add-data.php'>Add Data</a><br/>" ; echo "<a href='DeleteData.php'>Delete Data</a>" ; echo "</div>" ; echo"<div id='div2'>" ; if (isset($_POST['search'])) { $connection = odbc_connect('Olympics', '', ''); if (!$connection) {exit("Conection Failed: " . $connection);} $enrID = null ; if ( $event == '100 meters' and $gender == 'M') { $enrID = 1 ; echo "$enrID" ; }elseif ($event == '200 meters' and $gender == 'M') { $enrID = 2 ; echo "$enrID" ; }elseif ($event == '400 meters'and $gender == 'M') { $enrID = 3 ; }elseif ($event == '800 meters' and $gender == 'M') { $enrID = 4 ; }elseif ($event == '1500 meters' and $gender == 'M') { $enrID = 5 ; }elseif ($event == 'Long Jump' and $gender == 'M') { $enrID = 6 ; }elseif ($event == 'High Jump' and $gender == 'M') { $enrID = 7 ; }elseif ($event == 'Shot put' and $gender == 'M') { $enrID = 8 ; }elseif ($event == 'basketball' and $gender == 'M') { $enrID = 13 ; }elseif ($event == 'rowing' and $gender == 'M') { $enrID = 14 ; }elseif ($event == 'volleyball(indoor)' and $gender == 'M') { $enrID = 15 ; }elseif ($event == 'volleyball(beach)' and $gender == 'M') { $enrID = 16 ; }elseif ($event == '100 meters' and $gender == 'F') { $enrID = 17 ; }elseif ($event == '200 meters' and $gender == 'F') { $enrID = 18 ; }elseif ($event == '400 meters'and $gender == 'F') { $enrID = 19 ; }elseif ($event == '800 meters' and $gender == 'F') { $enrID = 20 ; }elseif ($event == '1500 meters' and $gender == 'F') { $enrID = 21 ; }elseif ($event == 'Long Jump' and $gender == 'F') { $enrID = 22 ; }elseif ($event == 'High Jump' and $gender == 'F') { $enrID = 23 ; }elseif ($event == 'Shot put' and $gender == 'F') { $enrID = 24 ; }elseif ($event == 'basketball' and $gender == 'F') { $enrID = 25 ; }elseif ($event == 'rowing' and $gender == 'F') { $enrID =26 ; }elseif ($event == 'volleyball(indoor)' and $gender == 'F') { $enrID = 27 ; }elseif ($event == 'volleyball(beach)' and $gender == 'F') { $enrID = 28 ; } $EnrVenID = null ; if ($venueyear == '1984') { $EnrVenID = 1 ; echo "$EnrVenID" ; }elseif ($venueyear == '1988') { $EnrVenID = 2 ; }elseif ($venueyear == '1992') { $EnrVenID = 3 ; }elseif ($venueyear == '1996') { $EnrVenID = 4 ; }elseif ($venueyear == '2000') { $EnrVenID = 5 ; }elseif ($venueyear == '2004') { $EnrVenID = 6 ; }elseif ($venueyear == '2008') { $EnrVenID = 7 ; echo "$EnrVenID" ; }elseif ($venueyear == '2012') { $EnrVenID = 8 ; echo "$EnrVenID" ; } $sql="INSERT INTO Athletes (Athname, Athcountry) values ( '$athname', '$country') " ; $rs=odbc_exec($connection,$sql); $sql4="INSERT INTO Enrollments (EnrMedal, EnrYear, EnrEventID, EnrVenID) values ( '$medal', '$venueyear', '$enrID', '$EnrVenID') " ; $rs4=odbc_exec($connection,$sql4); } echo "<form method='post' action=''>\n"; echo"Please fill out all the fields with the data that you wish to be added: <br/>"; echo"Athelete Name:<input type ='text' Name='athname' > <br/> \n" ; echo"Athelete Country:<input type ='text' Name='country' > <br/> \n" ; echo "Medal: <select name='medal' value='medal'>\n"; echo "<option > </option>\n"; echo "<option $Gold> Gold </option>\n"; echo "<option $Silver> Silver </option>\n"; echo "<option $Bronze'> Bronze</option>\n"; echo "</select>\n" ; echo "Venue Year: <select name='venueyear' value= 'venueyear'>\n"; echo "<option ></option>\n"; echo "<option $1984> 1984 </option>\n"; echo "<option $1988> 1988 </option>\n"; echo "<option $1992>1992 </option>\n"; echo "<option $1996> 1996 </option>\n"; echo "<option $2000> 2000 </option>\n"; echo "<option $2004> 2004 </option>\n"; echo "<option $2008> 2008 </option>\n"; echo "<option $2012> 2012</option>\n"; echo "</select>\n" ; echo "Venue City: <select name='venuecity' value= 'venuecity'>\n"; echo "<option > </option>\n"; echo "<option $LA> Los Angeles </option>\n"; echo "<option $Seoul> Seoul </option>\n"; echo "<option $Barca> Barcelona </option>\n"; echo "<option $ATL> Atlanta</option>\n"; echo "<option $Syd> Sydney </option>\n"; echo "<option $Ath> Athens</option>\n"; echo "<option $Beij> Beijing </option>\n"; echo "<option $Lon> London</option>\n"; echo "</select>\n" ; echo "Venue City: <select name='venuecountry' value= 'venuecountry'>\n"; echo "<option > </option>\n"; echo "<option $USA> U.S.A. </option>\n"; echo "<option $SK> South Korea </option>\n"; echo "<option $Spain> Spain </option>\n"; echo "<option $Aus> Australia </option>\n"; echo "<option $Greece> Greece</option>\n"; echo "<option $Chin> China </option>\n"; echo "<option $UK> United Kingdom</option>\n"; echo "</select>\n" ; echo "Event: <select name='event' value='event>\n"; echo "<option value=''> </option>\n"; echo "<option > </option>\n"; echo "<option $100m> 100 meters</option>\n"; echo "<option $200m> 200 meters </option>\n"; echo "<option $400m>400 meters </option>\n"; echo "<option $800m> 800 meters </option>\n"; echo "<option $1500m> 1500 meters </option>\n"; echo "<option $LongJump> Long Jump</option>\n"; echo "<option $HighJump> High Jumo </option>\n"; echo "<option $Shotput> Shot put </option>\n"; echo "<option $Basketball> Basketball </option>\n"; echo "<option $Rowing> Rowing </option>\n"; echo "<option $Volleyball> Indoor Volleyball </option>\n"; echo "<option $Volley> Beach Volleyball</option>\n"; echo "</select>\n" ; echo "Gender: <select name='gender'>\n"; echo "<option value=''> </option>\n"; echo "<option $Male>M</option>\n"; echo "<option $Female>F</option>\n"; echo "</select>\n" ; echo "<input type='submit' name='search' value='Search' />\n"; echo "</form>\n"; echo "</div>" ; } ?> </body> </html> I have the really long IF statements in there so that it enters the correct EnrID and EnrVenID into the database, to make sure it fills out all fields. I am using Microsoft access for my database. The problem is that it will only fill in the athlete's name and country, and not his/her enrollment information (what medal they got, their enr ID, what year it was taken place, etc. The problem with my login system is that I want the user to login with a username and password if they wish to be an admin, but the login system doesn't work. the variables aren't passed through the system for some reason, even though it worked a week ago, but now it doesn't. The code is if(isset($_POST['username'])){ $username= $_POST['username'] ; } if(isset($_POST['password'])){ $password= $_POST['password'] ; } $username = null ; $password = null ; Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/ Share on other sites More sharing options...
scootstah Posted May 4, 2012 Share Posted May 4, 2012 if(isset($_POST['username'])){ $username= $_POST['username'] ; } if(isset($_POST['password'])){ $password= $_POST['password'] ; } $username = null ; $password = null ; Do you really not see a problem here? Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1342950 Share on other sites More sharing options...
timmykins02 Posted May 4, 2012 Author Share Posted May 4, 2012 um no? Well at first I had $username = stripelashes($username) ; or however you wrote it . Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1342979 Share on other sites More sharing options...
MMDE Posted May 4, 2012 Share Posted May 4, 2012 um no? Well at first I had $username = stripelashes($username) ; or however you wrote it . Read the little code snippet scootstah posted from the top to the bottom. Try to understand what you do, then you ask yourself, is what I wanted to happen what I've accomplished? and it should be stripslashes, which makes no sense you use at all! o.O Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1342983 Share on other sites More sharing options...
scootstah Posted May 4, 2012 Share Posted May 4, 2012 What happens after that code? You are setting variables and then immediately setting them to null right after. Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1342984 Share on other sites More sharing options...
downah Posted May 5, 2012 Share Posted May 5, 2012 $username = null ; $password = null ; why do you set them to nothing..? that way the variable is empty Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343394 Share on other sites More sharing options...
timmykins02 Posted May 6, 2012 Author Share Posted May 6, 2012 Well it doesn't work even when i took out the lines where I set the variables to null. And I have no clue what's the problem Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343458 Share on other sites More sharing options...
scootstah Posted May 6, 2012 Share Posted May 6, 2012 Does the login system have anything to do with adding data to the database, or are these separate problems? Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343462 Share on other sites More sharing options...
timmykins02 Posted May 6, 2012 Author Share Posted May 6, 2012 the login system just checks if the username and password are in the database, but the variables arent being passed Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343521 Share on other sites More sharing options...
scootstah Posted May 6, 2012 Share Posted May 6, 2012 You didn't post any code for that. Also, the variables have no value because you set them to null. Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343577 Share on other sites More sharing options...
timmykins02 Posted May 7, 2012 Author Share Posted May 7, 2012 Even when i didn't null them out it doesnt work. here is the code <?php session_start () ; print_r ($_REQUEST) ; if(isset($_GET['message'])){ echo $_GET['message']; } if (isset($_POST['login'])) { if(isset($_POST['username'])){ $username= $_POST['username'] ; } if(isset($_POST['password'])){ $password= $_POST['password'] ; } $connection = odbc_connect('Olympics', '', ''); if (!$connection) {exit("Conection Failed: " . $connection);} $sql = "select count (*) AS counter from Users where Users ='$username' AND Passwords ='$password'"; $rs=odbc_exec($connection,$sql); echo "<table border='1'> \n"; echo " query<br/> \n"; (odbc_fetch_row($rs)) ; $query=odbc_result($rs, 1); if ($query == 1) { $_SESSION['loggedIn'] = "true"; $_SESSION['admin'] = 1 ; header("Location: search.php"); } elseif ($query == 0) $_SESSION['loggedIn'] = "false"; $_SESSION['admin'] = 0 ; $_SESSION['attempts'] =$_SESSION['attempts'] + 1 ; header("Location: index.php?message=Login Failed," . $_SESSION['attempts']); }elseif (isset($_POST['continue'])) { $_SESSION['loggedIn'] = "free"; $_SESSION['admin'] = 0 ; header("Location: search.php?message=You have logged in as a user. You do not have admin privileges. If you wish to have admin privileges, please log in. "); } echo "<div id='main'> " ; echo"<div id='nav'>"; echo"</div>" ; echo "<div id='div1'>" ; echo "</div>" ; echo"<div id='div2'>" ; echo "<form action='index.php' method='post'> \n" ; echo" Please enter your username and password if you wish. <br/> \n" ; echo "Username: <input type='text' name='username' > \n " ; echo "<br/>Password: <input type='password' name='password' > \n" ; echo "<br/><input type='submit' value='login' name='login'> <br/> \n" ; echo "</form>" ; echo "You may also continue as a guest if you wish. You will not be given administrator privileges."; echo "<form action='index.php' method='post'> \n" ; echo "<br/><input type='submit' value='Continue' name='continue'> <br/> \n" ; echo "</form" ; echo "</div>" ; echo "<div id='div3'>" ; echo "</div>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343635 Share on other sites More sharing options...
TimeBomb Posted May 7, 2012 Share Posted May 7, 2012 Even when i didn't null them out it doesnt work. Hmm. I see a possible issue with this line of code: if (isset($_POST['login'])) { Why don't you tell us what code that if conditional is supposed to contain? Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343647 Share on other sites More sharing options...
timmykins02 Posted May 7, 2012 Author Share Posted May 7, 2012 It is supposed to the run the rest of the code... like after the person presses submit it is supposed to run the SQL statement and check if the username and password are in the database, and if they are then it takes the user to the next page. Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343651 Share on other sites More sharing options...
TimeBomb Posted May 7, 2012 Share Posted May 7, 2012 It is supposed to the run the rest of the code... like after the person presses submit it is supposed to run the SQL statement and check if the username and password are in the database, and if they are then it takes the user to the next page. I see. I found where the if conditional starts. Can you show me where it ends? Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343653 Share on other sites More sharing options...
timmykins02 Posted May 7, 2012 Author Share Posted May 7, 2012 Ah.. I got it I was looking where it ends and i noticed i forget a bracket in my other conditional statement, but i fixed that and it works now. Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/262059-login-system-and-adding-data-into-a-database/#findComment-1343665 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.