I want someone to write a short piece of code storing query string data in a DB using wordpress
Before anything pops up in your mind, please und开发者_JAVA百科erstand that I am very new to PHP and to be honest, I am depending exclusively on stack overflow to build my simple and first php web application.
I am trying to get the data from a query string and store it in my database. I want someone to write a short piece of code to check whether the string exists and if it does, add it to my database. I am using wordprss so i think we can use $_GET and $wpdb but i don't know the syntax. The url with querystring is something like: http://www.mydomain.tld/?publishid=1235ABC
According to given address http://www.mydomain.tld/?publishid=1235ABC it would be something like below::
<?php
$input = isset($_GET['publishid']) ? $_GET['publishid'] : '';
if(!empty($input)) {
$query = "INSERT INTO table (input_field) VALUES ('$input')";
mysql_query($query);
}
?>
Something like this would check if the publishid exists in the GET variable. The rest depends on which database you are using, and what do you want to do if it doesn't exist.
if(!isset($_GET['publishid']))
{
//Do whatever you want if the key does not exists
}
else
{
//Insert into the database.
}
love the answers from (bariz and Nobita) and love this little modification
<?php
if(!empty($_GET['publishid'])) {
$input = $_GET['publishid'];
$query = "INSERT INTO table (input_field) VALUES ('$input')";
mysql_query($query);
}
?>
精彩评论