Database > General Database

updating profile information(mysql database)

(1/1)

suchait:
i am working on a project
in which i need to create a option for  for editing a user's profile.....
but getting error now .....

update.php (script for present the saved data) :

<?php
include('lock.php');


$host="localhost"; // Host name
$username="root"; // Mysql username
$password="*****"; // Mysql password
$db_name="dailynotes"; // Database name
$tbl_name="userinformation2"; // Table name
$user=$login_session;
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];


// Retrieve data from database
$sql="SELECT id,firstname,lastname,username,emailid,password FROM $tbl_name where id='$id' ";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Firstname</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>username</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Password</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="firstname" type="text" id="firstname" value="<? echo $rows['firstname']; ?>"></td>


<td align="center"><input name="lastname" type="text" id="lastname" value="<? echo $rows['lastname']; ?>" size="15"></td>


<td align="center"><input name="username" type="text" id="username" value="<? echo $rows['username']; ?>"></td>


<td><input name="emailid" type="text" id="emailid" value="<? echo $rows['emailid']; ?>" size="15"></td>


<td align="center"><input name="password" type="text" id="password" value="<? echo $rows['password']; ?>"></td>

</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?

// close connection
mysql_close();

?>



second file which performs the update in mysql database

update_ac.php :

<?php

include('lock.php');

$firstname=$_POST['firstname'];

$lastname=$_POST['lastname'];

$username=$_POST['username'];

$email=$_POST['emailid'];

$password=$_POST['password'];



$id=$_GET['id'];



$connection=mysql_connect("localhost","root","****")

or die("unable to connect with database");



$db=mysql_select_db("dailynotes",$connection)

or die("unable to find such database");



if(isset($_REQUEST['submit']))

{



$query="UPDATE userinformation2 SET firstname='$firstname',lastname='$lastname',username='$username',emailid='$email',password='$password' where id='$id' ";


$result=mysql_query($query)

or die("query failed:".mysql_error());


if($result)
{
echo"success";
}

}

?>


check the code ....
help plz....

ErnieAlex:
We probably can help you.  But, what error are you getting and what line is the code stopping at?

Please place code inside of the PHP tags above next time.  It is easier for us to copy the code to our editors that way. 

Let us know the error you are getting.  Thanks...

Navigation

[0] Message Index

Go to full version