Here is my PHP code, I guess the problem is with $_POST[...]
?
PHP:
<?php
require('connect.php');
$name = $_POST['name'];
$comment = $_POST['comment'];
$submit = $_POST['submit'];
if($submit)
{
if($name&&$comment)
{
$query=mysql_query("INSERT INTO comment (id,name,comment) VALUES ('','$name','$comment')");
header("Location: success.php");
}
else
{
echo "Lūdzu aizpildi visus logus.";
}
}
?>
The form of fields and textarea.
HTML:
<form action="help-add-comment.php" method="POST">
<label>Jūsu vārds: </label><br /><input type="text" name="name" size="25" value="<?php echo "$name" ?>" /><br /><br />
<label>Ziņojums: </label><br /><textarea name="comment" cols="25" rows="7"></textarea><br /><br />
<input type="submit" class="button button-red" name="submit" value="Pievienot" /><br/>
</form>
This is my result:
You're trying to access non-existent fields in the
$_POST
array, the warning is correct. You should only process those fields when they're actually there, so when you're actually responding to a form postback, by checking the request method:Note that this still allows a malicious user to trigger the warnings, and thus gain knowledge of your application internals, by faking a request. You can fix this by retrieving the POST values safely:
You can achieve the same effect by using the error suppression operator (
@
) but it's bad for performance and considered bad style for simple cases like this.