Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying data on screen problem from DB

Status
Not open for further replies.

sanjdhiman

Programmer
Jan 15, 2003
189
GB
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=&quot;100%&quot; cellpadding=&quot;4&quot; cellspacing=&quot;4&quot;>
<tr>
<td colspan=&quot;2&quot; class=&quot;Title&quot;>Change your Personal Details</td>
</tr>
<tr>
<td colspan=&quot;2&quot; class=&quot;Body&quot;>The following fields are changeable, please edit them appropiatly.</td>
</tr>
<tr>
<td colspan=&quot;2&quot; class=&quot;body&quot;><font color=&quot;#FF0000&quot;>PLEASE NOTE: Changing your email address will not change your user login name.</font></td>
</tr>
<?
check_valid_user();
?>

<tr>
<td colspan=&quot;2&quot; class=&quot;body&quot;>Individual Details</td>
</tr>
<?

getcurrentdetails($valid_user);


*/




echo &quot;<form name=\&quot;changepersonal\&quot; id=\&quot;changepersonal\&quot; action=\&quot;confirmchangepersonal.php\&quot; method=\&quot;post\&quot;>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>First Name</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;fname\&quot; maxlength=\&quot;30\&quot; size=\&quot;30\&quot; value= $fname></td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Last Name</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;lname\&quot; maxlength=\&quot;30\&quot; size=\&quot;30\&quot; value =$lname></td>
</tr>&quot;;


echo &quot;<tr>
<td colspan=\&quot;2\&quot; class=\&quot;body\&quot;>Address Details</td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Building / Flat No</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;number\&quot; maxlength=\&quot;30\&quot; size=\&quot;30\&quot; value=$bnumber></td>
</tr>&quot;;

echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Street Name</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;street\&quot; maxlength=\&quot;30\&quot; size=\&quot;30\&quot; value=$sname></td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>City / Town</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><select name=\&quot;citytown\&quot;>
</select></td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>County</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;county\&quot; maxlength=\&quot;30\&quot; size=\&quot;30\&quot; value=$county></td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Post Code</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;postcode\&quot; maxlength=\&quot;15\&quot; size=\&quot;15\&quot; value=$pcode></td>
</tr>&quot;;
echo &quot;<tr>
<td colspan=\&quot;2\&quot; class=\&quot;body\&quot;>Contact Details</td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Home Telephone No</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;telno\&quot; maxlength=\&quot;25\&quot; size=\&quot;25\&quot; value=$htel></td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Work Telephone No</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;workno\&quot; maxlength=\&quot;25\&quot; size=\&quot;25\&quot; value=$wtel></td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Fax No</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;faxno\&quot; maxlength=\&quot;25\&quot; size=\&quot;25\&quot; value=$faxno></td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Email Address</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;faxno\&quot; maxlength=\&quot;30\&quot; size=\&quot;30\&quot; value=$emailadd></td>
</tr>&quot;;

echo &quot;<tr>
<td colspan=\&quot;2\&quot;>&nbsp;</td>
</tr>&quot;;
echo &quot;<tr>
<td colspan=\&quot;2\&quot; align=\&quot;center\&quot;><input type=\&quot;submit\&quot; name=\&quot;changepersonaldetails\&quot; value=\&quot;Change Personal Details\&quot;>
&nbsp;<input type=\&quot;reset\&quot; name=\&quot;clear\&quot; value=\&quot;Reset Details\&quot;></td>
</tr>&quot;;
echo &quot;</form>&quot;;
?>
</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

 
put doublequotes for the value field of the form element.
ie.

echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>First Name</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;fname\&quot; maxlength=\&quot;30\&quot; size=\&quot;30\&quot; value=\&quot;$fname\&quot;></td>
</tr>&quot;;
echo &quot;<tr>
<td width=\&quot;25%\&quot; align=\&quot;right\&quot; class=\&quot;Form\&quot;>Last Name</td>
<td width=\&quot;75%\&quot; align=\&quot;left\&quot;><input type=\&quot;text\&quot; name=\&quot;lname\&quot; maxlength=\&quot;30\&quot; size=\&quot;30\&quot; value=\&quot;$lname\&quot;></td>
</tr> ...

spookie
--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
thank u mate.. that is wat i did thanks once again i have a quick question to do with style sheets....

What i have done or what i plan to do is to allow the users to change certain features of the website, i.e. background bgcolor, foreground fgcolor, font size and maybe a few others. DOnt know wat else i could allow the user to change interms of the way the site looks.

i have set up a simple table to hold this info in mysql. It goes like this:-

UserID
Bgcolor default 0
Fgcolor default 0
FontSize default 0
FontName default 0

They are all set to 0 when the user registers.

So in the style sheet would i have to declare some variables which will hence make the style sheet (css) dynamic.. is that possible or is it not... do u have an easier way to do it.. or is this probably a good way of tackling the problem

regards

and thanks in advance

sanj
 
Sure it is possible. Just change the extension of the file to [tt].php[/tt].

As a side note, you can remove all those return statements from your function. The first one would be the only one to execute, and you're not using the return value anyway. //Daniel
 
hey thanks daniel...

So u think its possible to do the whole user changing attributes on screen quite easily? excellent.. so change my style sheet to a php file then get the variables at the right points .. is it possible if u could give me a quick example of that... that would really help.. me being a beginner at this game.. but php is a really good language... and enjoying it..so muhc more flexible than any other language i hvae used... (i.e. ada) heheh

also i wil ltake out the return bits .. like u said i aint using them.. just setting them in the function right..

thanks for ur help

sanj
 
Not knowing anything about your tables or such, this piece of code assumes you have a table called [tt]styles[/tt] setup in a way similar to this:
[tt]CREATE TABLE styles (
userid int PRIMARY KEY,
bgcolor varchar(6),
textcolor varchar(6)
);[/tt]
and that you store the current user's ID in the session variable in [tt]$_SESSION['uid'][/tt].

[tt]<?php
session_start();
header('Content-type: text/css');
$dbh = mysql_connect(&quot;localhost&quot;, &quot;username&quot;, &quot;password&quot;) or die(&quot;Couldn't connect&quot;);
mysql_select_db(&quot;database&quot;) or die(&quot;Couldn't select database&quot;);
$result = mysql_query(&quot;SELECT * FROM styles WHERE userid = '&quot; . $_SESSION['uid'] . &quot;'&quot;) or die(&quot;Couldn't query&quot;);
$row = mysql_fetch_assoc($result);
echo &quot;body { background-color: #&quot; . $row['bgcolor'] . &quot;; color: #&quot; . $row['textcolor'] . &quot; }&quot;;
?>[/tt] //Daniel
 
Daniel hey mate thanks so much for your help that sounds like a pretty straight forward thing to do.. i hope i dont mess up hehehe cheers...

And if i have any problems i will defo come and ask you cos u seem to be clued up about php and mySQL

thanks again

will test it all out

sanj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top