开发者

confirm box in javascript while inserting record

开发者 https://www.devze.com 2023-03-01 13:30 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号