PDA

View Full Version : Updating customers details


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>

Fumigator
04-18-2007, 04:50 PM
You should use $_SESSION rather than the deprecated session_is_registered. Read the cautions and user notes in the manual here (http://us2.php.net/manual/en/function.session-is-registered.php).

What does "view page source" show you?

apalecka
04-18-2007, 10:23 PM
Thank you for replying you my last hope! I have no idea what to do with it...

It didnt change anything. Still the same. I try to add echo...

<?php
session_start();
echo "What the hell?";
if(!session_is_registered(myemail)){
header("location:main_login.php4");
}
?>
<html><body>

so i got error: Parse error: parse error in /users/update_cust_det.php4 on line 54 which is last line, and when i removed it error is still there.

Any ideas whats wrong wit it? Or what sort of code should i use, please?

Thanks a lot for any help!!

JohnDubya
04-18-2007, 10:30 PM
Some suggestions.

if(!session_is_registered(myemail)){

You need single quotes around "myemail." Otherwise, PHP thinks it is a function or whatever.

if(!$result) echo "sorry, $last, $first info not updated <br>";
else
echo "Thank you! Information updated.\n";
}else { // submit is false, query the DB

Not sure if this is your problem, but you need to use curly brackets to keep your code clean and organized. Like so:

if (!$result) {
echo "sorry, $last, $first info not updated <br>";
} else {
echo "Thank you! Information updated.\n";
}

<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">

Instead of writing out php and echo, you can do it the simplified way:

<form method="post" action="<?=$_SERVER['PHP_SELF']?>">

Lastly, it looks like you have two elses going on from the first if() statement. Check that as well. Good luck!

apalecka
04-19-2007, 12:28 AM
O! Cool thats much better - thank you!. Now it is acctually working.

The problem is it doesn't do what i want. I keep getting:

You are not authorised to view this page. Please loginhere

So it seems like my session is dead... but why...

JohnDubya
04-19-2007, 05:15 AM
You need to start using the superglobal $_SESSION instead of the session_is_registered() function. In other words, use this:

if (isset($_SESSION['myemail'])) {
//code here
}