Jump to content

Login System and Adding data into a Database


timmykins02

Recommended Posts

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 :)

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

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>";
?>

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.

 

 

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?  :shrug:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.