0

I am trying to update a edit profile in mysql. the first bit of code is when the submit button on forum is hit the data in my table users willl change. the secound bit code get the user info from the database it work fine you can select what person to update i just have to figer out how to display the detail in the forum. i don't seem to have any problems with it. the last bit doesn't do much yet outher then show the form and should show the info from the ger info.php i havent got that yet. ive been messing around trying to figure it all out for a while and can't seem to get it. at one point i tot i had it connecting but it still wouldn't update the database, so i have no idea. feel free to suggest anything.

<?php
if (!isset($_SESSION['id'])) { 
}
include('db.php');
header("Access-Control-Allow-Origin: *");
if (!isset($_GET['id'])){
    session_start();
    $id = 1;
}else{
    $id = $_GET['id'];
}
if (isset($_POST['UPDATE'])) {
$firstname = $_POST['firstname'];
$lastame= $_POST['lastname'];
$email= $_POST['email'];
$bio = $_POST['bio'];
$sql = mysql_query("UPDATE users SET firstname='$firstname',lastname='$lastname',email='$email', bio='$bio'WHERE id ='$id'"); 
echo 'Your account info has been updated, visitors to your profile will now see the new info.<br /><br />
To return to your profile edit area, <a href="profile.php">click here</a>';
exit();
}  //close if post
?>








<?php

include('db.php');
header("Access-Control-Allow-Origin: *");
if (!isset($_GET['id'])){
    session_start();
    $id = 1;
}else{
    $id = $_GET['id'];
}

$result = mysql_query("SELECT * FROM users WHERE id = ".$id.";");
if (mysql_num_rows($result) == 1){
    $id = mysql_result($result, 0,"id");
    $firstname = mysql_result($result, 0,"firstname");
    $lastname = mysql_result($result, 0,"lastname");
    $email = mysql_result($result, 0,"email");
    $bio = mysql_result($result, 0,"bio");
    $detailsArray = array ("status" => 1, "firstname" => $firstname,"lastname" => $lastname,"email" => $email,"bio" => $bio);
    echo json_encode($detailsArray);
}else{
    $detailsArray = array ("status" => 0);
    echo json_encode($detailsArray);
}

mysql_close();
?>



<?php
include('db.php');
?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit Your Account Info</title>
<script type="text/javascript">

<!-- Form Validation -->
function validate_form ( ) { 
valid = true; 
if ( document.form.firstname.value == <?php echo $firstname; ?>" /> ) { 
alert ( "firstname must not be blank." ); 
valid = false;
}
if ( document.form.lastname.value == <?php echo $lastname; ?>" /> ) { 
alert ( "lastname must not be blank." ); 
valid = false;
}
if ( document.form.email.value == <?php echo $email; ?>" /> ) { 
alert ( "email must not be blank." ); 
valid = false;
}
if ( document.form.bio.value == <?php echo $bio; ?>" /> ) { 
alert ( "bio must not be blank." ); 
valid = false;
}
return valid;
}
<!-- Form Validation -->
</script>
</head>
<body>
     <div align="center">
       <h3><br />
        Edit Account info  
         <br />
       </h3>
</div>
     <table align="center" cellpadding="8" cellspacing="8">
      <form action="file:///C:\xampp\htdocs\Team Project\Web\PHP\edit_info.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return validate_form ( );">
     <tr>

       <td><div align="right">Firstname:</div></td>
       <td><input name="frist" type="text" id="name" value="<?php echo $firstname; ?>"   size="30" maxlength="64" /></td>
    </tr>
        <tr>
          <td><div align="right">lastname:</div></td>
        <td><input name="secound" type="text" id="lastame" value="<?php echo $lastname; ?>"     size="30" maxlength="64" /></td>
        </tr>  
        <tr>
          <td><div align="right">Email:</div></td>
          <td><input name="email" type="text" id="email" value="<?php echo $email; ?>"   size="30" maxlength="24" /></td>
        </tr>
        <tr>
             <td class="style7"><div align="right">bio:</div></td>
          <td><textarea name="bio" cols="42" rows="8" id="bio"  value="<?php echo $bio; ?>" ></textarea></td>
        </tr>                
        <tr>

<td><input name="Submit" type="submit" value="Submit Changes" /></td>
        </tr>
      </form>
</table>

</body>
</html>
2
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by LastMitch
0

@johnjo

ive been messing around trying to figure it all out for a while and can't seem to get it. at one point i tot i had it connecting but it still wouldn't update the database, so i have no idea. feel free to suggest anything.

On this query:

$sql = mysql_query("UPDATE users SET firstname='$firstname',lastname='$lastname',email='$email', bio='$bio'WHERE id ='$id'");

Add this at the end: `or die(mysql_error());

$sql = mysql_query("UPDATE users SET firstname='$firstname',lastname='$lastname',email='$email', bio='$bio'WHERE id ='$id'") or die(mysql_error());

Tell me what error you get it? You should get an error.

On this query it's wrong:

$result = mysql_query("SELECT * FROM users WHERE id = ".$id.";");

it should look like this

$result = mysql_query("SELECT * FROM users WHERE id='$id'");

Add this at the end: `or die(mysql_error());

$result = mysql_query("SELECT * FROM users WHERE id='$id'") or die(mysql_error());

Tell me what error you get it? You should get an error.

0

when i put in the or die(mysql_error()); iam getting no error just blank screen now

as for the result= mysql-query its working fine so didnt tuch it

0

@johnjo

when i put in the or die(mysql_error()); iam getting no error just blank screen now

as for the result= mysql-query its working fine so didnt tuch it

Are you sure?

This query is wrong:

$result = mysql_query("SELECT * FROM users WHERE id = ".$id.";");

You can't fetch the id because you have a semi-colon and qoutes and period ".$id.";"

The correct query should look like this:

$result = mysql_query("SELECT * FROM users WHERE id ='$id'");

Are you connected to your database?

You need to test your database to see whether it is connected.

Your query is wrong there should be an error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.