Php Question

This is a discussion on "Php Question" within the PHP Forum section. This forum, and the thread "Php Question are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 20th, 2007, 21:10
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Php Question

I have a form that users input data by selecting options from list menus & entering data into text boxes, the data goes into mysql database.

I then use php code to echo the information from the database onto a profile page, for instance name address email and so on! The problem is that i have to manually type the name of the person who inserted the record (same name as entered into the name column when the record was submit or the record will not display in the profile page).. Below is a code example of what i am talking about, notice the name in the code says MR Andrew Lloyd, and my record will show up from my database into the profile page, if i dont type the name of the person that submit the record then there record will not be displayed in the profile page,

So if i had the website online and all different people were inputting records, what code would i need so the profile page automatically displays that users record when they enter the site, my site does require users to login to use the site, but the signup\ login database is seperate from my profile database. Could anyone give me any suggestions

Cheers.

PHP: Select all

<!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>Untitled Document</title>
</head>
<body>
<?php
$con 
mysql_connect("localhost","root","longstand")
  or
  die(
'Damn!, the crazy guinea pigs must have started nibbling on my computer cords again. MYSQL reckons <pre>' mysql_error() . '</pre>');

mysql_select_db("dblearn"$con)
  or
  die (
'Feckin hell, if it\'s not the guinea pigs then it\'s the gerbils. I shouldn\'t let rodents near the computer. MYSQL reckons <pre>' mysql_error() . '</pre>');
 

$name 'Louise'

$query "SELECT * FROM employees WHERE name = '$name' LIMIT 1"
$result mysql_query($query)
   or
   die (
'I finally got rid of the rodents now the grasshoppers are having a dig. damn. MYSQL reckons <pre>' mysql_error() . '</pre>');
   

if (!
mysql_num_rows($result))
 die (
'Did you lie to me? You said that was your name but nothing matched it in the result. I feel so dirty');

$details mysql_fetch_array($result);
 
mysql_free_result($result);
mysql_close($con);
 
?>
 
<p>My Name Is</p>
<p>
  <label>
  <input type="text" name="name" id="name"value="<?php echo isset($details['name']) ? $details['name'] : ''?>" />
  </label>
</p>
<p>My Email Address Is</p>
<p>
  <label>
  <input type="text" name="email" id="email"value="<?php echo isset($details['email']) ? $details['email'] : ''?>" /><br />
  </label>
</p>
<p>
  <label></label> 
My Phone Number Is</p>
<p>
  <label>
  <input type="text" name="phone" id="phone"value="<?php echo isset($details['phone']) ? $details['phone'] : ''?>" /><br /> 
  </label>
</p>
<p>My Photo's Called</p>
<p>
  <label>
  <input type="text" name="photo" id="photo" value="<?php echo isset($details['photo']) ? $details['photo'] : ''?>" /><br />
  </label>
</p>
<table width="200" height="196" border="0" bordercolor="#FF0099">  
<tr>    <td><img src="images/<?php echo isset($details['photo']) ? $details['photo'] : ''?>" alt="" width="200" height="196"/></td>  </tr></table>
<tr>
    <td>&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
<p>
  <label></label>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; </p>
</body>
</html>

Below is my database

CREATE DATABASE IF NOT EXISTS dblearn;
USE dblearn;
CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo VARCHAR(30))


Thanks
Reply With Quote

  #2 (permalink)  
Old Oct 20th, 2007, 21:49
marSoul's Avatar
Moderator
Join Date: Sep 2007
Location: Tehran - Iran
Age: 28
Posts: 398
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 4 Posts
Send a message via MSN to marSoul Send a message via Yahoo to marSoul
Re: Php Question

How the profile page works ? I mean users should login to system and see their profiles, or everyone can see users profiles ?
One way to do this is to use post or get methods to pass the name and select it from database...
__________________
Designing For Communicating
Website : http://www.datisdesign.com
Weblog : http://blog.datisdesign.com

Last Blog Entry: Throughout IRAN (Dec 10th, 2007)
Reply With Quote
  #3 (permalink)  
Old Oct 20th, 2007, 21:51
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Php Question

Cheers i will try that!!! Thanks 4 the repley
Reply With Quote
  #4 (permalink)  
Old Oct 20th, 2007, 21:53
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Php Question

In your database you need to create a column that is the primary index and give it an auto increment value

CREATE TABLE employees (ID INT NOT NULL AUTO_INCREMENT,name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo VARCHAR(30), PRIMARY_KEY(ID))

Now every time you insert a record the row will get a unique id that you can use to access records. You could pass the records on the $_GET string and re-write the code like

PHP: Select all

$id $_GET['id'

$query "SELECT * FROM employees WHERE ID = '$id LIMIT 1"
$result mysql_query($query

So accessing the page with mypace.com/index.php?id=1 will retrieve the user with the ID of 1
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #5 (permalink)  
Old Oct 21st, 2007, 01:12
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Php Question

Cheers Rakuli!!! Great advise.

I had the feeling that was the problem, see my sign up database users Unique Id so i have decided to run the profile creation page of the same database in a seperate table, instead of the preveious one am using now that is without "ID INT NOT NULL AUTO_INCREMENT" this should solve my problem. Should save records over writing each other aswell!!!

Cheers m8t.

This sql code seems to work well on the advice you have given me.

CREATE DATABASE IF NOT EXISTS dbclients;
USE dbclients;
CREATE TABLE `tbl_area` (
`areaid` int(10) unsigned NOT NULL auto_increment,
`areaname` varchar(45) NOT NULL,
PRIMARY KEY (`areaid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Take care.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
another question please....... napstar Starting Out 3 Feb 20th, 2007 22:28
css question Daniel Web Page Design 29 Feb 16th, 2007 12:13
Question!! JacobHaug JavaScript Forum 5 Dec 28th, 2006 18:22


All times are GMT. The time now is 22:24.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43