Jump to content

Joining the two


paulman888888

Recommended Posts

I have my php script that sends data to mySQL and i would like to also send the date (and time if its easy) and IP address.

 

<?php
// Insert a row of information into the table "example"
mysql_query("INSERT INTO example 
(name, score) VALUES('" . mysql_real_escape_string(substr($_GET['name'], 0, 13)) . "', '" . mysql_real_escape_string($_GET['score']) . "')") 
or die('Theres an error.# Please try again.#');  
echo "Score Uploaded!#";
?>

 

and this is my other page

<?php
if($_SERVER['HTTP_X_FORWARD_FOR'])
{
    $ip = $_SERVER['HTTP_X_FORWARD_FOR'];
}
else
{
    $ip = $_SERVER['REMOTE_ADDR'];
}

mysql_query("INSERT INTO ips (ip) VALUES ('{$ip}')");
?>
<?php
$today = date("m.d.y"); 
mysql_query("INSERT INTO date (date) VALUES ('{$today}')");
?>

I would like all the information to go into the same database.

Please help.

Link to comment
https://forums.phpfreaks.com/topic/108158-joining-the-two/
Share on other sites

Well first off you need to have the columns in the table for it...

 

 

So instead of 3 tables you would have 1 table with 4 colums (or more) -- name, score, ip, date (date_time)

 

then do...

 

$sql = "INSERT INTO example SET

name = '".$name."',

score = '".$score."',

ip = '".$ip."',

date_added = now()";

mysql_query($sql);

 

and there ya go...  it would add all of them into the same table.

 

Link to comment
https://forums.phpfreaks.com/topic/108158-joining-the-two/#findComment-555002
Share on other sites

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.