Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    editing a certain row

    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!

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,374
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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.



    .

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    heres my code

    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.
    Last edited by jumpman23; 02-27-2012 at 10:00 PM.

  • #4
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,374
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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.

    PHP 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>';

            
    // 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
    }
    ?>
    Last edited by mlseim; 02-28-2012 at 01:42 AM.

  • Users who have thanked mlseim for this post:

    jumpman23 (02-28-2012)

  • #5
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #6
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,374
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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.

  • #7
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.
    Last edited by jumpman23; 02-28-2012 at 06:03 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •