Jump to content

trying to get a popup to work...


texmansru47

Recommended Posts

I have a javascript popup as an error in a php if (isset verification).  I cannot tell whether or not the loop is working incorrectly or the popup is just not being called.  from the code it appears to be working (the if (isset verification)) since the work I ask to be completed if the response from the if (isset) loop is false, then write the record into the proper table and that is not happening.

 

So is there someone out there who can verify my javascript for the popup is correct or provide a means of validating my code in a test I would be grateful.

 

Here is the code:

 


<?php
if (isset($_GET['param1']) && !empty($_GET['param1'])){
    $prod=$_GET['param1'];     
    echo "Your Prod Number is:\n$prod"; }
    elseif ($_SERVER['REQUEST_METHOD'] == 'POST'){    
    $imei=$_POST['param1']; 
    echo "Your Bloody Prod Number is:\n$prod";    
           
// Main PHP code for connecting to the database for production processing
$con = mysql_connect("localhost","user","xxxxxx") or die('Connection: ' . mysql_error());;
mysql_select_db("logdata", $con) or die('Database: ' . mysql_error());

//SQL query for is the Prod Num was completed fine, this will populate the PROD table accordingly.

// This query is to generate values for validation.
$grabit = "SELECT * FROM `Prod` WHERE `ProdNum` = '$prod";
$testdata = mysql_query($grabit) or die(mysql_error());
$testit = mysql_fetch_assoc($testdata) or die(mysql_error()); 

print_r('$testit');  ?? I get nothing from this command - It may be due to when I click submit the form is scheduled to close, and the information is not displayed.

// variables from the SELECT Query
$done=$testit['PassGood'];
$batch=$testit['BatchNum'];
$sku=$testit['ModelSku'];
$type=$testit['ModelType'];
$model=$testit['ModelNum'];
$card=$testit['CardType'];
$notes=$_POST['undernotes'];

// variables for this section only!
$qc =$_POST['qcstatus'];
$Diag = 'Passed';
$ota =$_POST['TestResults'];

// Test loop of the data inputted to verify the data inputted into the table.  This is where I try to validate if a record for that Prod Num exists or not - not getting the error message at all.
if (isset($done)) {
    ?>
    <head>
    <script language="JavaScript">
    alert("This Unit has been passed as ALL GOOD.  Please forward to Kitting.");
    </script>
    </head>
    <?php
    } else {
    mysql_query("INSERT INTO `ProdHist` SELECT * FROM `Prod` WHERE `ProdNum` = '$prod") or die(mysql_error());  //but this portion of the code is not working when I put in a Prod Number that is already in the table.
    
    // Notify the User that the record is being copied to the ProdHist Table.
    print "<p>This record was updated in the History Table.</p>";
    
    // Insert the new data for this record in the main Prod Table.  This code is also not working when there is a duplicate record in the table.
    mysql_query("UPDATE `Prod` 
                Set `Diagnositc` = '$Diag'
                Set `TestResults` = '$ota'
                Set `undernotes` = '$notes'
                Set `DateRep` = Now()
                WHERE `ProdNum` = '$prod'") or die(mysql_error());
            @mysql_query("DELETE FROM `Prod` WHERE `ProdNum` = 0"); 

mysql_close($con);
}
}
?>	

<body bgcolor="#CCCCCC">

<P>
<BODY OnLoad="placeFocus()">

<!-- This section will create the form for the "all Good" Unit popup window. -->
<form method="post" name="prod" action="repair.php"><font color="#000080" face="Arial">
<input type="hidden" name="param1" value="<?php echo $imei; ?>" />  
<p><u><b><font size="2" font color="maroon" font type="Tahoma">Repair Section:</font></b></u></p>
<p><font face="Arial" font size="2">
  	<b>OTA Pass/Fail:   <select name="TestResults" size="1" name="TestResults">
<option value="NULL">--</option>
<option value="Passed">Passed</option>
<option value="Failed">Failed</option>
</select></b></font>    <font face="Arial" font size="2">
<td <font color="Navy" size="3" face="Tahoma"><b><u>Notes:</u>   </b></font></td>        
     <td><input name="undernotes" type="text" id="undernotes" size="35">
<p align="center">
<input type="submit" value="Repair Data Submit" name="submit" onclick="window.close()"></p>
</form>	

 

So when I have a duplicate Prod Num the php code seems to be working... there is no INSERT or UPDATE being processed.  I will be testing more on the results of a unique Prod Number being entered as well.

Link to comment
Share on other sites

Remember to only have one <body> and to put all content for display on the page inside it.

 

If PassGood exists in any way, shape or form in $testit then isset will always evaluate to true. A SQL query will probably be returning a value for PassGood, even if it is only an empty value. Try looking at the output of print_r($testit) (note lack of quotation marks around $testit!) to check whether the isset($done) really is working.

 

Link to comment
Share on other sites

Well I got the error message to work the problem is I had to take on the following command to see it:

<input type="submit" value="Repair Data Submit" name="submit" onclick="window.close()"></p>

 

Is there a way to have the error message pop up when the submit button is click, but also shutdown window as well... like a time delay or something?

 

Here the code again:

 

<?php
if (isset($_GET['param1']) && !empty($_GET['param1'])){
    $imei=$_GET['param1'];     
    echo "Your Prod Number is:\n$prod"; 
    }
    elseif ($_SERVER['REQUEST_METHOD'] == 'POST'){    
    $imei=$_POST['param1']; 
    // echo "Your Bloody Prod Number is:\n$prod";    
           
// Main PHP code for connecting to the database for production processing
$con = mysql_connect("localhost","user","xxxxxxx") or die('Connection: ' . mysql_error());;
mysql_select_db("logdata", $con) or die('Database: ' . mysql_error());

//Initial search and selection.
    $grabit = "SELECT * FROM `Prod` WHERE `ProdNum` = '$prod";
    $testdata = mysql_query($grabit) or die(mysql_error());
    $testit = mysql_fetch_assoc($testdata) or die(mysql_error()); 
//SQL query for is the Prod Num was completed fine, this will populate the PROD table accordingly.

// This query is to generate values for validation.
echo "\nThere is a Completed Transaction for this Record in this table.";
// variables from the SELECT Query
$done=$testit['PassGood'];
$batch=$testit['BatchNum'];
$sku=$testit['ModelSku'];
$type=$testit['ModelType'];
$rts=$testit['RTSNum'];
$card=$testit['CardType'];
$notes=$_POST['undernotes'];

// variables for this section only!
$qc =$_POST['qcstatus'];
$Diag = 'Passed';
$ota =$_POST['TestResults'];

// Test loop of the data inputted to verify the data inputted into the table.
if (isset($done)) {
    ?>
    <head>
    <script language="JavaScript">
    alert("This Unit has been passed as ALL GOOD.  Please forward to Kitting.");
    </script>
    </head>
    <?php
    } else {
    mysql_query("INSERT INTO `Prod` (`BatchNum`,`ProdNum`,`ModelNum`,`Diagnostic`,`ModelSku`,`ModelType`,`CardType`,`TestResults`,`undernotes`,`DateRep`) 
VALUES ('$batch', '$prod','$modnum','$Diag','$sku','$type','$card','$ota','$notes', Now())") or die(mysql_error()); 
@mysql_query("DELETE FROM `Prod` WHERE `ProdNum` = 0"); 
    
    mysql_query("INSERT INTO `ProdHist` SELECT * FROM `Prod` WHERE `IMEINum` = '$prod'") or die(mysql_error());
    
    // Notify the User that the record is being copied to the ProdHist Table.
    print "<p>This record was updated in the History Table.</p>";
    
mysql_close($con);
}
}
?>	
<body>
<P>

<!-- This section will create the form for the "Repair" Unit popup window. -->
<form method="post" name="prod" action="repair.php"><font color="#000080" face="Arial">
<input type="hidden" name="param1" value="<?php echo $prod; ?>" />  
<p><u><b><font size="2" font color="maroon" font type="Tahoma">Under 30 Repair OTA Section:</font></b></u></p>
<p><font face="Arial" font size="2">
  	<b>OTA Pass/Fail:   <select name="TestResults" size="1" name="TestResults">
<option value="NULL">--</option>
<option value="Passed">Passed</option>
<option value="Failed">Failed</option>
</select></b></font>    <font face="Arial" font size="2">
<td <font color="Navy" size="3" face="Tahoma"><b><u>Notes:</u>   </b></font></td>        
     <td><input name="undernotes" type="text" id="undernotes" size="35">
<p align="center">
  <input type="submit" value="Repair Data Submit" name="submit"></p> 
    </td>
</body>
</form>	

 

I desire the popup form to be closed when the user clicks submit, but the error message to popup even if the form is closed... OR Have the error message popup when the SUBMIT button is clicked and when the OK button on the error message is clicked both the form and message go away.  The only problem is what if the user enters in a value that is not in the table and the ELSE option kicks in.  Currently, without the onclick=windows.close() function, the form remains.  If I put the function back in the error message and form disappear so the user has no idea what transpired. 

 

I guess I would like my cake and eat it too!

 

Any ideas what I'm doing wrong?

 

thanks,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.