apalecka
04-18-2007, 03:02 AM
Hello
I've got customers table and login scripts and what i'm trying to do is to be able to edit customers details, modify them.
I'm using that script but it's not working and it's not displaying any errors just a blank page.
If anywone could give me some advice on what is wrong with it, I'd be very very gratefull!
Thanks!
Michael
<?php
session_start();
if(!session_is_registered(myemail)){
header("location:login.php4");
}
?>
<html><body>
<?php
if($HTTP_SESSION_VARS["myemail"]=='')
{
echo "You are not authorised to view this page. Please login";
echo ("<a href=login.php4>here</a>");
die();
}
else {
$db_link = mysql_connect("xxx", "xxx", "butteph9") or die("can't connect");
mysql_select_db("xxx", $db_link) or die("can't open");
if ($_POST['myemail']) {
$cust = $_POST['myemail'];
if ($_POST['submit']) {
echo "<br>";
$first = $_POST['first'];
$last = $_POST['last'];
$sql_query = "update customers set firstname='$first', lastname='$last' WHERE email='".$_SESSION['myemail']."'";
$result = mysql_query($sql_query);
if(!$result) echo "sorry, $last, $first info not updated <br>";
else
echo "Thank you! Information updated.\n";
}else { // submit is false, query the DB
$sql_query = "SELECT * FROM customers WHERE email='".$_SESSION['myemail']."'";
$result = mysql_query($sql_query); $myrow = mysql_fetch_array($result);
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<input type=hidden name="myemail" value="<?php echo $myrow[myemail] ?>">
First name:<input type="Text" name="first" value="<?php echo $myrow[firstname]?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $myrow[lastname]?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
} //end submit if-else
} else
{ // cust_id and submit do not exist, display list of employees
$result = mysql_query("SELECT * FROM customers", $db_link);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href= '%s?myemail=%s' >%s %s</a><br>\n",
$_SERVER['PHP_SELF'], $myrow[myemail], $myrow[firstname], $myrow[lastname]);
}
}
?>
</body>
</html>
I've got customers table and login scripts and what i'm trying to do is to be able to edit customers details, modify them.
I'm using that script but it's not working and it's not displaying any errors just a blank page.
If anywone could give me some advice on what is wrong with it, I'd be very very gratefull!
Thanks!
Michael
<?php
session_start();
if(!session_is_registered(myemail)){
header("location:login.php4");
}
?>
<html><body>
<?php
if($HTTP_SESSION_VARS["myemail"]=='')
{
echo "You are not authorised to view this page. Please login";
echo ("<a href=login.php4>here</a>");
die();
}
else {
$db_link = mysql_connect("xxx", "xxx", "butteph9") or die("can't connect");
mysql_select_db("xxx", $db_link) or die("can't open");
if ($_POST['myemail']) {
$cust = $_POST['myemail'];
if ($_POST['submit']) {
echo "<br>";
$first = $_POST['first'];
$last = $_POST['last'];
$sql_query = "update customers set firstname='$first', lastname='$last' WHERE email='".$_SESSION['myemail']."'";
$result = mysql_query($sql_query);
if(!$result) echo "sorry, $last, $first info not updated <br>";
else
echo "Thank you! Information updated.\n";
}else { // submit is false, query the DB
$sql_query = "SELECT * FROM customers WHERE email='".$_SESSION['myemail']."'";
$result = mysql_query($sql_query); $myrow = mysql_fetch_array($result);
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<input type=hidden name="myemail" value="<?php echo $myrow[myemail] ?>">
First name:<input type="Text" name="first" value="<?php echo $myrow[firstname]?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $myrow[lastname]?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
} //end submit if-else
} else
{ // cust_id and submit do not exist, display list of employees
$result = mysql_query("SELECT * FROM customers", $db_link);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href= '%s?myemail=%s' >%s %s</a><br>\n",
$_SERVER['PHP_SELF'], $myrow[myemail], $myrow[firstname], $myrow[lastname]);
}
}
?>
</body>
</html>