Jump to content

Echo from database to input text


princeofpersia

Recommended Posts

Hi guys

 

I have created a profile page where users can update their profile.

 

what I need to do is to echo back the users details in the inout text

 

I have name and telephone number

 

any ideas how to do it? here is my code

 

<?php

session_start();

include ("global.php");

 

 

//username session

$_SESSION['username']=='$username';

$username=$_SESSION['username'];

 

 

//welcome messaage

echo "Welcome, " .$_SESSION['username']."!<p>";

 

  if ($_POST['register'])

    {

    //get form data

    $name = addslashes(strip_tags($_POST['name']));

    $telephonenumber = addslashes(strip_tags($_POST['telephonenumber']));

 

 

 

 

$query = "UPDATE  users  SET name = ' $name' WHERE username='$username'";

$result = mysql_query($query);

 

$query = "UPDATE  users  SET telephonenumber = ' $telephonenumber' WHERE username='$username'";

$result = mysql_query($query);

 

 

 

}

 

 

?>

 

    <form action='updateprofile.php' method='POST'>

    Company Name:<br />

    <input type='text' name='name'><p />

    <input type='text' name='telephonenumber'><p />

 

    <input type='submit' name='register' value='Register'>

    </form>

 

 

_______

 

the reason i want to do this is because when user is updating the name field the empty input text for telephone number ovverides the telephone number field in the database.

 

I would aprreciate your help guys,

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/219107-echo-from-database-to-input-text/
Share on other sites

after the registration conditional:

$query = "SELECT name,   users WHERE username='$username'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

 

and your html:

    <input type='text' name='name' value='<?php echo $row['name']; ?>'><p />
     <input type='text' name='telephonenumber' value='<?php echo $row['telephonenumber']; ?>'><p />

 

Some points to note:

1. You don't have to do 2 update commands, they can be combined "SET name = '$name', telephonenumber='$telephonenumber'" etc

2. The following lines don't make sense:

//username session
$_SESSION['username']=='$username';
$username=$_SESSION['username'];

== checks for equality

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.