I’ve been getting better at PHP – but I have NO idea what I’m doing when it comes to MySQL.
I have a code
<a href="http://www.example.com/test.php?for=abcde&affi=12345&reff=foo"><IMG></a>
I need to grab the “for”, “affi” and “reff” and input them into a database
//Start the DB Call
$mysqli = mysqli_init();
//Log in to the DB
if (!$mysqli) {
die('mysqli_init failed');
}
if (!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
die('Setting MYSQLI_INIT_COMMAND failed');
}
if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
if (!$mysqli->real_connect('localhost', 'USERNAME', 'PASSWORD', 'DATABASE')) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
That’s what I’m using to create a connection. It works. I’ve also got a table created, call it “table”, with rows for “for”, “affi”, and “reff”.
So my question is… someone gets directed to http://www.example.com/test.php?for=abcde&affi=12345&reff=foo
Now that I’ve got a DB connection open – how do I SEND that data to the DB before redirecting them to their destination site? They click – pass across this page – get redirected to destination.
BONUS KARMA – I also need a separate PHP file that I can create that PULLS from that data base. If you could point me at some instructions or show me a simple “how to pull this rows values from this table” I would be greatly appreciative 🙂
If I understand correctly, you’ll want to use $_GET to get the URL parameters.
Then you want to run an insert query on the db with the values you got, which should be something like:
Then you need to change the page using a location header.
For the bonus question you just need the code you have now with a select query like:
and then fetch the query results.
If this does not answer your questions please provide some clarifications.