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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -