Is it possible to update all non-blank (only the inputs the user puts information in) inputs with one form? So, I have an edit_profile.php page, and I have a list of inputs. It's in one form too. I'm still a beginner at PHP so I'm not really sure how to do it. I know where I am going wrong with the PHP, I just don't know a way around it. Here is the html;
<form action="edit_profile.php" method="post">
<fieldset>
<legend>Edit your profile</legend>
<label for="title">Member Title</label>
<input type="text" name="title" id="title" placeholder="Member Title">
<span class="help-block">This will be shown next to your posts. Only numbers, letters, and grammar symbols allowed</span>
<hr class="soften">
<label for="about">About you</label>
<textarea name="about" id="about" placeholder="Tell us about yourself"></textarea>
<span class="help-block">This information will be visible to other registered members. Only numbers, letters, and grammar symbols allowed</span>
<hr class="soften">
<label>Your gender</label>
<p>I am...</p>
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-primary" id="gender" name="gender" value="Not Saying">Not Saying</button>
<button type="button" class="btn btn-primary" id="gender" name="gender" value="Male">Male</button>
<button type="button" class="btn btn-primary" id="gender" name="gender" value="Female">Female</button>
</div>
<span class="help-block">This is optional, leave as it is if you do not want to specify your gender.</span>
<hr class="soften">
<h3 class="muted">Social</h3>
<div class="row-fluid">
<div class="span4">
<label for="social_facebook">Facebook</label>
<input type="url" name="social_facebook" id="social_facebook" placeholder="Link to your Facebook page..." style="width: 100%">
</div>
<div class="span4">
<label for="social_twitter">Twitter</label>
<input type="url" name="social_twitter" id="social_twitter" placeholder="Link to your Twitter page..." style="width: 100%">
</div>
<div class="span4">
<label for="social_youtube">YouTube</label>
<input type="url" name="social_youtube" id="social_youtube" placeholder="Link to your YouTube page..." style="width: 100%">
</div>
</div>
<span class="help-block">This information will be displayed on your profile if anything is entered</span>
<hr class="soften">
<label class="checkbox">
<input type="hidden" name="view_profile" id="view_profile" value="0">
<input type="checkbox" name="view_profile" id="view_profile" value="1"> View profile after saving?
</label>
<hr class="soften">
<button type="submit" class="btn btn-primary">Save Profile</button>
<a href="./" class="btn btn-inverse">Cancel</a>
</fieldset>
and the PHP;
$gender = '';
$id = $_SESSION['id'];
$title = $_POST['title'];
$about = $_POST['about'];
$gender = $_POST['gender'];
$check = $_POST['view_profile'];
$facebook = $_POST['social_facebook'];
$twitter = $_POST['social_twitter'];
$youtube = $_POST['social_youtube'];
$errors = array();
if($title){
$range = range(0,32);
if(!in_array(strlen($title),$range)){
$errors[] = "<div class='alert alert-danger'>Member Title has a character limit of 32 characters!</div>";
}
}
# if(empty($gender)) {
# $errors[] = "<div class='alert alert-danger'>Please select a gender!</div>";
# }
$title = addslashes(htmlspecialchars($title));
$about = addslashes(htmlspecialchars($about));
$facebook = stripslashes($facebook);
$twitter = stripslashes($twitter);
$youtube = stripslashes($youtube);
if(count($errors) > 0){
foreach($errors AS $error){
echo '<div class="container">';
echo $error;
echo '</div>';
}
} else {
if(!empty($check)) {
$url = "./profile.php?id=".$_SESSION['id']."";
$_SESSION['profile_updated'] = "Your profile was successfully updated";
}
if(empty($check)) {
$url = './edit_profile.php';
$_SESSION['profile_updated_edit'] = "Your profile was successfully updated. <a href='./profile.php?id=".$_SESSION['id']."'>View it here</a>";
}
$sql4 = "UPDATE
`user_profiles`
SET
`title` = '$title',`about` = '$about', `gender` = '$gender', `facebook` = '$facebook', `twitter` = '$twitter', `youtube` = '$youtube'
WHERE
`id` = '$id'";
$res4 = mysql_query($sql4) or die(mysql_error());
header("Location: $url");
}
So I know I am going wrong on the "UPDATE user_profiles
query, I just do not know how to insert inputs if they contain information :)