I have a website where there is a "Add to my favorites" button. I want it to make it when user click on the button to check if the user is logged in and if it isto connect to the DB and to add a data into the DB, if he is not logged in to say "You are not logged in". I know how to write the PHP code but i need some help for the button or link it doesent matter Any help
Are you wanting an AJAX like feature? Or a basic POST form submit? Either or, you will be required to use a server side scripting language such as PHP. Pretty simple really, for a HTML <form> to POST data. <?php $error_flag = FALSE; $output_message = ''; if( TRUE == isset($_POST['submit']) ) { /* Do check here for user status. */ if( FALSE == $user->is_logged_in() ) { $output_message = 'You are not logged in.'; $error_flag = TRUE; } /* Do check here for Database connection */ if( FALSE == $db->is_connected() ) { $error_flag = TRUE; } if( FALSE == $error_flag ) { /* Do operations needed if the user is logged in and DB connection is made */ } } ?> <!-- HTML Code --> <!-- Echo $output_message --> <?= $output_message; ?> <form action="<?= $_SERVER['PHP_SELF']; ?>" method="post"> <input type="submit" name="submit" value="Button to Do Something" /> </form> Code (markup): Let me know if this basic example helps you out at all.
Yes but how to make it the AJAX or the Javascript coding. That i dont know. And how to connect that code with the PHP script