Saturday, 15 January 2011

php - How to make the enrollment key not visible again after the student logged out once inputted? -



php - How to make the enrollment key not visible again after the student logged out once inputted? -

basically, want create enrollment key every subject before pupil can enroll in subject. example, pupil logs in in business relationship , want create myself enroll in subject enrollment key , logged out after that. should be, 1 time logged in again, wont input enrollment key 1 time again subject 1 time again because did yet code asking enrolment key of subject everytime click subject. please help me. code:

<?php include_once('connect.php'); session_start(); if(isset($_post['crs_key'])) { $qry = "select * course"; $res = mysqli_query($con, $qry); $found = 0; while ($row = mysqli_fetch_array($res)) { if (($_post['crs_key'] == $row["course_enrollment_key"])) { echo "<script type='text/javascript'> window.location.href='afterkey.php'; settimeout(function () { window.location.href= 'afterkey.php'; },3000); </script>"; $found = 1; $_session['key'] = $row['course_enrollment_key']; } break; } if($found=1) { if(isset($_session['key'])) { echo "<script type='text/javascript'> window.location.href='afterkey.php'; settimeout(function () { window.location.href= 'afterkey.php'; },3000); </script>"; } } else if($found=0) { echo "<script type='text/javascript'> alert('invalid enrollment key!'); window.location.href='key.php'; settimeout(function () { window.location.href= 'key.php'; },3000); </script>"; } } ?> <html> <head> <title> enrollment key </title> </head> <body> <?php if (isset($_session["fname"])) { echo "<h2>welcome ".$_session['fname']."</h2>"; echo "<br /><p align='right'><a href='logout.php'>logout</a></p>"; if (isset($_session['key'])) { echo "header(location:'afterkey.php')"; } else { echo "<form name='enrollmentkey' method='post' action='key.php'> <div> <input type='text' name='crs_key' id='crs_key' placeholder='enrollment key' value=''> <br> <input type='submit' name='enroll' id='enroll' value='enroll'> </div> </form>"; } } ?> </body> </html>

you setting found = 1 within conditional check of $_post['crs_key'] input type. means if value not passed along, script going fail , move else if($found=0).

as can't see how database structured, first need query see if id (for instance) of user exists in registration_table matches course id in question.

this best can come with.

php mysql

No comments:

Post a Comment