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
Share on other sites

the code you got for ip should be okay... 

 

mysql_query("INSERT INTO ips set ip = '$_SERVER[REMOTE_ADDR]'");

 

and for date:

 

mysql_query("INSERT INTO date SET date = now()");

 

and it'll give you the date and time....

 

-- radar

 

 

Link to comment
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
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.