Forum Moderators: phranque
Can I do this? The idea is read in data from post.txt and do a MySQL insert to a table.
I plan to use ab tool to do some testing.
$ab -p ./post.txt [mdd...]
$ cat insert.php
<?php
$mysqli = mysqli_connect("localhost", "joeuser", "somepass", "testDB");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "INSERT INTO testTable (testField) VALUES ('".$_POST["testfield"]."')";
$res = mysqli_query($mysqli, $sql);
if ($res === TRUE) {
echo "A record has been inserted.";
} else {
printf("Could not insert record: %s\n", mysqli_error($mysqli));
}
mysqli_close($mysqli);
}
If I replace _POST to _GET here, that will work.
$ab [mdd...]
$ cat insertget.php
<?php
$mysqli = mysqli_connect("localhost", "joeuser", "somepass", "testDB");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$testfield = $_GET['testfield'];
$sql = "INSERT INTO testTable (testField) VALUES ('".$testfield."')";
echo $sql ;
$res = mysqli_query($mysqli, $sql);
if ($res === TRUE) {
echo "A record has been inserted.";
} else {
printf("Could not insert record: %s\n", mysqli_error($mysqli));
}
mysqli_close($mysqli);
}
?>
[edited by: IQRules at 4:39 am (utc) on Oct. 16, 2008]