Jump to content

Newbie question - populating SQL data


Rhawn

Recommended Posts

I am creating an outlink .php file.  Users are linked to my .php file, which sends them to another link.

I am trying to pull some data into a database I made.  The database is created, the table is name kw_track.  It has 3 columns: Site, Timestamp, Keyword.

Here is some code I copied and altered, but does not work.  It is not inserting any data into the table.

[code]
<php>
header("Location: http://www.outsidelink.com/");
?>

$now=time();
$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database name");
$res = mysql_query("INSERT INTO `kw_track` (`Website`, `Time_Stamp`, `Keyword`)VALUES ('$site', '$now', '$keywordvar')",$dbh);
[/code]

The values $site and $keywordvar are hopefully passed from the original link.

Any help is appreciated
Link to comment
Share on other sites

If there past by a query string, then they are $_GET type variables, so you need to assign them using $_GET


[code]$now = time ();

mysql_connect ( 'localhost', 'username', 'password' ) or die ( 'I cannot connect to the database because: ' . mysql_error () );
mysql_select_db ( 'database' );
mysql_query ( "INSERT INTO kw_track VALUES ( '" . mysql_real_escape_string ( $_GET['site'] ) . "', '" . $now . "', '" . mysql_real_escape_string ( $_GET['keywordvar'] ) . "' );" );[/code]


printf
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.