Weet iemand een goede tutorial hoe zo'n anti bot veld kan maken?
En die wil je niet vertellen? ;-)
Laat ook even zien wat je aan code hebt.
Dat helpt wat makkelijker.
Wat ik heb geprobeerd:
<?php
}else{// Captcha verification is Correct. Final Code Execute here!
$msg="<span style='color:green'>The Validation code has been matched.</span>";
}
}
?>
<?php
$msg= $sql;
$msg= "INSERT INTO students (name, _email, city)
VALUES ('".$_POST["name"]."','".$_POST["email"]."','".$_POST["city"]."')";
?>


Dit ondere is dan wat ik daarboven bij $msg heb ingevuld.
Waarom zet je die in $msg?
$msg is niets meer dan een container waar het bericht wordt geplaatst of de captcha goed/fout is.

Je kan na die $msg regel prima je queries uitvoeren.
Let wel op SQL-injection, als je $_POST, $_GET en en/of $_COOKIE variabelen gaat gebruiken.
Je kan het beste mysqli_real_escape_string() gebruiken in combinatie met de MySQLi-functies
Wat ben je allemaal aan het toveren Marcel :)

<?php

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
    // hier je controles formulier validatie e.d.

    // hier je CAPTCHA dingetje als alles klopt
          

    if($captcha === true)
    {
       // dit kan.
       $msg= "<span style='color:green'>The Validation code has been matched.</span>";  

       // nu kunnen we alles veilig doen.. hier alleen nog wel wat tegen SQL injection doen, want ander is dit lek
       $sql = "INSERT INTO students (name, _email, city)
                 VALUES ('".$_POST["name"]."','".$_POST["email"]."','".$_POST["city"]."')";

       // query uitvoeren

    }
}
?>


Als je $sql in $msg zet, dan kan je uren turen naar je scherm, maar dat doet ie niet.
(dubbel)


Toevoeging op 12/11/2015 17:15:50:

Dus ik kan al mijn php hier gewoon in zetten

<?php session_start();

if(isset($_POST['Submit'])){
// code for check server side validation
if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0){
$msg="<span style='color:red'>The Validation code does not match!</span>";// Captcha verification is incorrect.
}else{// Captcha verification is Correct. Final Code Execute here!
HIER
}
}
?>
Probeer het eens, en je weet het ;-)
Undefinded index student....

<?php session_start();

if(isset($_POST['Submit'])){
// code for check server side validation
if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0){
$msg="<span style='color:red'>The Validation code does not match!</span>";// Captcha verification is incorrect.
}else{// Captcha verification is Correct. Final Code Execute here!
$msg="<span style='color:green'>The Validation code has been matched.</span>";
$servername = "";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO students (student_name, student_email, student_city)
VALUES ('".$_POST["student_name"]."','".$_POST["student_email"]."','".$_POST["student_city"]."')";

if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}

$collection= array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
$fruit = array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
if(isset($_POST['submit']))
{ $fruit = $_POST['fruit'];
$values = array($collection);
foreach($collection as $selection )
{ if(in_array($selection, $fruit))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
} // end of foreach.

// MySQL statement.
$insert = "INSERT INTO table_fruit (orange, apple, grapefruit, banana, watermelon)
VALUES ({$values['orange']}, {$values['apple']}, {$values['grapefruit']}, {$values['banana']}, {$values['watermelon']})";
// MySQL statement to execute the INSERT statement above.
mysqli_query($conn, $insert) or die('<br/>Error reading database: '.mysqli_error($dbconnect));
mysqli_close($conn);
} // End of, if statement from the button check
;
}
}
?>

Je bedoelt student_name, student_email of student_city, ik zie geen index met de naam Students.

In dat geval bestaan die $_POST variabelen niet, omdat die formuliervelden niet bestaan.
Verder mis er beveiliging tegen SQL-injection en ben je nu behoorlijk goed hackbaar:

<?php
$sql = "INSERT INTO students (student_name, student_email, student_city)
VALUES(
'".$conn->real_escape_string($_POST["student_name"])."',
'".$conn->real_escape_string($_POST["student_email"])."',
'".$conn->real_escape_string($_POST["student_city"])."'
)";
?>

Ik krijg nu nog steeds undefinded index voor students. (het $sql heb ik veranderd naar die van jou)
Laat eens zien welke regel dat is? Die geeft PHP ook altijd door in foutmeldingen.

Reageren