/    Sign up×
Community /Pin to ProfileBookmark

how to execute php code on javascript confirm box

hi.i think i am asking a basic question, like i have submit button upon on click i am calling function which performs confirm() operation.. but now my problem is when i click on ok button i want my database opeartions should happen , if i press cancel it should not dont do any opeartions.. i think i need to use ajax for dis..as problem s with client side nd server side execution please any one can help me.. how can i achieve this..

my code is:
<input type=”submit” name=”Submit” onclick=”show_confirm()” value=”Add Menu Item” />

<script>
function show_confirm()
{
var r=confirm(“Do you want to add a menu item”);
if(r==true)
{
alert(“your menu has been added”);
}
if(r==false)
{
call ajax i think
}
}

my php code to be executed upon ok
<?php
ob_start();
include(“connection.php”);
$q1=”select * from menureg”;
$r1=mysql_query($q1);
$row1=mysql_num_rows($r1);
/*
if($row1>8)
{
echo “you are not supposed to insert menu itm”;
}
*/
if(isset($_POST[‘Submit’]))
{
$name=$_
POST[‘menuname’];
$ord=$row1+1;

/*echo $q=”insert into menureg(menuname,order1)values(‘$name’,’$ord’)”;
echo $r=mysql_query($q);*
/

$q1=”select * from menureg”;
$r1=mysql_query($q1);
$row1=mysql_num_rows($r1);
/*
if($row1>8)
{
echo “you are not supposed to insert menu itm”;
}*/
if($row1<8)
{
$q=”insert into menureg(menuname,order1)values(‘$name’,’$ord’)”;
$r=mysql_query($q);

/*if($r)
{
header(“location:process.php”);
ob_flush();
}*
/
}
else
{
$msg=”you are not supposed to insert menu item as limit is upto 8″;
}
}
?>

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@JunkMaleAug 14.2009 — 
  • 1. forum tags, please use them, it helps not only the reader but it also increases the chance of you getting help as your code is more readable.


  • 2. your question is not clear but if I am reading between the lines, yes, AJAX may be an option to you if you want to submit data without changing the page.
  • Copy linkTweet thisAlerts:
    @prathikanoeauthorAug 14.2009 — hi

    thanks for ur reply.. but i will tell u clearly my prob..i want my database operation to be done only if i click ok in the confirm box.please suggest me.hw to use ajax for dis problem..ur reply will help me a lot.

    regards

    prati
    Copy linkTweet thisAlerts:
    @JunkMaleAug 14.2009 — Thats what this site is for but you should be aware that AJAX is a subject that has been covered many times and many examples exist in the forum for javascript.
    Copy linkTweet thisAlerts:
    @prathikanoeauthorAug 14.2009 — ok.i have a basic idea regarding AJAX. I AM FACIN PROBLEM when i run ajax codes when the condition is true , the xmlHttp=GetXmlHttpObject(); is returnng null.. as it means it s not calling that function.
    Copy linkTweet thisAlerts:
    @JunkMaleAug 14.2009 — Well that depends on how the object is being made and if your browser supports that method of making an AJAX object. Whos thread are you refering to?
    Copy linkTweet thisAlerts:
    @prathikanoeauthorAug 14.2009 — i am referng to next page where i wan to execute my phhp code.in that case i am gettng null object exxecution.

    so i used thank for reply.but i dnt knw much bout ajax. so i used the other code i am able to succed in that but problem is when i click the cancel button i am not able t make the field value as null..

    my code is:

    <input type="submit" name="Submit1" onclick="return confirm('Are you sure want to Entry the menu item?')" value="Add Menu Item" />

    php code:

    <?

    if(isset($_POST['Submit1'])=="Add Menu Item")

    {

    perform db opeartion

    }

    else

    {

    here my textbox value shoul be null

    }

    ?>

    when i click submit button i can get confirm box wth ok nd cancel option..ok s workng fine but when i click on cancel the value wh i enter in the text box is not disppearng.. hw can i make it null..help me
    Copy linkTweet thisAlerts:
    @JunkMaleAug 14.2009 — Can you please use the "FORUM TAGS" for your code, it makes life alot easier and it makes your code readable.

    [code=php]<?
    if(isset($_POST['Submit1'])=="Add Menu Item")
    {
    perform db opeartion
    }
    else
    {
    here my textbox value shoul be null
    }

    ?>[/code]

    Which is easier to read your code.

    Where is your AJAX code? Where is the processing form script?
    ×

    Success!

    Help @prathikanoe spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...