I have a basic website set up with a forum and registration system. I am now working on adding the ability to edit content and update the db. I have yet to get any of the update portions of my site to work. This one loads the form with all the current data, but it doesn’t execute. It doesn’t seem to do anything at all. The same thing happens on any other page where I try to update the db with new info. Anyway, here is the code to the one for user profiles. I figure if I can get this one working I can fix the others.
<?php
include_once('includes/config.php');
include_once('classes/player.php');
include('includes/header.php');
$player = new Player;
if(isset($_GET['id']))
{
if( $user->is_logged_in() && ($_SESSION['user_id'] == $_GET['id']))
{
$user_id = $_GET['id'];
$data = $player->fetch_data($user_id);
if(isset($_POST['submit']))
{
if (isset($_POST['user_name'], $_POST['user_signature'], $_POST['user_email']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$sig = ($_POST['signature']);
$query = $pdo->prepare('UPDATE users SET (user_name, user_email, user_signature) VALUES (?, ?, ?) WHERE user_id = ?');
$query->bindValue(1, $name);
$query->bindValue(2, $email);
$query->bindValue(3, $sig);
$query->bindValue(4, $user_id);
$query->execute();
header("location:player.php?id=".$_GET['id']);
exit;
}
}
?>
<div id = "wrapper">
<div id = "header-style"><?php echo $data['user_name']; ?></div>
<section>
<?php if (isset($error)) { ?>
<small><?php echo $error; ?></small>
<?php } ?>
<form action="<?php echo "edit_player.php?id=".$_GET['id']?>" method="post" autocomplete="off">
<small>Username</small><br/>
<input type="text" name="name" placeholder="Something cool..." value="<?php echo $data['user_name']; ?>" /><br /><br />
<small>Email</small><br/>
<input type="email" name="email" placeholder="Email" value="<?php echo $data['user_email']; ?>" /><br /><br />
<small>Dead Drop Signature (limit 30 characters)</small><br />
<input type="text" name="signature" placeholder="Your tagline..." value="<?php echo $data['user_signature']; ?>" /><br/><br />
<input type="submit" value="Update" />
</form>
</section>
</div>
<?php
} else {
//the user is not the same
echo '<div id="errors">Sorry, you do not have sufficient rights to access this page.</div>';
}
}
include('includes/footer.php');
?>