WatsonN Posted September 26, 2010 Share Posted September 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/ Share on other sites More sharing options...
Jocka Posted September 26, 2010 Share Posted September 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115725 Share on other sites More sharing options...
WatsonN Posted September 26, 2010 Author Share Posted September 26, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115759 Share on other sites More sharing options...
kenrbnsn Posted September 26, 2010 Share Posted September 26, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115761 Share on other sites More sharing options...
WatsonN Posted September 26, 2010 Author Share Posted September 26, 2010 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115765 Share on other sites More sharing options...
jcbones Posted September 26, 2010 Share Posted September 26, 2010 Make sure there is no whitespace before the opening PHP tag (<?php) in LOGINS.php Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115766 Share on other sites More sharing options...
WatsonN Posted September 26, 2010 Author Share Posted September 26, 2010 There was but now its gone and the table isn't outputting any data Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115773 Share on other sites More sharing options...
jcbones Posted September 26, 2010 Share Posted September 26, 2010 Is the table headers printing? Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115778 Share on other sites More sharing options...
WatsonN Posted September 26, 2010 Author Share Posted September 26, 2010 They sure are Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115779 Share on other sites More sharing options...
WatsonN Posted September 26, 2010 Author Share Posted September 26, 2010 It was displaying the table with the original code but I just want to know how to break each row into its own set of variables Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1115928 Share on other sites More sharing options...
WatsonN Posted September 28, 2010 Author Share Posted September 28, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/214404-mysql-data-into-variables/#findComment-1116901 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.