confirm box in javascript while inserting record
i am inserting an record in database, while inserting i have to check if that value is already in the db. If it found then there will be a confirm box showing that 'Record is already in database. Do you want to add?'.
whi开发者_开发知识库le doing this, if the record found then i have given a confirm message in javascript and in that i wrote the insert query and then complete the script. It works, but if the user click on the Cancel button, then also record is inserted. Why this happen? I use this code -<script type="text/javascript">
if(confirm('Record already exist. Do you want to add?')) { <?
$insert = mysql_query("insert into user ----------");
?> }
</script>
thanks.
This cannot work. PHP runs on the server, JavaScript in the client's browser.
You can use AJAX for this purpose though; have a look at http://api.jquery.com/category/ajax/ to get started.
精彩评论