jazzman
-
Posts
5 -
Joined
-
Last visited
Never
Posts posted by jazzman
-
-
Can someone please direct me to an explanation of how this can be done?
-
Hi all!
I want to build a form in which there will be a button that allows to add an input field every time it is pressed. Can somebody please help me accomplish this? ???
-
Thanks for the quick replies...
I tried moving the doctype decleration to the bottom of the page but this didn't seem to work. Even removing it from the page still didn't have any effect.
Regarding the ob_ functions... I tried putting ob_start(); at the first line after <?php and ob_end_flush(); before ?> but this still didn't have any effect on the results. Perhaps you could explain more specificly how I am supposed to alter the code... -
Hi!
I am running an Apache server on CentOS. My main page is in php. It's supposted to be a user sign-up page for teachers and students that want to access information found in the MySQL database on my server. I decided to use sessions in order to take care of the user verification, but I'm having some problems achieving the results I want.
Here is the page code (don't notice the styling since it's using css):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<?php
//start session of a year
session_save_path("sessions");
ini_set("session.cookie_lifetime",time()+60*60*24*365);
session_start();
setcookie(session_name(), session_id(), time()+60*60*24*365, "/");
$input_id_student = $_POST['id_student'];
$input_id_teacher = $_POST['id_teacher'];
$input_pass = $_POST['pass'];
$student = 0;
$teacher = 0;
$connection = mysql_connect("localhost", "", "") or die (mysql_error());
mysql_select_db("tagma_ora", $connection) or die (mysql_error());
mysql_query("SET character_set_results=utf8");
//check if the id is of a student
$result = mysql_query("SELECT id FROM students", $connection);
$num_rows = mysql_num_rows($result);
for($i=0;$i<$num_rows;$i++)
{
$result_id[$i] = mysql_result($result,$i,"id");
if ($result_id[$i] == $input_id_student)
{
$student = 1;
$result2 = mysql_query("SELECT first_name, last_name, birth_date, stream, grade, class FROM students WHERE id='$input_id_student'");
$first_name = mysql_result($result2,0,"first_name");
$last_name = mysql_result($result2,0,"last_name");
$birth_date = mysql_result($result2,0,"birth_date");
$birth_date2 = strtotime($birth_date);
$birth_date3 = date('d/m/Y', $birth_date2);
$stream = mysql_result($result2,0,"stream");
$grade = mysql_result($result2,0,"grade");
$class = mysql_result($result2,0,"class");
}
}
//check if the id is of a teacher
$result = mysql_query("SELECT id FROM teachers", $connection);
$num_rows = mysql_num_rows($result);
for($i=0;$i<$num_rows;$i++)
{
$result_id[$i] = mysql_result($result,$i,"id");
if ($result_id[$i] == $input_id_teacher)
{
$teacher = 1;
$result2 = mysql_query("SELECT first_name, last_name, password FROM teachers WHERE id='$input_id_teacher'");
$first_name = mysql_result($result2,0,"first_name");
$last_name = mysql_result($result2,0,"last_name");
$result_password = crypt(mysql_result($result2,0,"password"));
}
}
if (strlen($input_id_student) == 0 && strlen($input_id_teacher) == 0 && strlen($input_pass) == 0)
$_SESSION['type'] = "none";
else if ($student == 1)
$_SESSION['type'] = "student";
else if ($teacher == 1 && crypt($input_pass, $result_password) == $result_password)
$_SESSION['type'] = "teacher";
else if ($teacher == 1 && crypt($input_pass, $result_password) != $result_password)
$_SESSION['type'] = "wrong_password";
else if (!isset($_SESSION['type']))
$_SESSION['type'] = "none";
else
$_SESSION['type'] = "not_in_list";
?>
<html lang="en" dir="ltr">
<head>
<title>Tagma Ora</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" href="tagma_ora.png" type="image/x-icon">
</head>
<body>
<a href="index.php"><img src="tagma_ora.png"></a>
<div id="div1">
<ul>
<li><a href="index.php">Main Menu</a></li>
<?php
if ($_SESSION['type'] == "student" || $_SESSION['type'] == "teacher")
echo '<li><a href="exit.php">exit</a></li>'
?>
</ul>
</div>
<div id="dev2"><a href="index.php">Main Menu</a><hr width="98%">
<?php
if ($_SESSION['type'] == "student")
echo $first_name . ' ' . $last_name . '<br>Details:<br>Birth Date:' . $birth_date3 . '<br>Stream' . $stream . '<br>Class' . $grade2 . ' ' . $class;
else if ($_SESSION['type'] == "teacher")
echo 'Welcome teacher ' . $first_name . ' ' . $last_name;
else if ($_SESSION['type'] == "wrong_password")
echo 'Wrong passoword';
else if ($_SESSION['type'] == "none")
{
echo '
<span class="header">Welcome to your school database!</span><br>
<br>
<span class="emphasize">Students:</span><br>
<form action="index.php" method="post">ID: <input name="id_student" type="text" maxlength="9"><br>
<input type="submit" value="OK">
<br><br>
<span class="emphasize">Teachers</span><br>
<table rows="2" cols="2">
<tr><td>ID: </td><td><input name="id_teacher" type="text" maxlength="9"><br></tr>
<tr><td>Password: </td><td><input name="pass" type="password"></td></tr></table><br><br>
<input type="submit" value="OK">
</form>';
}
else
echo 'You are not in the database...';
?>
</div>
</body>
</html>
[b]Now here's the precise problem[/b]:
Whenever I sign-up as a student/teacher the session works and the page reloads showing "Welcome student...", HOWEVER, when I click on a hyperlink "back" to the main page the session changes back to "none" (meaning it shows the sign-up page).
[b]How do I make the session stay even though I reload the page?[/b]
update select elements
in PHP Coding Help
Posted
Hi all!
I have a mysql table containing a list of grades and classes of a school. Now, I have a form with which one can add a student to a different table with his grade and class being determined according to the grades-classes table. I created two select lists: one for the grade and another for the class. I want that once the user has selected the grade from the first selection list he will be given the appropriate classes in the second selection list according to the mysql table.
Can someone please give me a clue how to do this?