Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help executing PHP file to write into SQL Table

    Hi all -

    I am relatively new to PHP coding and I am trying to write a program that inserts data into a SQL table. My code looks as follows.


    logCatcher.php



    Code:
    <?php
    
    //Connection Credentials
    $servername = "localhost";
    $username = "uname";
    $password = "pwd";
    $dbname = "sometable";
    
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    
    $sql = "INSERT INTO tabledata(timestamp,src,dst,user, agent, requestType, URL)
    VALUES ('Source','Destination','John', 'Doe', 'GET', 'http://www.google.com/')";
    
    if ($conn->query($sql) === TRUE) {
        $last_id = $conn->insert_id;
        echo "New record created successfully. Last inserted ID is: " . $last_id;
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    
    $conn->close();
    ?>

    I try to execute this on the server by writing a Batch file that looks something like this....

    Code:
    C:\php.exe" -f C:\logCatcher.php
    echo "Executed"
    But when I execute the Batch File nothing happens. No data is created in the database. Obviously there is no connection being made. Can you guide me as to what I am doing wrong?

    Thanks.

    SK

  2. #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    4,724
    Thanks
    15
    Thanked 497 Times in 492 Posts
    I doubt the " after php.exe is correct.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •