paulman888888 Posted May 31, 2008 Share Posted May 31, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/108158-joining-the-two/ Share on other sites More sharing options...
GingerRobot Posted May 31, 2008 Share Posted May 31, 2008 Sorry, what's the problem? If you're inserting into 3 different tables then you have you to use 3 separate queries. Quote Link to comment https://forums.phpfreaks.com/topic/108158-joining-the-two/#findComment-554480 Share on other sites More sharing options...
radar Posted June 1, 2008 Share Posted June 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/108158-joining-the-two/#findComment-554557 Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 i would like all of them to go into the same table. But i dont know how please help Quote Link to comment https://forums.phpfreaks.com/topic/108158-joining-the-two/#findComment-554711 Share on other sites More sharing options...
radar Posted June 1, 2008 Share Posted June 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/108158-joining-the-two/#findComment-555002 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.