I have a problem with the default value for $ _POST []; So, I have an html form with text fields, and the information is sent to a php script. The PHP script has a sql query that is sent to my database. But if my html text file is empty, the request doesn't matter. So I want my message to be assigned a default value of 0, so it returns a value at least.
So here is an example html form (this is not my script application). Just an example.
<form action="testscript.php" method="POST">
<input type="id" name="ID"/>
<input type="text" name="test"/>
<input type="submit" value="Send"/>
</form>
Ok, so this script will send both identifiers and the test text fields will always have a numeric value. And it sends the information to testcript.php
Here is an example testcript.php
$conn = mysqli_connect('host', 'dbuser', 'dbpass', 'dbname');
$id = $_POST['id'];
$test = $_POST['test'];
$sql = "INSERT INTO test_table (id, test) VALUES ($id, $test)";
if (mysqli_query($conn, $query)) {
echo "Success";
} else {
echo "Failed" . mysqli_error($conn);
}
, , html php script , :
INSERT INTO test_table (id, test) VALUES ( , )
:
INSERT INTO test_table (id, test) VALUES (0, 0)
. , value html, , .
, , statment ,
if (isset($_POST['test'])) {
$test = $_POST['test'];
} else {
$test = 0;
}
, , statment html- 100 . , statment , script , .
, , statment php value html?