473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Update Confirmation

Hi,how can I use confirmation here..?
I want to check if there are records that exist in database using pop up confirmation..this is my code..
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['upload'])){
  3.     if($_FILES['file']['name'] == "") {
  4. ?>
  5. <script type="text/javascript" >
  6. alert("Please specify a file to upload.");
  7. window.location = "uploadExam_part1.php";
  8. </script>
  9. <?php        
  10.         }
  11.     else {
  12.         include "config.php";    
  13.         $sel = "SELECT * from questionpart1";
  14.         $result = mysql_query($sel);
  15.  
  16.         if(mysql_num_rows($result) > 0) {
  17. ?>
  18. <script type="text/javascript">
  19.         var check = confirm("Are you sure you want to replace the questions?");
  20.         if(check) {
  21.           //i don't know what to do in here
  22.         }
  23.             else {
  24.             //and in here        
  25.             }
  26.  
  27. </script>
  28. <?php
  29.             }    
  30.  
  31.  
  32. require_once('DB.php');
  33.  
  34.  
  35.  
  36. $data = array();
  37.  
  38.  
  39.  
  40. $db =& DB::connect("mysql://root@localhost/aptitude", array());
  41.  
  42. if (PEAR::isError($db)) { die($db->getMessage()); }
  43.  
  44.  
  45. function add_person( $type, $question, $choice1, $choice2, $choice3, $choice4, $answer )
  46.  
  47. {
  48.  
  49.  global $data, $db;
  50.  
  51.  
  52.  
  53.  $sth = $db->prepare( "INSERT INTO questionpart1 VALUES(0, ?, ?, ?, ?, ?, ?, ? )" );
  54.  
  55.  $db->execute( $sth, array( $type, $question, $choice1, $choice2, $choice3, $choice4, $answer ) );
  56.  
  57.  
  58.  
  59.  $data []= array(
  60.    'type' => $type,
  61.  
  62.    'question' =>$question,
  63.  
  64.    'choice1' => $choice1,
  65.  
  66.    'choice2' =>  $choice2,
  67.  
  68.    'choice3' =>  $choice3,
  69.  
  70.    'choice4' => $choice4,
  71.  
  72.    'answer' => $answer
  73.  
  74.  );
  75.  
  76. }
  77.  
  78.  
  79.  
  80. if ( $_FILES['file']['tmp_name'] )
  81.  
  82. {
  83.  
  84.  $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
  85.  
  86.  $rows = $dom->getElementsByTagName( 'Row' );
  87.  
  88.  $first_row = true;
  89.  
  90.  foreach ($rows as $row)
  91.  
  92.  {
  93.  
  94.    if ( !$first_row )
  95.  
  96.    {
  97.      $type = "";
  98.  
  99.      $question = "";
  100.  
  101.      $choice1 = "";
  102.  
  103.      $choice2 = "";
  104.  
  105.      $choice3 = "";
  106.  
  107.      $choice4 = "";
  108.  
  109.      $answer = "";
  110.  
  111.  
  112.  
  113.      $index = 1;
  114.  
  115.      $cells = $row->getElementsByTagName( 'Cell' );
  116.  
  117.      foreach( $cells as $cell )
  118.  
  119.      {
  120.  
  121.        $ind = $cell->getAttribute( 'Index' );
  122.  
  123.        if ( $ind != null ) $index = $ind;
  124.  
  125.  
  126.        if ( $index == 2 ) $type = $cell->nodeValue;
  127.  
  128.        if ( $index == 3 ) $question = $cell->nodeValue;
  129.  
  130.        if ( $index == 4 ) $choice1 = $cell->nodeValue;
  131.  
  132.        if ( $index == 5 ) $choice2 = $cell->nodeValue;
  133.  
  134.        if ( $index == 6 ) $choice3 = $cell->nodeValue;
  135.  
  136.        if ( $index == 7 ) $choice4 = $cell->nodeValue;
  137.  
  138.        if ( $index == 8 ) $answer = $cell->nodeValue;
  139.  
  140.  
  141.  
  142.        $index += 1;
  143.  
  144.      }
  145.  
  146.      add_person(  $type, $question, $choice1, $choice2, $choice3, $choice4, $answer  );
  147.  
  148.    }
  149.  
  150.    $first_row = false;
  151.  
  152.  }
  153.  
  154. }
  155. }
  156. }
  157.  
  158. ?> 
  159.  
Any help will be greatly appreciated..
Oct 7 '11 #1
1 1335
acoder
16,027 Expert Mod 8TB
If the check has already been made, add the confirmation when the user submits.

If you're making the database check after the page load, but want to display the confirmation before the page is submitted, you'll need to make an Ajax request.
Oct 13 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
4
by: Fred | last post by:
Hi. How does one display a confirmation message of either 'Record Updated' or 'Recorded Added"? I've tried the form afterupdate and afterinsert but the afterupdate occurs on an insert too? So...
5
by: Brandon Mackie | last post by:
I am incredibly new to access and trying to learn as I go. I have set up a few queries one of which is executed by a docmd.runsql in visual basic. Because it is an update query it asks for...
4
by: Stephen | last post by:
Hello People, Using MS Access 2003 VBA I get the error 3020 Update or CancelUpdate without AddNew or Edit when I run through the following code. Can anyone help suggest anything to try? Thanks....
2
by: Marc Robitaille | last post by:
Hello, I use a server side button to delete or update data in my database. To have a confirmation from the user I use this code that I have found here. cmdOk.Attributes.Add("OnClick", "return...
1
by: irene | last post by:
Hi, I am trying to update the checkbox value in a datagrid. I am using TemplateColumn to add the checkbox to the datagrid and it is showing correct data from the database now. Ideally, the end user...
0
by: Elton W | last post by:
Hi Peter, You use DeleteButton.Attributes.Add("onclick", "return confirm ('Are you sure you want to delete?');"); in datagrid_ItemDataBound event to add confirmation for delete button.
0
by: Simon Rigby | last post by:
Hi all, I was of the impression that setting the DefaultMode property of a FormView would force the EditMode back to the defaut mode after clicking update or cancel. However, the FormView stays...
2
by: rsht | last post by:
I am new to the ASP.Net and need some helps. In ASP, page one can have a button event "confirm()" to pop-up a yes or no window: <form ... action="page2" > .... <input onClick="confirm();">...
2
by: beemomo | last post by:
Hi everyone. I used the BeforeUpdate event procedure to display a confirmation prompt and handle a user's response to either cancel or continue with the save as described in MSDN: Private Sub...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.