We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
  • 3
PHP Support Topic
Topic Started: Apr 5 2005, 05:42 PM (2,073 Views)
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
can somebody troubleshoot this for me please. The idea is it prints infomation about the user names in the SELECT (which will be dependant on who is logged in. I get a parse error whenever i run the script, annoying because it says the problem is with the ?> tag.

Code:
 

<?
$dbh = mysql_connect($adminhost, $adminname, $adminpass)
or die("Unable to connect to MySQL");
$selected = mysql_select_db($adminname,$dbh)
or die("Could not select database");
$result = mysql_db_query ($adminname,"SELECT * FROM `main` WHERE username = `Kingy`);
$stats1 = mysql_fetch_array ($result));
echo "Hi {.$stats1['username']}.";
echo "You are user number {.$stats1['username']}.";
?>


it is my first try at something like this so i may have a few errors!

thanks seth for the session thing!
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
Try this:

Quote:
 
<?
$dbh = mysql_connect($adminhost, $adminname, $adminpass)
or die("Unable to connect to MySQL");
$selected = mysql_select_db($adminname,$dbh);
or die("Could not select database");
$result = mysql_db_query ($adminname,"SELECT * FROM `main` WHERE username = `Kingy`);
$stats1 = mysql_fetch_array ($result));
echo "Hi {.$stats1['username']}.";
echo "You are user number {.$stats1['username']}.";
?>
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
the "or die" bit should be on that line too but got text wrapped, thats not the problem i am afraid.

thanks anyway
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
You should try wrapping variables in single quotes ('). That may do it.
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
which ones? i always thought double quotes are fine

by the way i got my session thing done! if you want to know how i did it qj feel free to pm me!
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Quote:
 
<?
$dbh = mysql_connect($adminhost, $adminname, $adminpass)
or die("Unable to connect to MySQL");
?>


For some reason I have no idea what the "or die" part does.
(guess that if the mysql_connect doesn't work $dbh becomes "Unable to connect to MySQL" right?)

Quote:
 
echo "Hi {.$stats1['username']}.";

What does this do again :$
(Just can't remember. *Qj feels stupid & n00bish )
Offline Profile Quote Post Goto Top
 
Tom!
Wheeeee
[ * ]
Code:
 

<?
$dbh = mysql_connect($adminhost, $adminname, $adminpass) or die("Unable to connect to MySQL");
$selected = mysql_select_db($adminname,$dbh) or die("Could not select database");
$result = mysql_query("SELECT * FROM `main` WHERE username = `Kingy`");
$stats1 = mysql_fetch_array($result);
echo "Hi {$stats1['username']}.";
echo "You are user number {$stats1['username']}.";
?>


would be valid syntax :luna:
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
thanks Tom!

Qj, "or die" provides an error message for the script, so that it tells you something is wrong rather than just giving a php error.

echo "Hi {$stats1['username']}";

gets the username from the stats1 array

I have it working now everybody thankyou very much!

However, i now have another problem (3 in one day, my bad)

I have a timestamp(14) field to get when a registration is made, this works fine, but what i would like to be able to do is somehow get a script to convert this into hours, so that i could determine how long somebody has been a member in hours. (for a member page)
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Take timestamp @ current moment.
Take timestamp set when user is registered.
Subtract.
Divide by 3600, take floor().
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
Seth you are a genius of the highest order!

thankyou so much!
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
:ermm:

It's all about using the tools you've been given by PHP.
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
indeed...i think the problem i have is that i tend to overcomplicate things, but php often has really simple answers!

anyway thanks again
Offline Profile Quote Post Goto Top
 
dbzlotrfan
Member
[ *  *  *  *  *  *  * ]
few things that I want to know about):

Class(es)
Foreach
Arrays (=>)
defines (define( 'ROOT_PATH', './' );
define( 'KERNEL_PATH', ROOT_PATH.'ips_kernel/' ) ; ) {without the space}


also may some other things that are shown (/seen) in the IPB soruce code (of like admin.php, index.php, (/others)). Thank you.
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
Hey, I need a voting script. I started a topic, but it doesn't seem to be very popular. Here's the link:

http://support.invisionfree.com/index.php?showforum=95

(note) I do not want a poll.
Offline Profile Quote Post Goto Top
 
dbzlotrfan
Member
[ *  *  *  *  *  *  * ]
what is a:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

? I know what the parse error is, I mean the T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING. the line of code that's giving me that is this:
$lang['mod_bansel'] = "Miembros inhabilitados";
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Technology Chat · Next Topic »
Add Reply
  • Pages:
  • 1
  • 3