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
https://forums.phpfreaks.com/topic/35148-newbie-question-populating-sql-data/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.