Jump to content

editing tables using php


ambo

Recommended Posts

$someUserId = 23523;

$query = "SELECT * FROM de_user WHERE userid = '$someUserId'";

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

$row = mysql_fetch_assoc($result);

echo "{$row['email']}<br />{$row['name']}<br />{$row['sex']}";

 

I used that to get the data But how do i Change the Data i wanna make a edit profile page would i use a new form to post the data or can it be done with php to verify the user is actully being the one edited???

Link to comment
https://forums.phpfreaks.com/topic/124677-editing-tables-using-php/
Share on other sites

That's a really complicated request. But, the basic steps are to create a form that has all the fields that they can modify populated by the results of your query. Then when they submit the page, do an update query that changes the data.

 

You'll probably want to check for special characters and stuff so they don't bomb the page if they enter a quote or something.

 

As far as validating who they are, you'll have to do some kind of check with something they enter against a value in the database to see if it matches. If it does, allow the update. If not, display an error.

Ok you have to use the

<?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }mysql_select_db("my_db", $con);

 

mysql_query("UPDATE Person SET Age = '36'WHERE FirstName = 'Peter' AND LastName = 'Griffin'");mysql_close($con);

?>

how does the <form> tag relate to what is red how do i get the for to post that data

OK, I'll try and simplify this as much as possible.

 

<form method="post">
<?php if (!isset($_POST['id'])){ ?>
Enter your ID here: <input type="text" size="5" name="id"><input type="submit" value="Submit">
<?php } elseif (!isset($_POST['name'])){
$result = mysql_query("SELECT name FROM users WHERE id = {$_POST['id']}");
$row = mysql_fetch_array($result);
?>
<input type="hidden" name="id" value="<?=$_POST['id?>">
Change your name: <input type="text" size="25" name="name" value="<?=$row[0]?>"><input type="submit" value="Submit">
<?php } else{
$result = mysql_query("UPDATE users SET name = '{$_POST['name']}' WHERE id = {$_POST['id']}")
if ($result) echo "Name saved";
else echo "Problem saving";
} ?>
</form>

 

Hope that helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.