View Full Version : calling all php and mysql guru's
Ive been searching for a day now and im going to cry soon.
I am to make a project a dummy website e-commerce website. So security and all the other things are not so important, just need things to be bland and plain but most importantly to work!
Ive got a mysql db set up, and my users can log in and log out thats working.
Now here is the problem. Once that particular user logs in i want him/her to be able to view the details stored on the db about them, i.e. their firstname, surname, email etc
Ive been trying so many methods but none seem to work or some are giving me blank results. If somebody can help me with this, it would be much appreciated.
Dismounted
04-09-2007, 06:16 AM
Is this using your own backend or vBulletin's? (I'm guessing your own) You will need to query the database for the user's row and output the information.
$result = mysql_query("SELECT * FROM `YOURUSERTABLE` WHERE `userid` = " . $YOURUSERIDVARIABLE . " LIMIT 1");
$row = mysql_fetch_assoc($result);
Then all your information would be in $row. To access it's data, simply use $row['FIELD'] (where FIELD is the name of the required field).
This is the test data in my contacts table as you can see: http://www.photo-host.org/img/958319table.jpg
ive inserted this, is this correct?:
$result = mysql_query("SELECT * FROM 'contacts' WHERE 'member_id' = " . $member_id . " LIMIT 1");
$row = mysql_fetch_assoc($result);
contacts is the table and member_id is the member id which auto increments as a new user registers.
I can login in fine with this error on top:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in e:\webareas\am663\carttest\login.php on line 8
EDIT: I added the "@" in front of mysql_fetch_assoc($result); which seemed to have removed the error message but when i call the data from the db e.g. echo $row['$member_id'];
echo $row['$username']; nothing shows up on my members page?
Adrian Schneider
04-09-2007, 07:22 PM
$result = mysql_query("
SELECT *
FROM contacts
WHERE member_id = $member_id
") or die(mysql_error());
$row = mysql_fetch_assoc($result);
$result = mysql_query("
SELECT *
FROM contacts
WHERE member_id = $member_id
") or die(mysql_erorr());
$row = mysql_fetch_assoc($result);[/code]
you have a typo i quickly fixed it, is it suppose to be in 6 lines? as i reduce it to 1 line the colour changes... but i still followed your example and it said:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3" ?? Im on my university server, do i upload a phpinfo file to find out?
Adrian Schneider
04-09-2007, 08:25 PM
What is the $member_id value set to? I'm assuming it's an integer... right?
What is the $member_id value set to? I'm assuming it's an integer... right?
look here: http://www.photo-host.org/img/958319table.jpg member id is an auto increment integer.
CREATE TABLE contacts (
member_id int(30) NOT NULL auto_increment,
firstname varchar(30) NOT NULL default '',
surname VARCHAR(30) NOT NULL default '',
contact_no INT(11),
housename_no VARCHAR(20),
address_line1 VARCHAR(20),
address_line2 VARCHAR(20),
address_line3 VARCHAR(20),
city_county VARCHAR(15),
postcode VARCHAR(8),
email varchar(30) NOT NULL default '',
username varchar(25) NOT NULL default '',
password varchar(255) NOT NULL default '',
PRIMARY KEY (member_id),
UNIQUE KEY username (username)
) TYPE=MyISAM COMMENT='Members';
Adrian Schneider
04-09-2007, 09:15 PM
In your query you use $member_id ... what is the value of that?
In your query you use $member_id ... what is the value of that?
What do you mean? the value in the sql table or in the php code?
Adrian Schneider
04-09-2007, 09:31 PM
The PHP variable... if its empty (and I'm pretty sure it is) the query will die because:
SELECT * FROM TABLE WHERE id = ;
Is not valid.
The PHP variable... if its empty (and I'm pretty sure it is) the query will die because:
SELECT * FROM TABLE WHERE id = ;
Is not valid.
Ohh ok, no its not empty it has:
$result = mysql_query("
SELECT *
FROM contacts
WHERE member_id = $member_id
") or die(mysql_error());
$row = mysql_fetch_assoc($result);
please check with this: http://www.photo-host.org/img/958319table.jpg did i do it right?
$strsql="SELECT email, firstname, surname, address_line1, ".
"address_line2, city_county, postcode FROM ".
"contacts WHERE id = '$member_id'";
Dismounted
04-10-2007, 04:50 AM
Is $member_id populated? Does it have the id in it?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.