PHP Question, if you know anything about PHP, and try to help me please [secret answer] [phone num]

Q: Heres the problem, im trying to get to a particular user information. But it does keep the entire script. I can not use a while loop until the very end of the script, or I get a parse error. This is a bit how it looks: $

getuser = @ mysql_query (“SELECT id, username, password, email, secret_question, secret_answer, name, age, gender, address, phone_num, icq, operates from user accounts WHERE username = $ username);

if (! $ getuser) (
echo (“Error performing query:”. mysql_error (). “);
exit ()) else (

while 977 503 ($ row = mysql_fetch_array ($ getuser)) (
if (@ $ row [active] == no) (977 503

and then I close the while loop when Im done. When I have the “$ row [username]” later in the script, i cannot get it! Ive tried using another query, but I would any other form requires.m absolutly clueless of what I could do. How the user, so its fixed throughout the script once someone logs?

I much if statements in my script i dont know whats what. Is there a good php editor with color? thing that could count each bracket with the color?

Thanks for all your help,:)
Carl


Best Answer: In your DB, you need a table counter.
It should have atleast 2 columns, user_id and count

In your code, I have made a few modifications, see if it works for you:

<?php
require_once('connect.php');

$user = trim($_GET['user']);
if(isset($user)) {
$sql = "SELECT count FROM counter WHERE user_id = '$user'";
$re = mysql_query($sql);
echo mysql_errno() . ": " . mysql_error() . "\n";
$r = mysql_fetch_row($re);
$count = $r['count'];

$user = mysql_real_escape_string($user);
if(isset($_GET['points']) && ($_GET['points'] == 'increase' || $_GET['points'] == 'decrease')) {
}
if($_GET['points'] == 'increase') {
$count++;
}
elseif($_GET['points'] == 'decrease') {
$count–;
}
$sql = "UPDATE counter SET count = $count WHERE user_id = '$user'";
mysql_query($sql);
}
$increasePoints = '<a href="?points=increase">Increase</a>';
$decreasePoints = '<a href="?points=decrease">Decrease</a>';

//echo the count and the variables. You can do this on the current page, or any page this code is included in.
echo 'User has ' . $count . ' points!
Do you want to ' . $increasePoints . ' or ' . $decreasePoints . '?
';
?>


Re:<?
session_start(); // start a session
$username = $row[username];
session_register("username"); // register $username as a session variable
?>

to gain access to value stored in $username in other scripts during the same session,

<?
session_start();

echo "The current user is $username";
?>

Session is only available with PHP 4 or newer versions.


Re:How would i use a session?

Re:Use session to store your variables.. that's what it's for.

Re:keep spamming our forums and you will lose your privelage to post here

AnandTech Moderator


Related posts

Leave a comment

0 Comments.

Leave a Reply


click to changeSecurity Code

[ Ctrl + Enter ]