date_default_timezone_set('UTC');// to get the actual time of registration
$caption = mysqli_real_escape_string($connect,$_POST['post_title']);
$postBody = mysqli_real_escape_string($connect,$_POST['post_body']);
$post_image = mysqli_real_escape_string($connect,$imagename);
$sql = "SELECT id FROM designers WHERE email = '".$_SESSION['email']."' ";
$run = mysqli_query($connect,$sql);
while($row = mysqli_fetch_array($run)){
$id = $row['id'];
$post_id++;
}
$query="INSERT INTO post(user_id,post_title,post_body,image,post_id) VALUES
('".$id."','".$caption."','".$postBody."','".$post_image."','".$post_id."')";
$result= mysqli_query($connect,$query);
if($result){
echo "<script>
alert(' Post Successful');
window.location.href ='profile.php'; // will take you to profile page
</script>";
}else{
echo "<script>alert('not Submitted')</script>";
i want to auto increment post_id by 1
When you write it into the post
table? Why not just set the column in the database table definition to auto-increment, and let it do the work for you?
I don’t see where your code above gets the initial value of $post_id
, so I can’t see how it would change value inside your loop.
You don’t have to “try” incrementing anything, the id field in the table should have the auto_increment
property and it will be autoincremented.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.