All,
I have two scripts - common.php and edit.php.
The working is that common.php contains a form that is used initially for registration and later used again so that registered users can edit their information.
edit.php contains the connection to the db to update the form with the current users information.
Here are the scripts:-
// common.php
<?
function show_form(){
echo"
<html>
<head>
<script>
//function checkrequired(which){
//var pass=true
//if (document.images){
//for (i=0;i<which.length;i++){
//var tempobj=which.elements[i]
//if (((tempobj.type=='text'||tempobj.type=='password')&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=='s'&&tempobj.selectedIndex==-1)){
//pass=false
//break
//}
//}
//}
//if (!pass){
//alert('You have not completed all the required information.\r\nPlease complete your entry and then re-submit.')
//return false
//}
//else
//return true
//}
//</script>
</Head>
<title>Welcome! Enter your registration details.</title>
<font face='Arial' size='2'>
<h3><b>Enter your company information.<b></h3>
<body>
<form method='post'action=$PHP_SELF>
<table width='50%' border='0' cellspacing='0' cellpadding='0'>
<div align='left'><font face='Arial' size='2'>
<tr><td>Company Name:</td> <td>
<input type='text' name='company' size=35 value='$_SESSION[company]'><br></td></tr>
<tr><td>Address:</td> <td>
<input type='text' name='address' size=35 value='$_SESSION[address]'><br></td></tr>
<tr><td></td><td>
<input type'text' name='address2' size=35 value='$_SESSION[address2]'><br></td></tr>
<tr><td>County:</td> <td>
<select name=county><option selected>$_SESSION[county]
<option value=Aberdeenshire>Aberdeenshire</option><option value=Anglesey>Anglesey</option><option value=Angus>Angus</option>
<option value=Argyllshire>Argyllshire</option><option value=Avon>Avon</option><option value=Ayrshire>Ayrshire</option>
<option value=Banffshire>Banffshire</option>
</tr>
<tr><td>Post Code:</td> <td>
<input type='text' name='postcode' size=9 value='$_SESSION[postcode]'><br></td></tr>
<tr><td>Phone No.:</td> <td>
<input type='text' name='tel' size=15 value='$_SESSION[tel]'><br></td></tr>
<tr><td>Fax No.:</td> <td>
<input type='text' name='fax' size=15 value='$_SESSION[fax]'><br></td></tr>
<tr><td>Web Site:</td> <td>
<input type='text' name='web' size=25 value='$_SESSION[web]'><br></td></tr>
</table>
<hr>
<font size='4'><b>Enter your contact information.</b></font>
<table width='50%' border='0' cellspacing='0' cellpadding='0'>
<div align='left'><font face='Arial' size='2'>
<tr><td>First Name: </td> <td><input type='text' name='first' size=19 value='$_SESSION[first]'><br></td></tr>
<tr><td>Surname: </td> <td><input type='text' name='surname' size=19 value='$_SESSION[surname]'><br></td></tr>
<tr><td>Position: </td> <td><input type='text' name='position' size=20 value='$_SESSION[position]'><br></td></tr>
<tr><td>Phone No.: </td> <td><input type='text' name='phone' size=15 value='$_SESSION[phone]'><br></td></tr>
<tr><td>Email: </td> <td><input type='text' name='email' size=25 value='$_SESSION[email]'><br></td></tr><br>
</table>
<hr>
<table width='31.5%' border='0' cellspacing='0' cellpadding='0'>
<div align='left'><font face='Arial' size='2'>
<tr><td>User Name: </td> <td><input type='text' name='user' size=19 value='$_SESSION[user]'><br></td></tr>
<tr><td>Password: </td> <td><input type='password' name='pass' size=19 value='$_SESSION[pass]'><br></td></tr>
<tr><td>Confirm Password: </td> <td><input type='password' name='passconf' size=19 value='$_SESSION[pass]'><br></td></tr><br>
</table><hr>
</form>
</body>
</html>";}
?>
Here is the edit.php
<?
session_start();
if (!session_is_registered("SESSION"))
{
header("Location: /error.php");
exit();
}
if ($HTTP_GET_VARS['submit']!="submit"){
$user=$HTTP_SESSION_VARS['SESSION_UNAME']; //define the username from the session name.
$connection=mysql_connect('localhost','root');//connect to the database
mysql_select_db('reseller');//select the database to use
$userdata=mysql_fetch_assoc(mysql_query("select * from user where user ='$user'")); //select the user details from db.
$pass=$userdata['pass'];
$email=$userdata['email'];
$company=$userdata['company'];
$contactdata=mysql_fetch_assoc(mysql_query("select * from contact where email ='$email'"));
$first=$contactdata['first'];
$surname=$contactdata['surname'];
$position=$contactdata['position'];
$phone=$contactdata['phone'];
$companydata=mysql_fetch_assoc(mysql_query("select * from company where company='$company'"));
mysql_close();
$address=$companydata['address'];
$address2=$companydata['address2'];
$county=$companydata['county'];
$postcode=$companydata['postcode'];
$tel=$companydata['tel'];
$fax=$companydata['fax'];
$web=$companydata['web'];
$_SESSION["pass"]=$pass;
$_SESSION["email"]=$email;
$_SESSION["company"]=$company;
$_SESSION["first"]=$first;
$_SESSION["surname"]=$surname;
$_SESSION["position"]=$position;
$_SESSION["phone"]=$phone;
$_SESSION["address"]=$address;
$_SESSION["address2"]=$address2;
$_SESSION["county"]=$county;
$_SESSION["postcode"]=$postcode;
$_SESSION["tel"]=$tel;
$_SESSION["fax"]=$fax;
$_SESSION["web"]=$web;
require("signup.php");
show_form();
echo"<html><form action=$PHP_SELF>
<input type=submit name=submit value=submit></form></html>";
}
else
if ($HTTP_GET_VARS["submit"]=="submit")
{
$_SESSION["company"]=$company;
echo"<html><script>
alert (\"$_SESSION["company"]\")
</script></html>";}
?>[?PHP]
What I need to do, is when the current user makes a change, I need to store that change in the db, overwriting their current record.
How do I do it, can anyone help pls?