Jump to content

Simple Cookies (which I can't do!)


Recommended Posts

Hi all, wonder if someone would be able to help. I am a pure beginner but am developing an app which allows students in a school to enter their username and see their timetable.  The php works great and fits fine in my app. I am trying to get it to remember the username which is entered so they do not need to enter it again.  I know I need cookies and have played with no joy.


I wondered if anyone would be able to help get the page to remember their username when entered (no password needed).  Many thanks.


<style type="text/css">
body,td,th {
color: #FFFFFF;
body {
background-color: #000000;
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
</style><form id="form1" name="form1" method="post" action="">
  <div align="center" class="style1"><strong>My Timetable Search</strong><br />
    <br />
    Enter Network User ID:<br />
    <input type="text" name="txtUserID" id="txtUserID" />
  <p align="center">
    <input type="submit" name="cmdGo" id="cmdGo" value="Show Timetable" />
    <br />
  <hr />
<div align="center">

$userName = $_POST["txtUserID"];
$hostname = "localhost";
$dbuser = "xxxxx";
$dbpassword = "xxxxxx!";
$dbname = "xxxxxxx";
$LessonCount = 0;

     $db_link=mysql_connect($hostname, $dbuser, $dbpassword)
     or die("Unable to connect to the server!");

     or die("Unable to connect to the database");


$sql= "SELECT core.UserID, wstt.Period, wstt.Lesson, wstt.Staff, wstt.Room FROM wstt INNER JOIN core ON wstt.Adno = core.Adno WHERE core.UserID='$userName'";


// find position of "FROM" in query
        $fpos=strpos($sql, 'from');

        // get string starting from the first word after "FROM"
        $strfrom=substr($sql, $fpos+5, 50);

        // Find position of the first space after the first word in the string
        $Opos=strpos($strfrom,' ');

        //Get table name. If query pull data from more then one table only first table name will be read.
        $table=substr($strfrom, 0,$Opos);

           // Get result from query

		  print('Timetable for'.$userName.'</title>');
            print('<link rel="stylesheet" href="style.css">');

		print('<h3>Timetable for: '.$userName.'</h3>');
		print('<div align="center"');

            if($num_row >0)
                    //Get number of fields in query


           # get column metadata
            $i = 1;

             //Set table width 10% for each column
            $width=10 * $num_fields;

           // print('<br><table width='.$width.'% align="center" border=1> padding=0<tr>');
		print('<br><table width='.$width.'% border="1" cellpadding="0" cellspacing="0" bordercolor="#000066"<tr>');
            print('<tr><th colspan='.$num_fields.'>Timetable List</th></tr>');

             while ($i < $num_fields)

              //Get fields (columns) names
            $meta = mysql_fetch_field($result);


           //Display column headers in upper case



                   //Get values for each row and column


                        for($i=1; $i<$num_fields; $i++)

                        //Display values for each row and column


					if ($LessonCount ==4) {
						print('<td colspan="4"><div align="center">-----------------------------------------------------</td></tr>');
						}else {
						($LessonCount = $LessonCount+1);





Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.