停止执行Php

时间:2015-07-01 16:44:24

标签: php mysql

我有这个代码,我试图使用javascript停止执行,但它不使用JavaScript,任何建议?我只是试图在javascript

返回错误时停止执行
if(mysql_num_rows($runzz)==0){

        echo "<p align='center'><font size='5'>This Item $code1 - $code2 - ".$rw2['description']. "</br></br> Doesn't Exist In The <u><b>".$rowto['name']."</b></u></br></br> Wanna Add IT ?</font></p>";

    ?>
<script>
function check(){
var r = confirm("Press a button!");
if (r == true) {
   return true;
} else {
   return false;
}
}
check();
</script>
<?php   
    }
$insert="INSERT INTO transfercopy(warehouseidfrom,warehouseidto,qty,itemid,uid)VALUES('$from','$to','$qty','$codeid','$uid')";
$run=mysql_query($insert,$con);
if(!$run)die("error".mysql_error());

1 个答案:

答案 0 :(得分:1)

我正在添加示例代码,以便您了解如何使用AJAX Call。

<?php
if(mysql_num_rows($runzz)==0){

echo "<p align='center'><font size='5'>This Item $code1 - $code2 - ".$rw2['description']. "</br></br> Doesn't Exist In The <u><b>".$rowto['name']."</b></u></br></br> Wanna Add IT ?</font></p>";

?>
<script>
    function check(){
        var r = confirm("Press a button!");

        if(r) {
            // Add additional parameter
            // You could use POST method too. Use whatever make sense to you. 
            var urlLink = 'http://www.example.com/warehouse/record.php?from=<?php echo $from?>&to=<?php echo $to?>';

            $.ajax({
                type: 'GET',
                url: urlLink,
                success: function(data) {
                    if(data == 'success') {
                        return 'You have successfully added new record!';   
                    }
                },
                error: function(data) {
                    console.log(data);
                }
            });
        } else {
         return false;   
        }
    }
   check();
</script>
<?php } ?>

<?php
// -- New File: record.php File 
//    
// You might wanna add the check, that it's the legit request and all the PHP Validation

$form = $_GET['from'];
$to = $_GET['to'];
$qty = $_GET['qty'];
$codeid = $_GET['codeid'];
$uid = $_GET['uid'];

$insert="INSERT INTO transfercopy(warehouseidfrom,warehouseidto,qty,itemid,uid)VALUES('$from','$to','$qty','$codeid','$uid')";
$run=mysql_query($insert,$con);
if(!$run) die("error".mysql_error());
else return 'success';

?>