I am trying to gather information via CURL and store that data in my database. I have setup my script as follows:
//extract data from the post
//set POST variables
$cookie_name = "drcuserid";
if(isset($_COOKIE[$cookie_name]))
{
$cookie = $_COOKIE[$cookie_name];
}
$url = 'http://dirtrif.loc/test.php';
$fields['username'] = $vbulletin->userinfo[username];
$fields['userid'] = $vbulletin->userinfo[userid];
$fields['email'] = $vbulletin->userinfo[email];
$fields['addontitle'] = $info['title'];
$fields['addonversion'] = $info['version'];
$fields['bburl'] = $vbulletin->options[bburl];
$fields['bbtitle'] = $vbulletin->options[bbtitle];
$fields['webmasteremail'] = $vbulletin->options[webmasteremail];
$fields['cookie'] = $_COOKIE[$cookie_name];
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
All of this data is exactly what I need to get, echoing out $fields_string
shows me all the data I requested, echoing $fields
shows me it is an array.
With that portion complete I endeavoured on my journey to store this data to my database. This is not stuff I am good at working with so I have been struggling every bit of the way, I have found numerous tutorials and videos but I just cant seem to get this to store the data.
My database is created within the install DB (for testing purposes), this is the query I ran to create my database:
CREATE TABLE IF NOT EXISTS drc_installs
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
userid INT UNSIGNED NOT NULL DEFAULT '0',
email varchar(255) NOT NULL,
addontitle varchar(255) NOT NULL,
addonversion varchar(255) NOT NULL,
bburl varchar(255) NOT NULL,
bbtitle varchar(255) NOT NULL,
webmasteremail varchar(255) NOT NULL,
cookie varchar(255) NOT NULL,
dateline INT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (id),
KEY userid (userid)
)
That all seems to be set up well.
So onto the text.php portion that is supposed to store this data. I've watched a couple tutorials on youtube, I've tried a few different tutorials. I am able to connect to my database, I'm just struggling to insert this data since the way the array returns is not like any of the tutorials I have seen.
After trial and error this is currently the contents of test.php:
$conn = mysqli_connect("localhost", "root", "password", "install") or die("Connection Error: " . mysqli_error($conn));
mysqli_query($conn, "INSERT INTO drc_installs (username,userid,email,addontitle,addonversion,bburl,bbtitle,webmasteremail,cookie) VALUES ('" . $fields['username']. "', '" . $fields['userid']. "', '" . $fields['email']. "', '" . $fields['addontitle']. "', '" . $fields['addonversion']. "', '" . $fields['bburl']. "', '" . $fields['bbtitle']. "', '" . $fields['webmasteremail']. "', '" . $fields['cookie']. "')");
I have played with things like:
if(isset($_POST['username']))
Yet only became more frustrated because I'm failing to comprehend what exactly I should be grabbing to store the data (and why). The end goal is just to store the data requested; each item into its own column in the database. Please help me see what I am failing to understand, this is all new to me.