1

EDIT: Fred -ii-, I have been looking over the page you referenced to resolving my issue ( PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset") however I cannot see anything linked to Mmy question, could you please elaborate?

I've been trying to set my code so that once you click on a button it will update a field in my database, however it doesn't seem to do anything, I'm fairly new to php and any help would be greatly appreciated.

(Some of the connection information like $username has been changed to a more generic format).

<?php
$username = "username";
$password = "password";
$host = "localhost";
$db = $username;
$connection = connect($host, $username, $password, $db);

    if(isset($_POST["PSol"]))
    {
        $sql = "UPDATE MK1 SET Sol='Progress' WHERE id = 1";
        if (mysqli_query($connection, $sql)) {
            echo "success";
        } else {
            echo "Error: " . $sql . "<br>" . mysqli_error($connection);
        }

        mysqli_close($connection);
        echo "<p>Disconnected from server: ".$host."</p>";
    }
?>
<form action = "" method = "POST" name = "PSolCanvas" class = "PSolCanvas">
    <input name = "PSol" type = "button" class = "PSol" value = "P"/>
</form>
Community
  • 1
  • 1
C.Marks
  • 79
  • 1
  • 8
  • `->query()` calls will NEVER return a boolean true. they'll either return a boolean false (failure), or a statement handle (success). – Marc B Mar 22 '16 at 20:17
  • @MarcB Thanks for the advice, I have removed the if statement now it was only checking if it was a success or not, and it still doesn't work, I believe I've missed a step however can;t figure it out.. – C.Marks Mar 22 '16 at 20:47
  • if you had error handilng on your query call, you'd have been told you'r calling it incorrectly. the syntax is `mysqli_query($con, $sql)`. NEVER assume success with db calls. always have even at least bare bones error handling: `mysqli_query(...) or die(mysqli_error($connection));` – Marc B Mar 22 '16 at 20:55
  • Is this you *real* code? Are you *really* missing the action attribute on your form tag? Without an action, the form doesn't do anything. – Scott Mar 22 '16 at 21:01
  • @MarcB & Scott Thank you for your advice, I'm new to php and mysql have still need to learn the basics, I have edited my code however it still doesn't react when clicked.. – C.Marks Mar 22 '16 at 21:18
  • **The form action can't be blank**... it has to have a value. Either a different PHP script or, if you are trying to use the same php page, then `action=""` in order to make the form reference the existing page. If you don't have an action attribute the "POST" never happens... so the form does nothing. – Scott Mar 23 '16 at 01:14
  • @Scott Thank you for explaining, i'm still learning and know that I need to research a lot more! I managed to get it to work with yours and MarcB's help, i had to set the type from "button" to "submit".. so thank you! :) – C.Marks Mar 23 '16 at 17:07

0 Answers0