Page 1 of 1

update problem

Posted: Mon Dec 05, 2005 11:07 am
by rami
I was trying to give option to update thier some data for the users(already registered)
what i want to do is display the data of that user in edit page for eg in edit form in name field->eariler name ..current name in database of that user ...in email field of edit form ...current email of database of the user...so on..
if user want to edit then s/he can, other wise ,the same name get entered as it will be displayed and uptouched by the user.
But i have been unable to do this

Code: Select all

if (eregi ("^[[].[[]' , -]{2,30}$", stripslashes(trim($_POST['address'])))) {
$addr = ($_POST['address']);
} else {
$addr = FALSE;
echo '<p><font color="red" size="+1">Please enter your address!</font></p>';
}




if (eregi ("^[[].' -]{2,15}$", stripslashes(trim($_POST['phone'])))) {
$m = ($_POST['phone']);
} else {
$m = FALSE;
echo '<p><font color="red" size="+1">Please enter your phone number!</font></p>';
}


if (!empty($_POST['remarks']))
{
$rm = ($_POST['remarks']);
}
else
{
$rm = '';
}

if ($fn && $addr $m && $rm) {

// Make sure the username is available.
$query = "SELECT teach_id FROM teachers WHERE teach_id='$cb1'";
$result = @mysql_query ($query);

if (mysql_num_rows($result) == 1) { // Available.
"update teachers set name='$fn',address='$addr',phone='$phone',remarks='$rm' where teach_id='$cb1'";
$result = @mysql_query ($query); // Run the query.

if ($result) { // If it ran OK.


echo '<h3><center>Your info has been updated!</center></h3>';

exit();

} else {

echo '<p><font color="red" size="+1">You could not be updated due to a system error. We apologize for any inconvenience.</font></p>';
}

} else { // The username is not available.
echo '<p><font color="red" size="+1">That username is already taken.</font></p>';
}

mysql_close(); // Close the database connection.

} else { // If one of the data tests failed.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}

} // End of the main Submit conditional.
//}
?>

<center><h1>Add Teacher</h1></center>




<table border="1" width="100%" bordercolor="#0000FF" bordercolorlight="#0000FF" bordercolordark="#0000FF">
<tr>
<td width="100%">
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<input type="hidden" name="MAX_FILE_SIZE" value="524288">
<p align="center">&nbsp;&nbsp;&nbsp;&nbsp; <b>Add&nbsp; Teacher</b></p>
<table border="0" width="100%" bgcolor="#EFEFEF">
<tr>
<td width="100%" colspan="3" bgcolor="#00659C">
<p align="center"><b>&nbsp;<font color="#FFFFFF">Enter Teacher's
profile</font></b></td>
</tr>

<tr>
<td width="41%"><b>Address </b></td>
<td width="59%"><input type="text" name="address" size="30" maxlength="30" value="<?
echo "$_SESSION['tname']";
?>" /></td>
</tr>

<td width="41%"><b>Email </b></td>
<td width="59%"><input type="text" name="email" size="30" maxlength="30" value="<?php
require_once ('../mysql_connect1.php');
$query = "SELECT email from teachers where teach_id=$cb1";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
echo "{$row['email']}";
mysql_close();
?>" /></td>
THIRD OPTION I TRIED IT WORKS FINE FOR THE FIRST ONE ie here old email of the database displays but in another filed it gives error SEE BELOW
</tr>
<td width="41%"><b>Phone </b></td>
<td width="59%"><input type="text" name="phone" size="11" maxlength="11" value=""<?php
require_once ('../mysql_connect1.php');
$query = "SELECT email from teachers where teach_id=$cb1";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
echo "{$row['email']}";
mysql_close();
?>" /></td>
IT GIVE ERROR MESSAGE HERE OR WARNRING SAYING
"<br /><b>Warning</b>: mysql_query(): Access denied for user 'ODBC'@'localhost' (using password: NO) in <b>c:\program files\easyphp1-8\www\edit.php</b> on line <b>271</b><br /><br /><b>Warning</b>: mysql_query(): A link to the server could not be established in <b>c:\program files\easyphp1-8\www\edit.php</b> on line <b>271</b><br /><br /><b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>c:\program files\easyphp1-8\www\edit.php</b> on line <b>272</b><br /><br /><b>Warning</b>: mysql_close(): no MySQL-Link resource supplied in <b>c:\program files\easyphp1-8\www\edit.php</b> on line <b>274</b><br />"
WITH IN THAT TEXT BOX
</tr>


Though it is not totally realted to book i have changed the code of chapter number 12 to get the work done
so may be i hope some body can help me as usual.
Thanks for help
If not when changing pass in that chapter number 12 how can we display old password in filed of new password of change password page
please help
thanks