6 Replies - 1707 Views - Last Post: 29 July 2008 - 03:42 PM Rate Topic: -----

#1 cbgfilms   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 14-July 08

Displaying Database Data In Form Fields.

Posted 29 July 2008 - 12:40 PM

Hi I am a complete begginer at using PHP and MySQL and I really struggled making a login system, so please explain stuff to me step by step, Thanks.

Basically I want to create a form where users to my website can do the following.
  • Login with their username and password
  • Proceed to the 'My Account' Page
  • There is a form where their signup information is displayed in fields
  • They can make any nessisary edits and changes to their information
  • They click submit, and the information is automatically changed in the database

If anyone could assist me that would be great, or a nessisary tutorial would help greatly, thanks. Charlie.

Is This A Good Question/Topic? 0
  • +

Replies To: Displaying Database Data In Form Fields.

#2 JBrace1990   User is offline

  • D.I.C Addict
  • member icon

Reputation: 112
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Displaying Database Data In Form Fields.

Posted 29 July 2008 - 01:17 PM

usually we ask for code, but in this case i'll give it, because it's one of those things that you wouldn't know where to start with...

<?php
$sql = mysql_query("SELECT * FROM table WHERE x='x'")or die(mysql_error());
$row = mysql_fetch_array($sql);



after you get that and store it in a variable, $row in this case, just set the value of the form to <?php echo $row['email']; ?>
Was This Post Helpful? 0
  • +
  • -

#3 cbgfilms   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 14-July 08

Re: Displaying Database Data In Form Fields.

Posted 29 July 2008 - 01:58 PM

View PostJBrace1990, on 29 Jul, 2008 - 01:17 PM, said:

usually we ask for code, but in this case i'll give it, because it's one of those things that you wouldn't know where to start with...

<?php
$sql = mysql_query("SELECT * FROM table WHERE x='x'")or die(mysql_error());
$row = mysql_fetch_array($sql);



after you get that and store it in a variable, $row in this case, just set the value of the form to <?php echo $row['email']; ?>

Thanks for that, it seems quite simple. But I don't understand how the script would know what database to connect to and the password and stuff.
Was This Post Helpful? 0
  • +
  • -

#4 JBrace1990   User is offline

  • D.I.C Addict
  • member icon

Reputation: 112
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Displaying Database Data In Form Fields.

Posted 29 July 2008 - 02:50 PM

you have to add that in.... >_>

I figured you'd understand that is what was needed =/
Was This Post Helpful? 0
  • +
  • -

#5 cbgfilms   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 14-July 08

Re: Displaying Database Data In Form Fields.

Posted 29 July 2008 - 03:06 PM

View PostJBrace1990, on 29 Jul, 2008 - 02:50 PM, said:

you have to add that in.... >_>

I figured you'd understand that is what was needed =/


Not really, would this be right? I found it on another of my pages :blink:

<?php
$host="sql207.byethost17.com"; // Host name
$username="b17_2102460"; // Mysql username
$password="CENSORED"; // Mysql password
$db_name="b17_2102460_members"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>

Was This Post Helpful? 0
  • +
  • -

#6 JBrace1990   User is offline

  • D.I.C Addict
  • member icon

Reputation: 112
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Displaying Database Data In Form Fields.

Posted 29 July 2008 - 03:37 PM

yes, that's one way to do it =p
Was This Post Helpful? 0
  • +
  • -

#7 cbgfilms   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 14-July 08

Re: Displaying Database Data In Form Fields.

Posted 29 July 2008 - 03:42 PM

View PostJBrace1990, on 29 Jul, 2008 - 03:37 PM, said:

yes, that's one way to do it =p


Ok, sadly I'm now having a few problems :-(

Goto www.europeanteens.byethost17.com
Click on 'Members' in the navigation
Login with
john1 as the username
1234 as the password
proceed to the my account page
look at the problem.

Below is the code for that page *UPDATED*:

<?
session_start();
if(!session_is_registered(myusername)){
header("location:notloggedin.php");
}
?>

<?php
$host="sql207.byethost17.com"; // Host name
$username="b17_2102460"; // Mysql username
$password="CENSORED"; // Mysql password
$db_name="b17_2102460_members"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql = mysql_query("SELECT * FROM members WHERE x='x'")or die(mysql_error());
$row = mysql_fetch_array($sql);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Account</title>
<style type="text/css">
<!--
.style40 {
	font-size: 24px;
	font-family: Geneva, Arial, Helvetica, sans-serif;
	color: #EEC310;
}
.style43 {font-size: 14px}
.style44 {color: #EEC310}
.style47 {
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style48 {color: #EEC310; font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 14px; }
-->
</style>
</head>

<body>
<table width="751" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
	<th width="752" height="196" background="banner.png" scope="row"><p>&nbsp;</p></th>
  </tr>
  <tr>
	<th height="35" valign="top" scope="row"><img src="navigation_exclusive.png" alt="exclusive navbar" width="752" height="35" border="0" usemap="#Map" /></th>
  </tr>
  <tr>
	<th height="196" valign="top" background="wrapper.png" scope="row"><table width="748" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<th width="12" scope="col">&nbsp;</th>
		<th width="720" align="center" valign="top" scope="col"><p class="style40">My Account<br />
			<span class="style43">Hello <?php echo $_SESSION['myusername']; ?> below enter your existing username and password, and then fill in any required details that you would like changed. Please allow upto 48hrs for the change to be made.</span></p>
		  <table width="393" height="269" border="8" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
			<tr>
			  <td width="375" height="253" bgcolor="#0033CC"><script src="http://jotform.com/js/form.js?v2.0.727" type="text/javascript"></script>
<style type="text/css">html,body{height:100%; margin:0;}
.tbmain{ 
 /* Changes on the form */
 background: white !important; 
}
.left{
  /* Changes on the form */
  color: black !important; 
  font-family: Verdana !important;
  font-size: 12px !important;
}
.head{
  color:#333333;
  font-size:20px;;
  text-decoration:underline;
  font-family:"Verdana";
}
td.left {
  font-family:"Verdana";
  font-size:12px;
  color:black;
}
.pagebreak{
  font-family:"Verdana";
  font-size:12px;
  color:black;
}
.tbmain{
  height:100%;
  background:white;
}
span.required{
  font-size: 13px !important;
  color: red !important;
}

</style> 
</head>
<body>
<table width="100%" cellpadding="2" cellspacing="0" class="tbmain">
<tr><td width="10" height="10" bgcolor="#0033CC" class="topleft">&nbsp;</td>
<td bgcolor="#0033CC" class="topmid">&nbsp;</td>
<td width="10" height="10" bgcolor="#0033CC" class="topright">&nbsp;</td>
  </tr>
<tr>
<td width="10" bgcolor="#0033CC" class="midleft">&nbsp;&nbsp;&nbsp;</td>
<td valign="top" bgcolor="#0033CC" class="midmid">
<form  action="http://jotform.com/submit.php"  method="post" name="q_form_82023709968">
<input type="hidden" name="formID" value="82023709968" />
<div id="main"> 
<table width="520" cellpadding="5" cellspacing="0">
 <tr >
   <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
	 <label >Current Username *</label>
   </span> </td>
   <td bgcolor="#0033CC" class="right" >
   <input name="q9_CurrentUsername" type="text" class="text" id="q9"  onblur="validate(this,'Required')" value="<?php echo $row['username']; ?>" size="35"  maxlength="100" maxsize="100" />  </td>
 </tr>
 <tr >
   <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
	 <label >Current Password *</label>
   </span> </td>
   <td bgcolor="#0033CC" class="right" >
   <input type="password" size="35" name="q10_CurrentPassword" class="text" value="" id="q10"  onblur="validate(this,'Required')"  maxlength="100" maxsize="100" />  </td>
 </tr>
 <tr >
  <td colspan="2" bgcolor="#0033CC" class="left style44 style47" >&nbsp;</td>
 </tr>
 <tr >
   <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
	 <label >New Username</label>
   </span> </td>
   <td bgcolor="#0033CC" class="right" >
   <input type="text" size="35" name="q12_NewUsername" class="text" value="" id="q12"  maxlength="100" maxsize="100" />  </td>
 </tr>
 <tr >
   <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
	 <label >New Password</label>
   </span> </td>
   <td bgcolor="#0033CC" class="right" >
   <input type="password" size="35" name="q13_NewPassword" class="text" value="" id="q13"  maxlength="100" maxsize="100" />  </td>
 </tr>
 <tr >
   <td width="150" bgcolor="#0033CC" class="left" ><span class="style48">
	 <label >Email Address</label>
   </span> </td>
   <td bgcolor="#0033CC" class="right" >
   <input type="text" size="35" name="q14_EmailAddress" class="text" value="" id="q14"  onblur="validate(this,'Email')"  maxlength="100" maxsize="100" />  </td>
 </tr>
 <tr >
   <td width="150" valign="top" bgcolor="#0033CC" class="left"  ><span class="style48">
	 <label>Profile</label>
   </span> </td>
   <td bgcolor="#0033CC" class="right" >
   <textarea cols="27" rows="2" name="q15_Profile" class="text" id="q15" ></textarea>  </td>
 </tr>
 <tr >
  <td width="150" bgcolor="#0033CC" class="left" >&nbsp;  </td>
  <td bgcolor="#0033CC" class="right">
  <input type="submit" class="btn" value="Submit" /> </td>
 </tr>
</table>
</div>
</form>
</td>
<td width="10" bgcolor="#0033CC" class="midright">&nbsp;&nbsp;&nbsp;</td>
</tr>
<tr>
 <td width="10" height="10" bgcolor="#0033CC" class="bottomleft">&nbsp;</td>
 <td bgcolor="#0033CC" class="bottommid">&nbsp;</td>
 <td width="10" height="10" bgcolor="#0033CC" class="bottomright">&nbsp;</td>
</tr>
</table>
<script type="text/javascript">
validate("q_form_82023709968");
</script>
&nbsp;</td>
			</tr>
		  </table>		  <p class="style40">&nbsp;</p></th>
		<th width="20" height="210" scope="col">&nbsp;</th>
	  </tr>
	</table></th>
  </tr>
  <tr>
	<th height="25" background="footer.png" scope="row">&nbsp;</th>
  </tr>
</table>
<map name="Map" id="Map">
  <area shape="rect" coords="530,5,594,33" href="logout.php" />
  <area shape="rect" coords="156,8,211,29" href="list_records.php" />
</map>
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1