Jump to content

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


Gregg

Recommended Posts

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...
Link to comment
Share on other sites

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.
[quote]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>[/quote]
Link to comment
Share on other sites

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

[code]
<?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>

[/code]
Link to comment
Share on other sites

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'
Link to comment
Share on other sites

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"];
}
?>
Link to comment
Share on other sites

Try:
[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 = '$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"];
}
?>
[/code]
Link to comment
Share on other sites

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.

[b]I used this to make the database:[/b] Thanks to the Tutorial,
[code]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';[/code]

[b]And this is all the php on the "EditProfile" page, i removed the (Welcome, thinking maby it was the cause of the error..
[/b][code]<?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"];
}
?>[/code]

[b]And the form in witch it should be displayed and changed,[/b]But dont seen to load it..
[code]<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>[/code]

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. ???
Link to comment
Share on other sites

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

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

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

Here is the code:

[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"];
}
?>
[/code]

Also, you do have the username and email set within the session right?
Link to comment
Share on other sites

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..
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.