Jump to content

mysql data into variables


WatsonN

Recommended Posts

I have a table and the structure is

ID, UID, Site, Uname, Pass

I already have this

<?php

$result = mysql_query(sprintf("SELECT * FROM Logins WHERE UID = %d", $_COOKIE['UID_WatsonN']));
//check login table against cookie
if(($num = mysql_num_rows($result)) > 0){
mysql_close();
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th>ID</th>
<th>UID</th>
<th>Site</th>
<th>Uname</th>
<th>Pass</th>
</tr>
<center>
<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"ID");
$f2=mysql_result($result,$i,"UID");
$f3=mysql_result($result,$i,"Site");
$f4=mysql_result($result,$i,"Uname");
$f5=mysql_result($result,$i,"Pass");
?>

<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
</tr>

<?php
$i++;
}
}
?>

 

which only gets the data from that one person. What is in the table is usernames and passwords for diffrent sites and i want to take all the usernames and passwords and put them into variables to pass on to the login form.

Link to comment
Share on other sites

hm i've never done queries like that.. I always have issues when i do the damn > < signs. Usually adding = makes it work for me though. <=

 

why not just do a while statement for the query though.. like this:

 

<?php
while ($row = mysql_fetch_array($result, MYSQL_NUM){
$f1 = $row['ID'];
$f2 = $row['UID'];
$f3 = $row['Site'];
$f4 = $row['Uname'];
$f5 = $row['Pass'];
?>

so on so forth.. same idea here just a different method.

Link to comment
Share on other sites

I changed it to

<?php

$result = mysql_query(sprintf("SELECT * FROM Logins WHERE UID = %d", $_COOKIE['UID_WatsonN']));
//check login table against cookie
if(($num = mysql_num_rows($result)) > 0){
mysql_close();
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th>ID</th>
<th>UID</th>
<th>Site</th>
<th>Uname</th>
<th>Pass</th>
</tr>
<center>
<?php
while ($row = mysql_fetch_array($result, MYSQL_NUM){
$f1 = $row['ID']; //Line 107
$f2 = $row['UID'];
$f3 = $row['Site'];
$f4 = $row['Uname'];
$f5 = $row['Pass'];
?>
<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
</tr>

<?php
}
}
?>

and got the error

Parse error: syntax error, unexpected '{' in /home/content/n/a/t/nathanwatson/html/admin/LOGINS.php on line 107

Link to comment
Share on other sites

You're missing the closing ")" on this line:

<?php
while ($row = mysql_fetch_array($result, MYSQL_NUM){
?>

It should be

<?php
while ($row = mysql_fetch_array($result, MYSQL_NUM)){
?>

 

But that line won't work with the rest of your code, you should be using:

<?php
while ($row = mysql_fetch_assoc($result)){
?>

 

Ken

Link to comment
Share on other sites

I did that and now I get this error

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/n/a/t/nathanwatson/html/admin/LOGINS.php:1) in /home/content/n/a/t/nathanwatson/html/admin/timer.php on line 3

 

This is timer.php

<?php
$error = 'Your session timed out.'; 
session_start();
if($_SESSION['session_count'] == 0) { 
$_SESSION['session_count'] = 1;
$_SESSION['session_start_time']=time();
} else {
$_SESSION['session_count'] = $_SESSION['session_count'] + 1;
}

$session_timeout = 1800;

$session_duration = time() - $_SESSION['session_start_time'];
if ($session_duration > $session_timeout) { 
session_unset();
session_destroy();
session_start();
session_regenerate_id(true);
setcookie("Key_WatsonN", 0, time()-3600);
setcookie("Errors", 0, time()-3600); 
setcookie("UID", 0, time()-3600);
setcookie("PWD", 0, time()-3600);
setcookie(Errors, $error, time()+120000);
$_SESSION["expired"] = "yes";
header("Location: /"); // Redirect to Login Page
} else {
$_SESSION['session_start_time']=time();
}
?>

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.