...

View Full Version : editing a certain row



jumpman23
02-27-2012, 08:19 PM
ok i'm a little stuck and hopefully someone can help me out. I set up my registration from, which the user gets a password through email and logs into the home screen.

my question is, I have the database setup with id numbers that increment for every user. I have the site remembering the person but how exactly do I have the php code make sure its the person through ID, then when it is correct able to aim at a certain row for that user in sql.

Example: say the user registered a email, but wanted to change his email. How can I set up the php code to find that row and he is able to make the changes.


Thank you!

mlseim
02-27-2012, 08:44 PM
You say the site knows who the user is...
Is that by using a $_SESSION or $_COOKIE?

You aim at the row by doing a query similar to this ...

$id=$_SESSION['id'];
$sql="SELECT * FROM mytable WHERE userid='$id' ";

I'm just making up variable names because we can't see any of your scripts.

It should either find only one of them (id found), or none of them (not found).
If the result contains more than one row, that means you have duplicated id's.

There of course is a lot more scripting to display, select, edit, update ... etc.
but you just asked about how to query using SELECT.



.

jumpman23
02-27-2012, 09:14 PM
heres my code


<div class="container">

<?php
if($_SESSION['id'])
echo '<h1>Hello, '.$_SESSION['usr'].'! You are registered and logged in!</h1>';
else echo '<h1>Please, <a href="demo.php">login</a> and come back later!</h1>';
?>

<?php
$id=$_SESSION['firstname'];
$sql="SELECT firstname FROM tz_memebers WHERE firstname='$firstname' ";
?>

<p>username:<?php echo $_SESSION['usr']; ?> </p>
<p>firstname:<?php echo $_SESSION['firstname'];?> </p>p </p>
<p>email: </p><?php echo $_SESSION['email'];?> </p>p
<p>location: </p>
</div>


the problem is it retrieves the "username" but i cant seem to retrieve any of the other rows such as "name" and so on.

mlseim
02-28-2012, 01:39 AM
oooo...
you're not even close.

You might want to find some free tutorials by searching Google.
It looks like you may have several things wrong ... but this will get you going in the right direction.




<div class="container">

<?php
if($_SESSION['id'])
echo '<h1>Hello, '.$_SESSION['usr'].'! You are registered and logged in!</h1>';
else echo '<h1>Please, <a href="demo.php">login</a> and come back later!</h1>';

// It looks like a possible mix-up with SESSION variables ...
// as though you are thinking $_SESSION is related to MySQL query.
// I guess I'm not sure what you're doing here.

$id=$_SESSION['firstname'];
$sql="SELECT firstname FROM tz_memebers WHERE firstname='$firstname' ";
$result=mysql_query($sql)

// Is this spelled correctly? tz_memebers
// because "memebers" is spelled "members".

// I'm not sure of your MySQL column names, but you have to do the query first,
// and then display the results ... in your case, there should only be one row.

while ($row = mysql_fetch_assoc($result)) {
?>

<p>username:<?php echo $row['usr']; ?> </p>
<p>firstname:<?php echo $row['firstname'];?> </p>p </p>
<p>email: </p><?php echo $row['email'];?> </p>p
<p>location: </p>
</div>

<?php
}
?>

jumpman23
02-28-2012, 04:02 AM
To better clarify my question, what I'm trying to do is from my sql database, I'm looking pretty much make sure the ID integer is the same of the user that is logged in. If so then from that id row im looking to fetch a cetain row such as name, last name.. so on.

thank you for the help it really is appreciated

mlseim
02-28-2012, 12:19 PM
Yep ...
That's what I'm doing in post #4.

You need to connect to DB, query it, and display results.
Show me the script you have so far.

jumpman23
02-28-2012, 05:36 PM
Problem solved. Thank you, what I did was make a few tweeks with ur original top post. I really appreciate your help, you are a life saver to a novice who is trying to learn.! Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum