$credit = $_POST['credits'];
$twitter_impressions = '2';
$twitter_spend='1';
$fb_impressions = '2';
$fb_spend='1';
if (isset($_POST['type'])) {
if ($_POST['type'] == 'twitter') {
$total = ($credit * $twitter_spend);
$convert = (($credit * $twitter_impressions) / $twitter_spend);
$stmt=$db->prepare("UPDATE social_posts
SET credits = credits + :credits, message = :message
WHERE username = :user AND id = :id");
$stmt->bindParam(':user', $username);
$stmt->bindParam(':credits', $convert);
$stmt->bindParam(':id', $_POST['id']);
$stmt->bindParam(':message', $_POST['text']);
$stmt->execute();
}
if ($_POST['type'] == 'facebook') {
$total = ($credit * $fb_spend);
$covert = (($credit * $fb_impressions) / $fb_spend);
$stmt=$db->prepare("UPDATE social_posts
SET credits = credits + :credits, message = :message
WHERE username = :user AND id = :id");
$stmt->bindParam(':user', $username);
$stmt->bindParam(':credits', $convert);
$stmt->bindParam(':id', $_POST['id']);
$stmt->bindParam(':message', $_POST['text']);
$stmt->execute();
}
}
Form processing is only working when $_POST['type'] is twitter, when it is facebook it is not processing.
foreach ($row AS $row) {
?>
<div class="contain" style="display:none;">
<div class="alert alert-success" id="<? echo $row['id']; ?>">
<form style="height:42px;">
<h4 class="pull-left" style="text-transform: capitalize; width:11%;">
<? echo $row['type']; ?> Post:
</h4>
<textarea class="pull-left" style="margin-right:1%;">
<? echo $row['message']; ?>
</textarea>
<h4 class="pull-left" style="text-transform: capitalize; width:6%;">
Credits:
</h4>
<input class="pull-left ucredits" style="width:8%; margin-right:1%; "
type="text" value="" />
<h4 class="pull-left" style="text-transform: capitalize; width:9%;">
Impressions:
</h4>
<i class="<? echo $row['type']; ?>" style="display:none;">
<? echo $row['type']; ?>
</i>
<input class="pull-left credits" style="width:9%; margin-right:1%; "
type="text" value="<? echo $row['credits']; ?>" />
<button class="pull-left btn btn-primary update"
id="update<? echo $i++; ?>" value="<? echo $row['id']; ?>" type="submit"
style="width:7%; margin-right:1%;" name="credits">Submit</button>
</form>
</div>
</div>
<? } ?>
<script>
$(document).ready(function(){
$('.alert').on('click', 'button[id^=update]', function(e) {
e.preventDefault();
e.stopPropagation();
var form = $(this).closest( "form" );
var checkValues = form.find(".update").val();
var checkCred = form.find(".ucredits").val();
var checkPost = form.find("textarea").text();
var checkType = form.find("i").text();
$.ajax({
type: "POST",
url: "update_social_cred.php",
data: {
id: checkValues,
credits: checkCred,
text: checkPost,
type: checkType
},
success:function(result) {
alert (checkType);
}
});
});
});
</script>
The form is absolutely submitting because I both have it echoing the type correctly, and when the type is twitter, the form is correctly processing. However when the type is facebook, it is not processing. I have also tried switching facebook from the 3rd if statement to the 2nd, yet still only if type is twitter is the form being correctly processed. Equally I have tried to change the if's to if elseif else statements, no change.
Also for the record, there are other type's I am not showing here, all fail except twitter, all use the exact same format and code only different variables.