无法在PHP文件中执行Javascript代码

时间:2015-09-07 10:00:45

标签: javascript php

我有一个将数据输入mysql数据库的php文件。现在我想在成功插入数据后显示一条javascript消息。但是我无法执行javascript代码。

以下是我的代码。



<html>
    <head>
       <title></title>

       <script type="text/javascript">
            function run(){
                alert("Data Inserted Successfully");
            }
    </script>
</head>
<body>
<?php 

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "datacentre";


$first=$_POST['firstname'];//this values comes from html file after submitting 

$last=$_POST['lastname'];

$dept= $_POST['department'];

$unit= $_POST['unit'];

$request=$_POST['request'];

$purpose=$_POST['purposebuttons']; 

$accessedby = $_POST['personbuttons'];

 $description=$_POST['description']; 

$accessdate = $_POST['date-time'];


/* Get Current Date and Time for the bookking_time field */
$booking_time=new DateTime();
$booking_time = $booking_time -> format("Y-m-d H:i:s");


// Create connection
$con = new mysqli($servername, $username, $password, $dbname , 3306);
    

if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}  

 //mysql_select_db("$database", $con);
 $sql= "INSERT INTO data_centre_users (first_name,last_name,department, unit, request, purpose , accessed_by, 

description,booking_time,access_time)
VALUES ('$first','$last','$dept', '$unit','$request','$purpose', '$accessedby' ,'$description', NOW() , '$accessdate')"; 

if ($con->query($sql) === TRUE) {

  /* Calling the javascript code */
    echo '<script> run(); </scrit>';
} else {
    echo "Error: " . $sql . "<br>" . $con->error;
}

$con->close();

 ?>
</body>
</html>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:0)

脚本结束标记拼写错误。更新如下:

echo '<script> run(); </script>';

答案 1 :(得分:0)

检查Application Context

的拼写
#include <stdio.h>

int main() {

    int ret = fork();
    if(ret == 0)
    {
            char *params[4]  = {"/bin/ls", "-l",0}; //cmd params filled

            int res = execv( "/bin/ls" , params);  //parameters for cmd
            //int res = execv( "/bin/ls" , NULL);  //this is fail case (when child-exit with -1 status can be seen)
            printf("\n child exiting (%d) .. \n", res); //on successful execution of cmd, this exit never appears
        }
        else
        {
            waitpid(ret,1,0);
            printf("parent exiting\n");
    }

    return 1;
 }

这将是

private void TransferFile(string _sFileName, string _sIPAdress)
        {
            List<Byte> bFileBuffer = File.ReadAllBytes(_sFileName).ToList();


            byte[] bFileName = Encoding.ASCII.GetBytes(_sFileName);
            bFileBuffer.InsertRange(0, bFileName);

            //Get the File name length, BitConvertor occupies the first 4 bytes
            byte[] brcvdDataCount = BitConverter.GetBytes((UInt32)_sFileName.Count());
            bFileBuffer.InsertRange(0, brcvdDataCount);


            //Open TCP/IP Connection
            TcpClient tcpClientSocket = new TcpClient(_sIPAdress, 8080);
            NetworkStream nsNetworkStream = tcpClientSocket.GetStream();
            nsNetworkStream.Write(bFileBuffer.ToArray(), 0, bFileBuffer.Count);
            nsNetworkStream.Close();

        }​​

答案 2 :(得分:0)

您拼写错误</scrit>必须是</script>

你可以试试这个:

   echo '<script> alert("Data Inserted Successfully"); </script>'