Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

HTML Form PHP action not working.

Options
  • 31-08-2015 9:22pm
    #1
    Banned (with Prison Access) Posts: 32,865 ✭✭✭✭


    Can anyone see what I'm doing wrong here? It's just a basic form that inserts values into a mysql database.

    I've tested the PHP separately in PHPStorm and it's working fine. But nothing happens when I click submit!

    Any help greatly appreciated.

    [HTML]<html>
    <head>
    <title>AMS</title>
    <link rel="stylesheet" type="text/css" href="ams.css">
    </head>
    <body>
    <form action="send_post.php" method="get">
    <div id="acc">
    Account Ref.<br>
    <input type="text" name="accref" size="12">
    <input type="checkbox" name="vat" value="vat"> VAT Exempt<br>
    </div>
    <p></p>
    <div id="reason">
    Adjustment Reason:<br>
    <select name="reason">
    <option value="0">Please Select A Reason</option>
    <option value="1">Reason 1</option>
    <option value="2">Reason 2</option>
    <option value="3">etc etc</option>
    </select>
    </div>
    <p></p>
    <div id="amount">
    Amount.<br>
    <input type="text" name="amount" size="7"/>
    </div>
    <p></p>
    <div id="submit">
    <input type="submit" name="submit"/> <input type="reset" name="reset"/>
    </div>
    </form>
    </body>
    </html>[/HTML][PHP]<?php
    //Connecting to sql db.
    $connect = @mysqli_connect(&quot;host","user","password","database");

    //error handling
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    //you need to exit the script, if there is an error
    exit();
    }

    //Sending form data to sql db.
    mysqli_query($connect,"INSERT INTO adjustments (reason_id, account_no, amount)
    VALUES ('$reason', '$accref', '$amount')")
    ?>[/PHP]


Comments

  • Registered Users Posts: 291 ✭✭Seridisand


    try changing to post

    <form action="send_post.php" method="post">


  • Banned (with Prison Access) Posts: 32,865 ✭✭✭✭MagicMarker


    Good spot, not joy though! It was post initially and I changed it to get to see if that worked, forgot to change it back!

    Thanks though.


  • Registered Users Posts: 291 ✭✭Seridisand


    It could be a lot of things
    I assume there's more code where you provide the connection details?
    Can you test that you can connect to the database with those credentials?
    Does your import statement work if you try to manually insert into the db using an ide?
    Does the table/database/column (count/name(s)) match?
    Any sort of stack trace?
    Why are you using so many empty <p></p> tags?


  • Registered Users Posts: 63 ✭✭ThrowinShapes


    Perhaps you're doing it elsewhere, but just from the code you've supplied I can't see how you're collecting that information that's being posted to your PHP file.

    If this is the case, then try adding this somewhere in your PHP file before your INSERT statement:

    [PHP]
    $reason = $_REQUEST;
    $accref = $_REQUEST;
    $amount = $_REQUEST;
    [/PHP]


  • Banned (with Prison Access) Posts: 32,865 ✭✭✭✭MagicMarker


    I discovered the issue, I'm just opening the php file just in the browser rather than using the actual webserver, so I changed the action to...

    [HTML]<form action="http://localhost:81/ams/send_post.php&quot; method="post">[/HTML]

    I'm using WAMP stack, and my files are saved down in the apache2 htdocs folder. I had assumed just having the file name as the action would work. Where would I need to save my files for that to be the case? Tis awfully confusing!

    edit: Ah, I see I just need to open my index file in the webserver initially, which would mean I wouldn't have to use the full path for the action.
    Perhaps you're doing it elsewhere, but just from the code you've supplied I can't see how you're collecting that information that's being posted to your PHP file.

    If this is the case, then try adding this somewhere in your PHP file before your INSERT statement:

    [PHP]
    $reason = $_REQUEST;
    $accref = $_REQUEST;
    $amount = $_REQUEST;
    [/PHP]

    Yes, thank you, that helps a lot. This would have been my next problem had you not mentioned it! Thanks a mill.


  • Advertisement
  • Registered Users Posts: 6,150 ✭✭✭Talisman


    You can avoid such nightmares by using a virtualised environment for development. Take a look at Scotch Box, their preconfigured Vagrant Box will provide you with a complete LAMP Stack.


Advertisement