Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » A Really Easy Php Question
Closed Thread
Old 12-07-2006, 01:26 AM   #1 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Question A Really Easy Php Question

Below is the setup/story, but the question is how do I put in a php variable as the value of a form input?

For the life of me I can't figure out how to put in a hidden form with a PHP value. here is what i want to have work

PHP Code:
<input type="hidden" value="<?php echo $invite?>" name="invite">
which is supposed to hold the value of how many invite codes the user has.

Only problem is, when i go to check the source (and attempt to echo the value), it says "Resource id #5"

So how can i put in $invite as the value?
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
Old 12-07-2006, 04:57 PM   #2 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

Babbage

Default

Well, usually when PHP echo's out something like Resource id #5, it usually means that your variable is some form of handle, instead of a simple scalar variable.

Does invite hold a handle to a file or something?
Babbage is offline  
Old 12-07-2006, 06:29 PM   #3 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default mmmm... cookies

well $invite will usually have a value of 10, which is found by accessing the mysql database. At first i was estatic to find that the variables were hidden in that way because one of my other problems was that if a user changed it they would have more invite codes, but i didn't think it would actually echo Resoruce id #5.

Not sure if it matters, but the method that i am sending the data is POST. This is part of a login page - partially to keep robots out (not googlebot or anything, but "competition" robots), and partially to make things more simple on myself. You put in your info, if it is accepted, you go to a page that has a submit button where you click there, and it POST's the variables, such as $invite.

I'm not completelly sure what a handle is (temp name of a file..?), but it should just be a simple integer variable.
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
Old 12-07-2006, 07:18 PM   #4 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

Babbage

Default

Can you post your code leading up to the use of this variable? It will be much easier to diagnose if you can do that (obviously you can leave out any sensitive information).


Quote:
I'm not completelly sure what a handle is (temp name of a file..?), but it should just be a simple integer variable.
A handle is basically the id given to connect to a specified file. In this case instead of a file, it is given to a database resource.
Babbage is offline  
Old 12-07-2006, 09:05 PM   #5 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default

Before i post this, the things it stores such as "shared" and "downloaded" is NOT a warez type of site... I'm not that stupid

i know its not the most optimized, but im still working on that part

Code:
The problem has been solved and the code has been deleted because i'd rather not post my code all over the place....
So thats all of it, hardly what you may call "optimized", but it works for testing pretty well

Anyways, why can't it echo the $_COOKIE['invitekeys']?
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
Old 12-07-2006, 09:32 PM   #6 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

Babbage

Default

PHP Code:
$invitequery "SELECT invitekeys FROM hsmemberdb WHERE username = '$username' and ******** = '$password'";
$invite mysql_query($invitequery); 
This code is what is giving you the problem. See, when you call mysql_query(), it actually returns a result set, not the result. Its kind of like an array, that is holding your results (even if its only one result).

So, to get the information from your result set that you want, you will want to use one of the functions that php provides for accessing the array of the result set. I have included a link to one such function:

http://us2.php.net/manual/en/functio...etch-assoc.php

Just take a look at example one. At the bottom is a while loop that goes through the result set, and grabs the information.

If you have any problems, just let me know.
Babbage is offline  
Old 12-07-2006, 10:08 PM   #7 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default

thank you!!

That worked perfectly!
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
Old 12-07-2006, 10:15 PM   #8 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

Babbage

Default

Glad it worked for you. Good luck with your website!
Babbage is offline  
Old 12-07-2006, 11:03 PM   #9 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default

alright... this will definatelly be the last issue cause its the last thing i have to sort out... but basically, i can't get authentification to work right or i have some kind of minor error wrong

PHP Code:
updated code below 
The way i put this in my code was using the include(), but i need it to somehow disallow access to those without the cookie stored.
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
Old 12-08-2006, 01:01 AM   #10 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

Babbage

Default

Well, if the person has the cookies on their computer, than information will be passed when you call $_COOKIE['user'] and $_COOKIE['pass'].

So, you can always test to see if those variables are not empty, and if they are redirect them to your signin page with the invalid marker.

PHP Code:
$username $_COOKIE['user'];
$password $_COOKIE['pass'];

if(empty(
$username) || empty($password)){
  
header('Location: ../signin.php?error=invalid');

I'm not sure if this is what you were looking for. If it's not, please correct me.
Babbage is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On