Update Confirmation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bluirish 11
    New Member
    • Oct 2011
    • 2

    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..t his is my code..
    Code:
    <?php
    if(isset($_POST['upload'])){
    	if($_FILES['file']['name'] == "") {
    ?>
    <script type="text/javascript" >
    alert("Please specify a file to upload.");
    window.location = "uploadExam_part1.php";
    </script>
    <?php		
    		}
    	else {
    		include "config.php";	
    		$sel = "SELECT * from questionpart1";
    		$result = mysql_query($sel);
    		
    		if(mysql_num_rows($result) > 0) {
    ?>
    <script type="text/javascript">
    		var check = confirm("Are you sure you want to replace the questions?");
    		if(check) {
    		  //i don't know what to do in here
    		}
    			else {
    			//and in here		
    			}
    		
    </script>
    <?php
    			}	
    
    
    require_once('DB.php');
    
    
    
    $data = array();
    
    
    
    $db =& DB::connect("mysql://root@localhost/aptitude", array());
    
    if (PEAR::isError($db)) { die($db->getMessage()); }
    
    
    function add_person( $type, $question, $choice1, $choice2, $choice3, $choice4, $answer )
    
    {
    
     global $data, $db;
    
    
    
     $sth = $db->prepare( "INSERT INTO questionpart1 VALUES(0, ?, ?, ?, ?, ?, ?, ? )" );
    
     $db->execute( $sth, array( $type, $question, $choice1, $choice2, $choice3, $choice4, $answer ) );
    
    
    
     $data []= array(
       'type' => $type,
    
       'question' =>$question,
    
       'choice1' => $choice1,
    
       'choice2' =>  $choice2,
    
       'choice3' =>  $choice3,
    
       'choice4' => $choice4,
    
       'answer' => $answer
    
     );
    
    }
    
    
    
    if ( $_FILES['file']['tmp_name'] )
    
    {
    
     $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
    
     $rows = $dom->getElementsByTagName( 'Row' );
    
     $first_row = true;
    
     foreach ($rows as $row)
    
     {
    
       if ( !$first_row )
    
       {
         $type = "";
    
         $question = "";
    
         $choice1 = "";
    
         $choice2 = "";
    
         $choice3 = "";
    
         $choice4 = "";
    
         $answer = "";
    
          
    
         $index = 1;
    
         $cells = $row->getElementsByTagName( 'Cell' );
    
         foreach( $cells as $cell )
    
         {
    
           $ind = $cell->getAttribute( 'Index' );
    
           if ( $ind != null ) $index = $ind;
    
    
           if ( $index == 2 ) $type = $cell->nodeValue;
    
           if ( $index == 3 ) $question = $cell->nodeValue;
    
           if ( $index == 4 ) $choice1 = $cell->nodeValue;
    
           if ( $index == 5 ) $choice2 = $cell->nodeValue;
    
           if ( $index == 6 ) $choice3 = $cell->nodeValue;
    
           if ( $index == 7 ) $choice4 = $cell->nodeValue;
    
           if ( $index == 8 ) $answer = $cell->nodeValue;
    
    
    
           $index += 1;
    
         }
    
         add_person(  $type, $question, $choice1, $choice2, $choice3, $choice4, $answer  );
    
       }
    
       $first_row = false;
    
     }
    
    }
    }
    }
    
    ?>
    Any help will be greatly appreciated..
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    Working...