The code below loads data from my mysql database into the form on the page, the only problem is i have to type the persons name from the database into the code for the data to display in the form,
what code should i use so that when the user logs in, the data from that user- that is stored in the
sql databse is sent to the form and displayed.
I have mentioned before i am not to sharp with
Php, so please dont repley to this thread unless you can provide me a example of code, i want to learn & i am learning, but right now people relpying to my posts leaving comments that dont even display any code or advise related to solving the problem are not helping me solve my problem to be honest.
You will find various threads posted by me on the
php forum page, you will notice that a little bit of code here & there attached to them would fix the problem and my problem and give me the chance to learn & see how i should do the code in the future, but i appear to be asking to much. I no people are here to help am just unsure why i have been struggling to get it, its obvious am trying learn
My
php code with the form:
- PHP: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
-->
</style></head>
<body>
<?php
$con = mysql_connect("localhost","root","longstand1")
or
die('Damn!, its messing up. MYSQL reckons <pre>' . mysql_error() . '</pre>');
mysql_select_db("dblink_system", $con)
or
die ('Oh hell, its real messin up now. MYSQL reckons <pre>' . mysql_error() . '</pre>');
$first_name = 'Joe';
$query = "SELECT * FROM accounts WHERE first_name = '$first_name' LIMIT 1";
$result = mysql_query($query)
or
die ('More mysql errors. MYSQL reckons <pre>' . mysql_error() . '</pre>');
if (!mysql_num_rows($result))
die ('Are you sure your name is in the database');
$details = mysql_fetch_array($result);
mysql_free_result($result);
mysql_close($con);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Accounts</title>
<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
.style1 {
font-family: "Comic Sans MS";
font-size: 24px;
color: #FFFFFF;
}
.style2 {
font-family: Tahoma;
color: #FFFFFF;
}
-->
</style></head>
<body>
<table width="559" height="235" border="5" cellpadding="0" cellspacing="0">
<tr>
<td height="225" valign="top"><form id="form1" name="form1" method="post" action="">
<table width="547" height="220" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="42" height="29"> </td>
<td width="190"> </td>
<td width="315"> </td>
</tr>
<tr>
<td height="66"> </td>
<td><span class="style1">My name is:</span></td>
<td><input type="text" name="first_name" value="<?php echo isset($details['first_name']) ? $details['first_name'] : ''; // check the value is set and write it down?>" />
</tr>
<tr>
<td height="68"> </td>
<td class="style1">My surname Is:</td>
<td><input type="text" name="last_name" value="<?php echo isset($details['last_name']) ? $details['last_name'] : ''; // check the value is set and write it down?>" />
</tr>
<tr>
<td height="19"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="19"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form> </td>
</tr>
</table>
<p class="style2">Accounts Page</p>
</body>
</html>
Its a web design "help" forum, am jus here for help?
Dont no weather you would need it but here is the login form:
- PHP: Select all
<?php require_once('Connections/dblink_system.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['user_name'])) {
$loginUsername=$_POST['user_name'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "account.php";
$MM_redirectLoginFailed = "log_in.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_dblink_system, $dblink_system);
$LoginRS__query=sprintf("SELECT user_name, password FROM accounts WHERE user_name=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $dblink_system) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Login</title>
<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
.style1 {
color: #FFFFFF;
font-family: Tahoma;
}
-->
</style></head>
<body>
<table width="380" height="190" border="5" cellpadding="0" cellspacing="0">
<tr>
<td width="368" valign="top"><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<table width="369" height="178" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="137"><div align="right">Username:</div></th>
<td width="232"><input type="text" name="user_name" id="user_name" /></td>
</tr>
<tr>
<th><div align="right">Password:</div></th>
<td><input type="text" name="password" id="password" /></td>
</tr>
<tr>
<th><div align="right">Forgot Password?</div></th>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
<tr>
<td> </td>
<td><input type="reset" name="button2" id="button2" value="Reset" /></td>
</tr>
</table>
</form> </td>
</tr>
</table>
<p class="style1">Login Form</p>
</body>
</html>
Cheers