aley
aley

Reputation: 1

Display and Edit Form in same page base on user ID

I'm quite new in this PHP programming and already tried looking my issue at this forum but no success.

I have build a simple webform using PHP and stuck when trying to edit form. My form consist of below

  1. register html form - basicallly user fill in the form and hit submit. the form will then go to register.php

  2. Register.php - all the field store at database and I also display the form using the SESSION (not call from database) in this page.

Here is my problem start. At the dispay(register.php) I want allow user to edit his/her information and submit again(which i think use update query base on ID). But I truly don't know how to do this.

Can someone advice me or give some simple code for this so that I can have clearer view?

Upvotes: 0

Views: 1636

Answers (1)

Nickool
Nickool

Reputation: 3702

you also must strip slashes for avoiding Sql injection

In previous pages you must store the username from textbox of login Something like this:

session_start();

$_SESSION['username']=$_POST['input of login txtbox'];

you can just get the condition with user cause you have just one unique user 2 users mustn't have the same user name then just store the username of them in $_SESSION

   $connection=Mysql_connect('server','user','pass');
if(array_key_exists('sub2',$_POST))
{
    if(!$connection)
    {
        echo 'connection is invalid';
    }
    else
    {
            Mysql_select_db('Your DB',$connection);
            $pas=$_POST['pass1'];
                    $username=$_POST['username'];
                    $pas=mysql_escape_string($pas);
                    $username=mysql_escape_string($username);

   $query="update user set user='$username'and pass=password('$pas') where  username='".$_SESSION['username'].";
       //some code
    }

in your form:

    <p><b>User Name:</b><input type="text" name="username" />

    <p><b>Password:</b><input type="password" name="pass1" />
    <input type="submit" name="sub2" value="update"/>

use this site for secure your code

Upvotes: 1

Related Questions