Jump to content

superted27

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

superted27's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for that. I tried print_r - nothing displayed so I took it out. I don't know what a browser plugin is. I am trying but advice given is rather generic so I can't actually see where I am going wrong. I have looked at a lot of examples. I know many people just post to forums to get an answer and be lazy, but I have spent all week trying to figure this out myself and I am at a loss now as I do not see what I am doing wrong? For instance, am I collecting the cookie at the right point so it stores when the user enters a value? Can I write something which detects a cookie and puts the value back in the text box on this same page? If so, how would I go about doing that?
  2. Hi, Had another re-shuffle around based on what you said, but I don't think its working at all. This is the entire page code nothing before. All I need it to do is store the username which is entered so the next time they visit the page they don't need to enter it again. Anyone be able to tell me or show me where I am going wrong? I am trying to figure this out myself but I am driving blind now :-\ <?php setcookie('userTT',$userName,(time()+60*60*24*30)); //FROM HERE print('<html>'); print('<head><title>'); print('Timetable for'.$userName.'</title>'); print('<style type="text/css">'); print('body,td,th {'); print('color: #FFFFFF;'); print('}'); print('body {'); print(' background-color: #000000;'); print('}'); print('.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}'); print('<link rel="stylesheet" href="style.css">'); print("</head>"); print('<body><br>'); echo "here"; echo $_COOKIE["userTT"]; print('</style><form id="form1" name="form1" method="post" action="">'); print('<label>'); print('<div align="center" class="style1"><strong>My Timetable Search</strong><br />'); print('<br />'); print('Enter Network User ID:<br />'); print('<input type="text" name="txtUserID" id="txtUserID" value=""/>'); print('</div>'); print('<p align="center">'); print('<label>'); print('<input type="submit" name="cmdGo" id="cmdGo" value="Show Timetable"'); print(' </label>'); print(' <br />'); print('</p>'); print('<hr />'); print('</form>'); print('<div align="center">'); $userName = $_POST["txtUserID"]; $hostname = "xxxx"; $dbuser = "xxxxxxr"; $dbpassword = "xxxxx"; $dbname = "xxxxxx"; $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('<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>
  3. Hi again all, I wondered if anyone could help again (sorry). I have one single page which I would like to record a cookie when the user hits submit. The next time the user visits the site, I want it to recall the cookie and put the value in the textbox on the page. I think I have it storing the cookie (not sure though), but I am having trouble getting it to recall in the text box. I wondered if someone could look at this code and see where I am going wrong or help with what I need to add. New to PHP so having trouble getting my head around things. Thanks in advance. <? setcookie('user',$userName,(time()+60*60*24*30) ); ?> <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" value=""/> </div> <p align="center"> <label> <input type="submit" name="cmdGo" id="cmdGo" value="Show Timetable" onclick="setcookie('user',$userName,(time()+60*60*24*30);"/> </label> <br /> </p> <hr /> </form> <div align="center"> <?php $userName = $_POST["txtUserID"]; $hostname = "xxxxx"; $dbuser = "xxxxx"; $dbpassword = "xxxxxx"; $dbname = "xxxxx"; $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>
  4. 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>
×
×
  • 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.