How do I post a string to a MySQL database with PHP? -
i trying write simple application, allows me post simple string mysql database. error. doing wrong here? here attempt:
<?php $servername = "xxxx.awardspace.net"; $username = "xxx"; $password = "xxx"; $dbname = "xxx"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "insert tokens (`token`) values (". $_post["token"].")"; if ($conn->query($sql) === true) { echo "new record created successfully"; } else { echo "error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>
when request:
curl -i -x post \ -h "content-type:text/plain" \ -d \ 'token=neverlucky' \ 'http://myurl.mygamesonline.org/?token=teststring123'
it returns:
error: insert tokens (
token
) values ()
column count doesn't match value count @ row 1
my mysql table have single column named token , type varchar (200)
simply make $token=$_post['token'];
, insert so:
$sql = "insert tokens (`token`) values ('$token')";
Comments
Post a Comment