Jump to content


Photo

How to pull user info from DB, then save it??


  • Please log in to reply
15 replies to this topic

#1 Gregg

Gregg
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts
  • LocationUSA

Posted 26 August 2006 - 09:25 PM

Ok, i used the turtorial on how to make a user account. And it got it working great!
But i couldent find one on how to let them modify there profile??
I set up this datebase, and the users info is stored on the "users" table.
But i cant seem to get the forms to pull the saved info or allow the userto change it on the EDIT PROFILE.PHP?

Here is the fields listed inside the "users" table:
  userid
  first_name
  last_name
  email_address
  username
  password
  best_time
  genderid
  time
  catogory
  tag_line
  info
  teaser

I am using this php to call it:
<?
include 'db.php';
session_start();

echo "<b>Welcome,</b> ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."!<br />";
echo "<hr color=\"#000000\">";

        $query1 = "SELECT * FROM users where identity = '$userid' and email ='$email_address'";
        $result1 = mysql_query($query1,$db);
        $total1 = mysql_affected_rows();
        if($total1>0)
        {
echo $result=mysql_query($query,$db);
$sql="select * from users where identity='$userid'";
  $result=mysql_query($sql,$db);
  $row=mysql_fetch_array($result);

  $userid=$row["username"];
  $password=$row["password"]; 
  $email=$row["email_address"];
  $sex=$row["genderid"];
  $catogory=$row["catogory"];

  $query="update users set
  password='$password', email='$email_address',
sex='$genderid', catogory='$catogory';

?>

What am i doing wrong...

#2 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 26 August 2006 - 09:47 PM

Are you getting an error or is it just doing nothing?

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 26 August 2006 - 09:53 PM

Can you post the rest of the code on that page?

#4 Gregg

Gregg
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts
  • LocationUSA

Posted 26 August 2006 - 09:54 PM

Well its funny its pulling the E-Mail but nothing else. I get this error message at the top;

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/public_html/EditProfile.php on line 12

Here is the code of the entire php.

PHP
<?
include 'db.php';
session_start();

echo "Welcome, ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."!
";
echo "<hr color=\"#000000\">";

echo $result=mysql_query($query,$db);
$sql="select * from users where row='$userid'";
  $result=mysql_query($sql,$db);
  $row=mysql_fetch_array($result);

  $userid=$row["username"];
  $password=$row["password"];
  $email=$row["email_address"];
  $sex=$row["genderid"];
  $catogory=$row["catogory"];
?>

FORM
<form id="form1" name="form1" method="post" action="">
              <table width="92%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="28%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">My Online ID:</font></div></td>
                  <td width="72%"><input name="username" type="text" value="<? echo $username?>" maxlength="24" readonly="true" />
                    <a href="UserNames.txt" onclick="NewWindow(this.href,'name','350','150','yes');return false"><img src="images/User_Locked.gif" alt="Locked!" width="20" height="17" border="0" /></a></td>
                </tr>
                <tr>
                  <td><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">E-Mail:</font></div></td>
                  <td><span class="normal_text">
                    <input  type="text" name="email" value="<?echo $email_address?>" />
                  </span></td>
                </tr>
                <tr>
                  <td><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">My Pass:</font></div></td>
                  <td><span class="normal_text">
                    <input maxlength="16" name="password"
                        size="16" type="password" value="<? echo $password?>" />
                  </span></td>
                </tr>
                <tr>
                  <td><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">Gender:</font></div></td>
                  <td><span class="normal_text">
                    <select name="gender" class="general_text" id="genderid">
                      <option value=""></option>
                      <?$ressex=mysql_query("select * from gender");
while($rowgenderid=mysql_fetch_object($resgenderid))
{
$id_genderid=$rowgenderid->id;?>
                      <option value="<?echo $rowgenderid->id?>" <?if($genderid==$id_genderid){echo Selected;}?>> <?echo $rowgenderid->name?> </option>
                      <?}?>
                    </select>
                  </span></td>
                </tr>
                <tr>
                  <td><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">om</font></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">om</font></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">om</font></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">om</font></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><font color="#333333" face="Arial, Helvetica, sans-serif" size="2">om</font></td>
                  <td>&nbsp;</td>
                </tr>
              </table>
            </form>



#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 26 August 2006 - 10:14 PM

Here, try this (you may need to do some editing, tried to match everything, but never know):

<?php
include 'db.php';
session_start();
echo "Welcome, ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."!<br />";

if (isset($_POST['submit'])) {
  $userid=$_POST["username"];
  $password=$_POST["password"]; 
  $email=$_POST["email_address"];
  $sex=$_POST["genderid"];
  $catogory=$_POST["catogory"];

$query = "UPDATE users SET username = '$userid', password = '$password', email_address = '$email', genderid = '$sex', catogory = '$catogory' WHERE identity = '$userid' AND email ='$email_address'";
$result = mysql_query($query, $connection) or die(mysql_error());
echo "Your account has been updated!<br />";
}

$query = "SELECT * FROM users WHERE identity = '$userid' AND email ='$email_address'";
$result = mysql_query($query, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
  $userid=$row["username"];
  $password=$row["password"]; 
  $email=$row["email_address"];
  $sex=$row["genderid"];
  $catogory=$row["catogory"];
}
?>

<form name='update' method='post' action="<?php echo $_SERVER['PHP_SELF']; ?>">

<table width="100%">

	<tr>
		<td>Username:</td>
		<td><input name="userid" value="<?php echo $userid; ?>"></td>
	</tr>
	
	<tr>
		<td>Password:</td>
		<td><input name="password" value="<?php echo $password; ?>"></td>
	</tr>
	
	<tr>
		<td>Email Address:</td>
		<td><input name="email" value="<?php echo $email; ?>"></td>
	</tr>

	<tr>
		<td>Gender;</td>
		<td>
			<SELECT name="sex">
				<?php
				if ($sex == "") {
					echo "<OPTION>Choose One</OPTION>";
				} else {
					echo "<OPTION value='$sex'>$sex</OPTION>";
				}
				?>
				<OPTION value="Male">Male</OPTION>
				<OPTION value="Female">Female</OPTION>
			</SELECT>

		</td>
	</tr>

	<tr>
		<td>Catogory:</td>
		<td><input name="catogory" value="<?php echo $catogory; ?>"></td>
	</tr>
</table>
		<center><input name='submit' type='submit' value='Update'></center>
</form>



#6 Gregg

Gregg
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts
  • LocationUSA

Posted 26 August 2006 - 10:39 PM

Looks clean on the page but i recive a nasty error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/darkwate/public_html/datingsite/WebCams/EditProfile.php on line 19

I checked the conect php "AKA , db.php" it it is all working great, why is this one messing up??

I pasted it as you said and made the few changes and still no..

I did a little tweeking but now it says: Unknown column 'identity' in 'where clause'

#7 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 26 August 2006 - 11:29 PM

Well try it the way I had it (with the needed changes), but in the url try this:

EditProfile.php?identity=USERIDHERE&email=EMAILHERE

Change the USERIDHERE and EMAILHERE to one of a user and see what it says.

#8 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 26 August 2006 - 11:31 PM

Oh, I forgot, also:
$result = mysql_query($query, $connection) or die(mysql_error());

Should be:

$result = mysql_query($query) or die(mysql_error());




#9 Gregg

Gregg
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts
  • LocationUSA

Posted 26 August 2006 - 11:43 PM

Sorry for all the requests but i am still learning lol, It still says:

Unknown column 'identity' in 'where clause'

And the php is like this:

<?php
include 'db.php';
session_start();
echo "Welcome, ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."!<br />";
echo "<hr color=\"#000000\">";

if (isset($_POST['submit'])) {
  $userid=$_POST["username"];
  $password=$_POST["password"];
  $email=$_POST["email_address"];
  $sex=$_POST["genderid"];
  $catogory=$_POST["catogory"];

$query = "UPDATE users SET identity = '$username', password = '$password', email_address = '$email', genderid = '$sex', catogory = '$catogory' WHERE identity = '$userid' AND email ='$email_address'";
$result = mysql_query($query) or die(mysql_error());
echo "Your account has been updated!<br />";
}

$query = "SELECT * FROM users WHERE identity = '$username' AND email ='$email_address'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
  $userid=$row["username"];
  $password=$row["password"];
  $email=$row["email_address"];
  $sex=$row["genderid"];
  $catogory=$row["catogory"];
}
?>

#10 Gregg

Gregg
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts
  • LocationUSA

Posted 27 August 2006 - 01:40 AM

Any help here would be great.
Or maby if you know of a tutorial on making a modofy profile.php?

#11 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 27 August 2006 - 08:45 AM

Try:
<?php
include 'db.php';
session_start();
echo "Welcome, ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."!
";
echo "<hr color=\"#000000\">";

if (isset($_POST['submit'])) {
  $userid=$_POST["username"];
  $password=$_POST["password"];
  $email=$_POST["email_address"];
  $sex=$_POST["genderid"];
  $catogory=$_POST["catogory"];

$query = "UPDATE users SET  username = '$userid', password = '$password', email_address = '$email', genderid = '$sex', catogory = '$catogory' WHERE  username = '$userid' AND email ='$email_address'";
$result = mysql_query($query) or die(mysql_error());
echo "Your account has been updated!
";
}

$query = "SELECT * FROM users WHERE username = '$userid' AND email ='$email_address'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
  $userid=$row["username"];
  $password=$row["password"];
  $email=$row["email_address"];
  $sex=$row["genderid"];
  $catogory=$row["catogory"];
}
?>


#12 Gregg

Gregg
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts
  • LocationUSA

Posted 27 August 2006 - 05:33 PM

Ok, the code you gave dident give any errors but dident pull the info eather..
So i am posting all the info on this so maby i can get it resolved.

I used this to make the database: Thanks to the Tutorial,
CREATE TABLE users (
  userid int(25) NOT NULL auto_increment,
  first_name varchar(25) NOT NULL default '',
  last_name varchar(25) NOT NULL default '',
  email_address varchar(50) NOT NULL default '',
  username varchar(25) NOT NULL default '',
  password varchar(255) NOT NULL default '',
  best_time varchar(255) NOT NULL default '',
  genderid tinyint(5) NOT NULL default '0',
  time tinyint(5) NOT NULL default '0',
  email varchar(100) NOT NULL default '',
  catogory tinyint(5) NOT NULL default '0',
  tag_line varchar(25) NOT NULL default '',
  info text NOT NULL,
  teaser text NOT NULL,
  user_level enum('Newbie','1','2','3','Admin') NOT NULL default 'Newbie',
  user_rating enum('0','1','2','3','4','5','6','7','8','9','10') NOT NULL default '0',
  user_warnlevel enum('0','1','2','3','4','5','Banned') NOT NULL default '0',
  signup_date datetime NOT NULL default '0000-00-00 00:00:00',
  last_login datetime NOT NULL default '0000-00-00 00:00:00',
  activated enum('0','1') NOT NULL default '0',
  premium char(2) default 'N',
  loggedin char(1) NOT NULL default 'N',

  PRIMARY KEY  (userid)
) TYPE=MyISAM COMMENT='Membership Information';

And this is all the php on the "EditProfile" page, i removed the (Welcome, thinking maby it was the cause of the error..
<?php
include 'db.php';

if (isset($_POST['submit'])) {
  $userid=$_POST["username"];
  $password=$_POST["password"];
  $email=$_POST["email_address"];
  $sex=$_POST["genderid"];
  $catogory=$_POST["catogory"];

$query = "UPDATE users SET  username = '$userid', password = '$password', email_address = '$email', genderid = '$sex', catogory = '$catogory' WHERE  username = '$userid' AND email ='$email_address'";
$result = mysql_query($query) or die(mysql_error());
echo "Your account has been updated!
";
}

$query = "SELECT * FROM users WHERE username = '$userid' AND email ='$email_address'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
  $userid=$row["username"];
  $password=$row["password"];
  $email=$row["email_address"];
  $sex=$row["genderid"];
  $catogory=$row["catogory"];
}
?>

And the form in witch it should be displayed and changed,But dont seen to load it..
<form name='update' method='post' action="<? echo $_SERVER['PHP_SELF']; ?>">

<table width="100%">

	<tr>
		<td>Username:</td>
		<td><input name="userid" value="<? echo $userid; ?>" readonly="true">
		  <img src="images/User_Locked.gif" alt="Locked" width="20" height="17" /></td>
	</tr>
	
	<tr>
		<td>Password:</td>
		<td><input name="password" type="password" value="<? echo $password; ?>"></td>
	</tr>
	
	<tr>
		<td>Email Address:</td>
		<td><input name="email" value="<? echo $email; ?>"></td>
	</tr>

	<tr>
		<td>Gender;</td>
		<td>
			<SELECT name="sex">
				<? echo $genderid; ?>
			</SELECT></td>
	</tr>

	<tr>
		<td>Catogory:</td>
		<td><select name="select">
           <? echo $catogory; ?>
          </select></td>
	</tr>
</table>
		<center><input name='submit' type='submit' value='Update'></center>
</form>

Just so you know i did remove all the other php "code" of the page thinking maby it was an errorcause it was not compatible with it and still no. ???

#13 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 27 August 2006 - 06:23 PM

Use the code I said, but access the page like:
EditProfile.php?username=USERNAMEHERE&email=EMAILHERE

Since the query is pulling and updating the information
WHERE  username = '$username' AND email ='$email_address'

If it's not set in the parameters, then it doesn't know what information to pull. Make sense?

Here is the code:

<?php
include 'db.php';
session_start();
echo "Welcome, ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."!
";
echo "<hr color=\"#000000\">";

if (isset($_POST['submit'])) {
  $userid=$_POST["username"];
  $password=$_POST["password"];
  $email=$_POST["email_address"];
  $sex=$_POST["genderid"];
  $catogory=$_POST["catogory"];

$query = "UPDATE users SET  username = '$userid', password = '$password', email_address = '$email', genderid = '$sex', catogory = '$catogory' WHERE  username = '$username' AND email ='$email_address'";
$result = mysql_query($query) or die(mysql_error());
echo "Your account has been updated!
";
}

$query = "SELECT * FROM users WHERE username = '$username' AND email ='$email_address'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
  $userid=$row["username"];
  $password=$row["password"];
  $email=$row["email_address"];
  $sex=$row["genderid"];
  $catogory=$row["catogory"];
}
?>

Also, you do have the username and email set within the session right?

#14 Gregg

Gregg
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts
  • LocationUSA

Posted 27 August 2006 - 06:41 PM

Ok, it pulled the "Username" & "E-Mail" but nothing else?
I entered a new pass and hit ok.
And when i submited it said updated but ilooked at the DB ad it wasent updated...

And how do i make it so it works for all users and not just me?

I was thinking of  going back to cookie  usage... Cause when i have cookies set it pulls and saves it just fine in my other DB..
My other php site uses cookies and it works 100%

Or is it possible to ad a  "UsErCoKie" in the login proccess... on the on i got from the tutorial?
I was taught to use cookies, this session is just to much unnessary work..

#15 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 27 August 2006 - 07:05 PM

Do you set the "$username" and "$email_address" when they login? To the session?

#16 Gregg

Gregg
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts
  • LocationUSA

Posted 27 August 2006 - 07:26 PM

I am not shure what you mean,on the login page?
Or in the link to the editprofile.php?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users