Jump to content

updating user information based on id


silverglade

Recommended Posts

Hi, I want to update user information in the database but it doesn't do anything. No data entered upon form submission. Please anyone if you can help would be great. Thank you.

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$host		= "";//edited out
$database 	= "";
$username 	= "";
$password 	= "";

$tbl_name   = "users";
$link = mysqli_connect($host, $username, $password);
$conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error());
mysql_select_db($database);

session_start();

IF (isset($_SESSION['userid'])){
$userid=$_SESSION['userid'];
echo $userid;
}

//$currentUser = $_SESSION['myusername']; 

//do some cleanup//
IF (isset($_POST['submit'])){

$first =  $_POST['first'];
$last = $_POST['last'];
$dob = $_POST['dob'];
$gender =  $_POST['gender'];

$country =  $_POST['country'];
$state =   $_POST['state'];
$town =   $_POST['town'];
$zip =  $_POST['zip'];
$email =  $_POST['email'];



$first = mysql_real_escape_string( '$first');
$last = mysql_real_escape_string(  '$last');
$dob = mysql_real_escape_string(  '$dob');
$gender = mysql_real_escape_string(  '$gender');

$country = mysql_real_escape_string(  '$country');
$state = mysql_real_escape_string(  '$state');
$town = mysql_real_escape_string(  '$town');
$zip = mysql_real_escape_string(  '$zip');
$email = mysql_real_escape_string(  '$email');


};
IF (isset($_SESSION['userid'])){
$userid=$_SESSION['userid'];
}
ELSE{
$getuserid=mysql_query ("SELECT id FROM users ORDER BY id DESC limit 1") or die(mysql_error());
WHILE ($gtuserid = mysql_fetch_array($getuserid)) {
$theuserid=$gtuserid['id'];
$userid=$theuserid;
$_SESSION['userid']=$theuserid;
$userid=$_SESSION['userid'];
}//$getuserid
}// IF ELSE (isset($_SESSION['userid']))


/////UPDATE SECTION///// 
IF (isset($_POST['submit'])){
mysql_query ( "UPDATE users SET firstname='$first', lastname='$last', dob = '$dob', gender='$gender',    country='$country', state='$state', town='$town', zip='$zip', email='$email'   WHERE id=$userid") or die(mysql_error());  
}//IF ($_POST['update']=="Update")



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Connection</title>
<style type="text/css">	
body {
font-family:Calibri;
font-size:1em;
}
.title {
font-size:1.6em;
font-weight:strong;
}
.links a{
font-size::1.2em;
text-decoration:none;
}
.links a:hover{
font-size::1.2em;
color:#0066FF;
text-decoration:none;
}
</style>
</head>
<body>
<p><span class="title">Add your personal information/span></p>

<form action="thebeast.php" method="post">
    <p>
    <input type="text" name="first" size="20" id="first"  /> 
  First name<br />
    <input type="text" name="last" size="20"  id="name" />
    Last name<br />
    <input name="dob" type="text" size="20" id="dob"  ; } ?>
    Date of Birth<br />
    <input type="text" name="gender" size="20" id="gender"   />
  Gender <br />
  <input type="text" name="country" size="20" id="country"   />
  Country<br />
  <input type="text" name="state" size="20" id="state"   />
  State<br />
    <input type="text" name="town" size="20" id="town"  />
    Town<br />
    <input type="text" name="zip" size="20" id="zip"  />
Zip Code<br />
    <input type="text" name="email" size="40" id="email"   />
    Email<br />
    <br />
     
  
     

      
   <input type="submit" name="submit" value="Add your information" />
      
        
</form> 





</body>
</html>

Link to comment
Share on other sites

Change the update line to:

mysql_query ( "UPDATE users SET firstname='".$first."', lastname='".$last."', dob = '".$dob."', gender='".$gender."', country='".$country."', state='".$state."', town='".$town."', zip='".$zip."', email='".$email."'   WHERE id=".$userid."") or die(mysql_error());

 

 

If that doesn't work let me know.

Link to comment
Share on other sites

thank you Karl. It updates the info, but where the user data should be in the row fields for that user, things like this are in there, literally string names. like this "$name", "dob", "$city". It is putting the variable names in there instead. any help greatly appreciated. here is the code as I adjusted it.

 

/////UPDATE SECTION///// 
IF (isset($_POST['submit'])){
mysql_query ( "UPDATE users SET firstname='".$first."', lastname='".$last."', dob = '".$dob."', gender='".$gender."', country='".$country."', state='".$state."', town='".$town."', zip='".$zip."', email='".$email."'   WHERE id=".$userid."") or die(mysql_error());
}//IF ($_POST['update']=="Update")

Link to comment
Share on other sites

Hmm, try this instead:

mysql_query ( "UPDATE users SET firstname='{$first}', lastname='{$last}', dob = '{$dob}', gender='{$gender}', country='{$country}', state='{$state}', town='{$town}', zip='{$zip}', email='{$email}'   WHERE id={$userid}) or die(mysql_error());

Link to comment
Share on other sites

Had a bit of a cleanup with your code so try this:

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$host        = "";//edited out
$database     = "";
$username     = "";
$password     = "";

$tbl_name   = "users";
$link = mysqli_connect($host, $username, $password);
$conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error());
mysql_select_db($database);

session_start();

if (isset($_SESSION['userid'])){
    $userid=$_SESSION['userid'];
    echo $userid;
}

//$currentUser = $_SESSION['myusername']; 

//do some cleanup//
if (isset($_POST['submit'])){

    $first =  $_POST['first'];
    $last = $_POST['last'];
    $dob = $_POST['dob'];
    $gender =  $_POST['gender']; 
    $country =  $_POST['country'];
    $state =   $_POST['state'];
    $town =   $_POST['town'];
    $zip =  $_POST['zip'];
    $email =  $_POST['email'];
    //Clean them
    $first = mysql_real_escape_string($first);
    $last = mysql_real_escape_string($last);
    $dob = mysql_real_escape_string($dob);
    $gender = mysql_real_escape_string($gender);
     
    $country = mysql_real_escape_string($country);
    $state = mysql_real_escape_string($state);
    $town = mysql_real_escape_string($town);
    $zip = mysql_real_escape_string($zip);
    $email = mysql_real_escape_string($email);

    mysql_query ( "UPDATE users SET firstname='{$first}', lastname='{$last}', dob = '{$dob}', gender='{$gender}', country='{$country}', state='{$state}', town='{$town}', zip='{$zip}', email='{$email}'   WHERE id={$userid}") or die(mysql_error());

}

if (isset($_SESSION['userid'])){
    $userid=$_SESSION['userid'];
} else {
    $getuserid=mysql_query ("SELECT id FROM users ORDER BY id DESC limit 1") or die(mysql_error());
    
    while ($gtuserid = mysql_fetch_array($getuserid)) {
        $theuserid=$gtuserid['id'];
        $userid=$theuserid;
        $_SESSION['userid']=$theuserid;
        $userid=$_SESSION['userid'];
    }//$getuserid
}// IF ELSE (isset($_SESSION['userid']))
  
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Connection</title>
<style type="text/css">    
    body {
    font-family:Calibri;
    font-size:1em;
    }
    .title {
    font-size:1.6em;
    font-weight:strong;
    }
    .links a{
    font-size:1.2em;
    text-decoration:none;
    }
    .links a:hover{
    font-size:1.2em;
    color:#0066FF;
    text-decoration:none;
    }
</style>
</head>
<body>
<p><span class="title">Add your personal information/span></p>

<form action="thebeast.php" method="post">
    <p>
    <input type="text" name="first" size="20" id="first"  /> 
    First name<br />
    <input type="text" name="last" size="20"  id="name" />
    Last name<br />
    <input name="dob" type="text" size="20" id="dob"  ; } ?>
    Date of Birth<br />
    <input type="text" name="gender" size="20" id="gender"   />
    Gender <br />
    <input type="text" name="country" size="20" id="country"   />
    Country<br />
    <input type="text" name="state" size="20" id="state"   />
    State<br />
    <input type="text" name="town" size="20" id="town"  />
    Town<br />
    <input type="text" name="zip" size="20" id="zip"  />
    Zip Code<br />
    <input type="text" name="email" size="40" id="email"   />
    Email<br />
    <br /> 
   <input type="submit" name="submit" value="Add your information" />   
</form> 





</body>
</html>

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.