Created
July 14, 2012 21:10
-
-
Save jennkartchner/3113365 to your computer and use it in GitHub Desktop.
loginVal.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!$_SESSION){ | |
session_start(); | |
} | |
$hostName='157.201.194.254'; | |
$userName = "jdoggett"; | |
$password = ''; | |
if(!($db = mysql_connect($hostName, $userName, $password))) { | |
print"<br> Can't connect"; | |
} | |
else | |
{ | |
} | |
$database = 'jdoggett'; | |
if(!(mysql_select_db($database))) { | |
print "Error could not select database"; | |
} | |
else | |
{ | |
$username = $_POST['username']; | |
$passWord = $_POST['password']; | |
////////////////////////////////////////////////////// | |
$user = "SELECT user_id FROM user WHERE username='$username' and password='$passWord'"; | |
$user_id = mysql_query($user); | |
$users = mysql_fetch_assoc($user_id); | |
$theUser = $users['user_id']; | |
/////////////////////////////////////////////////////// | |
$role = "SELECT role_id FROM user WHERE username='$username' and password='$passWord'"; | |
$role_id = mysql_query($role); | |
$roles = mysql_fetch_assoc($role_id); | |
//echo "role_id" .$roles['role_id']; | |
/////////////////////////////////////////////////////// | |
$sql = "SELECT * FROM user WHERE username='$username' and password='$passWord'"; | |
$result = mysql_query($sql); | |
$row = mysql_fetch_array($result); | |
// //$active = $row['active']; | |
$count = mysql_num_rows($result); | |
// //echo " count " + $count; | |
if($count == 1 && $roles['role_id'] == 1){ | |
$_SESSION['user'] = $theUser; | |
header('Location: teacher.php'); | |
} else if($count == 1 && $roles['role_id'] == 2) { | |
header('Location: adminHome.html'); | |
}else{ | |
//echo $_POST['password']; | |
echo "Wrong Username or Password"; | |
//echo $_POST['password']; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
// if(!isset($_SESSION['user_id'])){ | |
// die('you need to login'); | |
// }else{ | |
echo $_SESSION['user']; | |
print_r($_SESSION); | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns = "http:///www.w3.org/1999/xhtml"> | |
<html> | |
<head> | |
<title>Database Querying | |
</title> | |
<link rel="stylesheet" href="bootstrap-responsive.css" type="text/css" media="screen" /> | |
<link rel="stylesheet" href="bootstrap.css" type="text/css" media="screen" /> | |
</head> | |
<body id="body" onload="getFile()"> | |
<form class="well"> | |
<div style="font-weight: bold; font-size: large;">UVMTA SPRING FESTIVAL</div> | |
</form> | |
<?php | |
if(isset($_GET['action'])){ | |
if ($_GET['action'] == 'select'){ | |
$id = $_GET['id']; | |
$student = selectStudent($id); | |
} | |
elseif($_GET['action'] == 'delete'){ | |
$id = $_GET['student_id']; | |
removeStudent($id); | |
echo "$id"; | |
} | |
elseif($_GET['action'] == 'store'){ | |
storeStudent(); | |
} | |
} | |
/////////STORE//////////////////////////////////// | |
function storeStudent(){ | |
$hostName ='157.201.194.254'; | |
$userName = "jdoggett"; | |
$password = ''; | |
if(!($db = mysql_connect($hostName, $userName, $password))) { | |
print"<br> Can't connect"; | |
} | |
$database = 'jdoggett'; | |
if(!(mysql_select_db($database))) { | |
print "Error could not select database"; | |
} | |
else | |
{ | |
$user_id = $_REQUEST['user_id']; | |
$student_id = $_REQUEST['studentId']; | |
$first_name = $_REQUEST['firstName']; | |
$last_name = $_REQUEST['lastName']; | |
$level_id = $_REQUEST['level_id']; | |
$type_id = $REQUEST['type_id']; | |
$age = $_REQUEST['age']; | |
$instrument = $_REQUEST['instrument']; | |
if($student_id == ""){ | |
$insert = "INSERT INTO students | |
(student_id | |
, first_name | |
, last_name | |
, level_id | |
, type_id | |
, num_festivals | |
, age | |
, instrument | |
, user_id) | |
VALUES | |
('$student_id' | |
, '$first_name' | |
, '$last_name' | |
, '$level_id' | |
, '$type_id' | |
, '$num_festivals' | |
, '$age' | |
, '$instrument' | |
, '$user_id');" ; | |
mysql_query($insert); | |
} | |
else | |
{ | |
$selectResult = "UPDATE students | |
SET first_name = '$first_name' | |
, last_name = '$last_name' | |
, level_id = '$level_id' | |
, type_id = '$type_id' | |
,num_festivals = '$num_festivals' | |
,age = '$age' | |
,instrument = '$instrument' | |
, user_id = '$user_id' | |
WHERE student_id = \"$student_id\""; | |
mysql_query($selectResult); | |
} | |
} | |
} | |
//////////DELETE//////////////////////////////////// | |
function removeStudent($id){ | |
echo "$id"; | |
$hostName='157.201.194.254'; | |
$userName = "jdoggett"; | |
$password = ''; | |
$id = $_REQUEST['id']; | |
if(!($db = mysql_connect($hostName, $userName, $password))) | |
{ | |
print"<br> Can't connect"; | |
} | |
$database = 'jdoggett'; | |
if(!(mysql_select_db($database))) | |
{ | |
print "Error could not select database"; | |
} | |
else | |
{ | |
$selectResult = "DELETE FROM students WHERE student_id = '$id'"; | |
mysql_query($selectResult); | |
} | |
} | |
//////////////SELECT////////////////////////////// | |
function selectStudent($id){ | |
$hostName='157.201.194.254'; | |
$userName = "jdoggett"; | |
$password = ''; | |
if(!($db = mysql_connect($hostName, $userName, $password))) { | |
print"<br> Can't connect"; | |
} | |
$database = 'jdoggett'; | |
if(!(mysql_select_db($database))) { | |
print "Error could not select database"; | |
} | |
else | |
{ | |
$selectResult = "select * from students where student_id = \"$id\""; | |
$results = mysql_query($selectResult); | |
$rows = mysql_num_rows($results); | |
$student = mysql_fetch_assoc($results); | |
return $student; | |
} | |
} | |
//} | |
?> | |
<script language="JavaScript" type="text/javascript"> | |
var req; | |
function processReqChange() | |
{ | |
if(req.readyState == 4) | |
{ | |
if(req.status == 200) | |
{ | |
var php = req.responseText; | |
document.getElementById('php').innerHTML = php; | |
} | |
else | |
{ | |
alert("there was a problem retrieving the xml data:"+ req.status); | |
} | |
} | |
} | |
function loadxmlDoc(url){ | |
if(window.XMLHttpRequest) | |
{ | |
req = new XMLHttpRequest(); | |
} | |
else if(window.ActiveXObject) | |
{ | |
req = new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
if (req != null) | |
{ | |
req.onreadystatechange = processReqChange; | |
req.open("GET", url, true); | |
// var query = "query=?"; | |
// query = query + 'SELECT * FROM student'; | |
// console.log(query); | |
// req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
// req.setRequestHeader("Content-length", query.length); | |
req.send(); | |
} | |
else | |
{ | |
alert("browser doesn't support XMLHTTP"); | |
} | |
} | |
function getFile(){ | |
loadxmlDoc("teacher_students.php"); | |
} | |
</script> | |
<?php | |
print '<pre>'; | |
print_r($_REQUEST); | |
print '</pre>'; | |
echo "hello"; | |
echo $_SESSION['user']; | |
?> | |
<form action="teacher.php?action=store" method="POST" class="well"> | |
<input type="hidden" name="studentId" value="<?php echo $student['student_id']; ?>"/> | |
<div id="first">First Name <input class="span3" type="text" name="firstName" value="<?php echo $student['first_name']; ?>" /></div> | |
<div id="last">Last Name <input class="span3" type="text" name="lastName" value="<?php echo $student['last_name']; ?>" /></div> | |
<div>Skill Level</div> | |
<select name="level_id"> | |
<option value="1">Beginner</option> | |
<option value="2">Intermediate</option> | |
<option value="3">Pre-Advanced</option> | |
<option value="4">Advanced</option> | |
<option value="5">Junior Concerto</option> | |
<option value="6">Senior Concerto</option> | |
</select> | |
<div>Type</div> | |
<select name="type_id"> | |
<option value="1">Concerto</option> | |
<option value="2">Two-Piano Duets</option> | |
<option value="3">Duet</option> | |
<option value="4">Solo</option> | |
</select> | |
<div id="numfest">Number of Festivals<input class="span3" type="text" name="numFestivals" size="10" value="<?php echo $student['num_festivals']; ?>" /></div> | |
<div id="age">Age<input class="3" type="text" name="gender" size="5" value="<?php echo $student['age']; ?>" /></div> | |
<div id="instrument">Instrument<input class="3" type="text" name="city" size="15" value="<?php echo $student['instrument']; ?>" /></div> | |
<input type="submit" id="submit" class="btn btn-info" name="submit" value="Submit" /> | |
</form> | |
<div id="php"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns = "http:///www.w3.org/1999/xhtml"> | |
<head> | |
<title>Database Querying | |
</title> | |
<link rel="stylesheet" href="bootstrap-responsive.css" type="text/css" media="screen" /> | |
<link rel="stylesheet" href="bootstrap.css" type="text/css" media="screen" /> | |
</head> | |
<body> | |
</body> | |
</html> | |
<?php | |
$hostName='157.201.194.254'; | |
$userName = "jdoggett"; | |
$password = ''; | |
/////////////////////////////////////////////////////////////// | |
if(!($db = mysql_connect($hostName, $userName, $password))) { | |
print"<br> Can't connect"; | |
} | |
else | |
{ | |
} | |
$database = 'jdoggett'; | |
if(!(mysql_select_db($database))) { | |
print "Error could not select database"; | |
} | |
else | |
{ | |
/////////////////////////////////////////// | |
$level = 'SELECT level_id from students where user_id = 1'; | |
$levels = mysql_query($level); | |
$level_id = mysql_fetch_assoc($levels); | |
$theLevel = $level_id['level_id']; | |
echo $level_id['level_id']. " "; | |
/////////////////////////////////////////// | |
$type = 'SELECT type_id from students where user_id = 1'; | |
$types = mysql_query($type); | |
$type_id = mysql_fetch_assoc($types); | |
$theType = $type_id['type_id']; | |
echo $type_id['type_id']. " "; | |
/////////////////////////////////////////// | |
$query = 'Select * from students s | |
inner join level l on l.level_id = s.level_id | |
inner join type t on s.type_id = t.type_id | |
where user_id = 1'; | |
$result = mysql_query($query); | |
if($result == false) | |
{ | |
$error = mysql_error(); | |
} | |
else | |
{ | |
echo "<table border=1 class='table table-bordered'>"; | |
while($row=mysql_fetch_assoc($result)) | |
{ | |
print "<tr>"; | |
print "<td>" .$row['student_id'] . "</td>"; | |
print "<td>" .$row['first_name']. " </td>"; | |
print "<td>" .$row['last_name']. "</td>"; | |
print "<td>" .$row['level']. "</td>"; | |
print "<td>" .$row['type']. "</td>"; | |
print "<td>" .$row['num_festivals']. "</td>"; | |
print "<td>" .$row['age']. "</td>"; | |
print "<td>" .$row['instrument']. "</td>"; | |
printf('<td> <a href="?action=select&id=%s">Modify</a></td>', $row['student_id']); | |
printf('<td> <a href="?action=delete&id=%s">Delete</a></td>', $row['student_id']); | |
print "</tr>"; | |
} | |
} | |
echo "</table>"; | |
} | |
//////////////////////////////////////////////////////// | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment