sanjdhiman
Programmer
hi there all i have a quick question for u. Wont take u guys long but i can seem to be able to work it out.
Ok im using PHP mySQL and Apache in the usual way. However, im running a few functions so that i can get data
out of the database and put it into Text Fields (HTML text fields) Below is how i get the data from the DB :
function getcurrentdetails($email)
{
global $fname;
global $lname;
global $bnumber;
global $sname;
global $county;
global $pcode;
global $htel;
global $wtel;
global $faxno;
global $emailadd;
$conn = db_connect();
if (!$conn)
return false; //could not connect to database
$result = mysql_query("SELECT * FROM regusers WHERE Email = \"$email\""
;
$row = mysql_fetch_array($result);
$fname = stripslashes($row["FirstName"]);
$lname = stripslashes($row["LastName"]);
$bnumber =$row["HouseNumber"];
$sname = $row["StreetName"];
//dont forget to enter the CITY TOWN values in as well at some point......
$county = stripslashes($row["County"]);
$pcode = $row["Postcode"];
$htel = $row["HTelephone"];
$wtel = $row["WTelephone"];
$faxno = $row["Fax"];
$emailadd = stripslashes($row["Email"]);
return $fname;
return $lname;
return $bnumber;
return $sname;
//dont forget the cityTown here also
return $county;
return $pcode;
return $htel;
return $wtel;
return $faxno;
return $emailadd;
}
so its based on a global variable $valid_user which is passed into the above function as $email.
Is it a good idea to set all these variables as global, couldnt think of any other way of doing it other than this.
Below is the Form which calls this function
<table width="100%" cellpadding="4" cellspacing="4">
<tr>
<td colspan="2" class="Title">Change your Personal Details</td>
</tr>
<tr>
<td colspan="2" class="Body">The following fields are changeable, please edit them appropiatly.</td>
</tr>
<tr>
<td colspan="2" class="body"><font color="#FF0000">PLEASE NOTE: Changing your email address will not change your user login name.</font></td>
</tr>
<?
check_valid_user();
?>
<tr>
<td colspan="2" class="body">Individual Details</td>
</tr>
<?
getcurrentdetails($valid_user);
*/
echo "<form name=\"changepersonal\" id=\"changepersonal\" action=\"confirmchangepersonal.php\" method=\"post\">";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">First Name</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"fname\" maxlength=\"30\" size=\"30\" value= $fname></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Last Name</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"lname\" maxlength=\"30\" size=\"30\" value =$lname></td>
</tr>";
echo "<tr>
<td colspan=\"2\" class=\"body\">Address Details</td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Building / Flat No</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"number\" maxlength=\"30\" size=\"30\" value=$bnumber></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Street Name</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"street\" maxlength=\"30\" size=\"30\" value=$sname></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">City / Town</td>
<td width=\"75%\" align=\"left\"><select name=\"citytown\">
</select></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">County</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"county\" maxlength=\"30\" size=\"30\" value=$county></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Post Code</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"postcode\" maxlength=\"15\" size=\"15\" value=$pcode></td>
</tr>";
echo "<tr>
<td colspan=\"2\" class=\"body\">Contact Details</td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Home Telephone No</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"telno\" maxlength=\"25\" size=\"25\" value=$htel></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Work Telephone No</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"workno\" maxlength=\"25\" size=\"25\" value=$wtel></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Fax No</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"faxno\" maxlength=\"25\" size=\"25\" value=$faxno></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Email Address</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"faxno\" maxlength=\"30\" size=\"30\" value=$emailadd></td>
</tr>";
echo "<tr>
<td colspan=\"2\"> </td>
</tr>";
echo "<tr>
<td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"changepersonaldetails\" value=\"Change Personal Details\">
<input type=\"reset\" name=\"clear\" value=\"Reset Details\"></td>
</tr>";
echo "</form>";
?>
</table>
When the user edits his or her details in the above form (because they are logged into the system there details are shown in the text fields) i only get the first word that is all, not the whole data, i.e. if i have in the DB humberstone drive I only get Humberstone on the screen ???
can anyone think why that is? what i am doing wrong???
Thanks in advance for your help
sanj
Ok im using PHP mySQL and Apache in the usual way. However, im running a few functions so that i can get data
out of the database and put it into Text Fields (HTML text fields) Below is how i get the data from the DB :
function getcurrentdetails($email)
{
global $fname;
global $lname;
global $bnumber;
global $sname;
global $county;
global $pcode;
global $htel;
global $wtel;
global $faxno;
global $emailadd;
$conn = db_connect();
if (!$conn)
return false; //could not connect to database
$result = mysql_query("SELECT * FROM regusers WHERE Email = \"$email\""
$row = mysql_fetch_array($result);
$fname = stripslashes($row["FirstName"]);
$lname = stripslashes($row["LastName"]);
$bnumber =$row["HouseNumber"];
$sname = $row["StreetName"];
//dont forget to enter the CITY TOWN values in as well at some point......
$county = stripslashes($row["County"]);
$pcode = $row["Postcode"];
$htel = $row["HTelephone"];
$wtel = $row["WTelephone"];
$faxno = $row["Fax"];
$emailadd = stripslashes($row["Email"]);
return $fname;
return $lname;
return $bnumber;
return $sname;
//dont forget the cityTown here also
return $county;
return $pcode;
return $htel;
return $wtel;
return $faxno;
return $emailadd;
}
so its based on a global variable $valid_user which is passed into the above function as $email.
Is it a good idea to set all these variables as global, couldnt think of any other way of doing it other than this.
Below is the Form which calls this function
<table width="100%" cellpadding="4" cellspacing="4">
<tr>
<td colspan="2" class="Title">Change your Personal Details</td>
</tr>
<tr>
<td colspan="2" class="Body">The following fields are changeable, please edit them appropiatly.</td>
</tr>
<tr>
<td colspan="2" class="body"><font color="#FF0000">PLEASE NOTE: Changing your email address will not change your user login name.</font></td>
</tr>
<?
check_valid_user();
?>
<tr>
<td colspan="2" class="body">Individual Details</td>
</tr>
<?
getcurrentdetails($valid_user);
*/
echo "<form name=\"changepersonal\" id=\"changepersonal\" action=\"confirmchangepersonal.php\" method=\"post\">";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">First Name</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"fname\" maxlength=\"30\" size=\"30\" value= $fname></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Last Name</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"lname\" maxlength=\"30\" size=\"30\" value =$lname></td>
</tr>";
echo "<tr>
<td colspan=\"2\" class=\"body\">Address Details</td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Building / Flat No</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"number\" maxlength=\"30\" size=\"30\" value=$bnumber></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Street Name</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"street\" maxlength=\"30\" size=\"30\" value=$sname></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">City / Town</td>
<td width=\"75%\" align=\"left\"><select name=\"citytown\">
</select></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">County</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"county\" maxlength=\"30\" size=\"30\" value=$county></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Post Code</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"postcode\" maxlength=\"15\" size=\"15\" value=$pcode></td>
</tr>";
echo "<tr>
<td colspan=\"2\" class=\"body\">Contact Details</td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Home Telephone No</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"telno\" maxlength=\"25\" size=\"25\" value=$htel></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Work Telephone No</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"workno\" maxlength=\"25\" size=\"25\" value=$wtel></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Fax No</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"faxno\" maxlength=\"25\" size=\"25\" value=$faxno></td>
</tr>";
echo "<tr>
<td width=\"25%\" align=\"right\" class=\"Form\">Email Address</td>
<td width=\"75%\" align=\"left\"><input type=\"text\" name=\"faxno\" maxlength=\"30\" size=\"30\" value=$emailadd></td>
</tr>";
echo "<tr>
<td colspan=\"2\"> </td>
</tr>";
echo "<tr>
<td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"changepersonaldetails\" value=\"Change Personal Details\">
<input type=\"reset\" name=\"clear\" value=\"Reset Details\"></td>
</tr>";
echo "</form>";
?>
</table>
When the user edits his or her details in the above form (because they are logged into the system there details are shown in the text fields) i only get the first word that is all, not the whole data, i.e. if i have in the DB humberstone drive I only get Humberstone on the screen ???
can anyone think why that is? what i am doing wrong???
Thanks in advance for your help
sanj