Jump to content

Simple Cookies (which I can't do!)


superted27

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="">
  <label>
  <div align="center" class="style1"><strong>My Timetable Search</strong><br />
    <br />
    Enter Network User ID:<br />
    <input type="text" name="txtUserID" id="txtUserID" />
  </div>
  <p align="center">
    <label>
    <input type="submit" name="cmdGo" id="cmdGo" value="Show Timetable" />
    </label>
    <br />
  </p>
  <hr />
</form>
<div align="center">
  <?php


$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!");

     mysql_select_db($dbname)
     or die("Unable to connect to the database");

        $fields_array=array();
        $num_fields=0;
        $num_row=0;
       

$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
            $result=mysql_query($sql);
            $num_row=mysql_numrows($result);

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

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


            if($num_row >0)
            {
                    //Get number of fields in query
                    $num_fields=mysql_num_fields($result);

         

           # 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);

            $fields_array[]=$meta->name;

           //Display column headers in upper case
       print('<th><b>'.strtoupper($fields_array[$i]).'</b></th>');

                    $i=$i+1;
                    }

            print('</tr>');
                


                   //Get values for each row and column
                while($row=mysql_fetch_row($result))
                {
                 print('<tr>');

			  


					//SET TO 1 TO HIDE USERNAME
                        for($i=1; $i<$num_fields; $i++)
                        {

                        //Display values for each row and column
                        print('<td>'.$row[$i].'</td>');



                        }


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


					//STOP	


                print('</tr>');
                }


    }


		print('</div>');
    ?>
</div>

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.

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