php edit data page issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

Code: Select all

$visitor_id = 'visitor_id';
You're setting $visitor_id to a string literal. That can't possibly be right. Should be, well, an ID, no?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

The content of that column is going to be a number, isn't it? You're passing a string value, 'visitor_id', into the query. That should probably be replaced with a value from the user's session or something.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

That's the right idea, yes.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

Can you post the code in question? Sounds like $_SESSION['user_id'] might not be set, which leaves $visitor_id with a null value.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

You're selecting it, so you should be getting it back. Have you checked that $visitor_id is being set? Have you examined what you're getting back from the database?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

ianhaney wrote:is def weird, how can I check to see if the visitor id is being set

Code: Select all

$visitor_id = $_SESSION['user_id'];
var_dump($visitor_id); exit;
You really want some sort of checking that $_SESSION['user_id'] is set before doing anything that depends on it.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

var_dump your rows, too, to see what's coming back from the DB
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

If you don't have visitor_id available via the session, then you're not going to be able to pass it into the query and will need to use what you have. Joining on the users table could work. I don't recall users having a visitor_id foreign key, though. How are the tables related?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

ianhaney wrote:I think the site getting confused, in the users table is a record of 14 when the user(me) signed up and when I went to the second form, it's storing the data from the second form with a visitor_id record of 75
Why?

No, seriously. Why is it designed this way? What is the benefit of this design? Are visitors entirely distinct from users? Could the information not be combined into a single table?
ianhaney wrote:so I think I need the user_id of 14 to correspond with the visitor_id of 75 within the database tables
Yes, you'd need to establish a foreign key relation, so your users table would have a visitor_id column to connect the two. Before proceeding to do that, however, consider my questions above.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

Where are you inserting records into the users table?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

Where. You've got the query defined, but I don't see it being executed anywhere.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

No it's not. You're defining $sql, not executing the query, then overwriting $sql with new values.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

$id is undefined because you're asking for the insert ID of a query that was never run
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php edit data page issue

Post by Celauran »

ianhaney wrote:Notice: Undefined variable: error in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/the-tax-elephants/register.php on line 79
Where have you defined $error?
ianhaney wrote:Warning: Cannot modify header information - headers already sent by (output started at /home/sites/broadwaymediadesigns.co.uk/public_html/sites/the-tax-elephants/register.php:80) in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/the-tax-elephants/functions.php on line 11
I feel like we've discussed this. You cannot send headers after having sent output to the browser. Leave your markup at the bottom of the file. Logic comes first so you can do things like redirect or set headers or whatever.
Post Reply