Hangwire Posted January 27, 2011 Share Posted January 27, 2011 Hi everybody, my goal is to get the IP of someone accesing the site, writing the time and date along with his IP into the database. Of course, I would be adding the script to my frontpage when I make it work. But I get this error: Parse error: syntax error, unexpected T_VARIABLE in D:\Program Files\xampp\xampp\htdocs\script1.php on line 8 I've checked line 8, I dont find anything in it that is out of place. Here is the code: <?php $ip = $_SERVER['REMOTE_ADDR']; $date = date("m.d.y"); $time = time(); mysql_connect ("localhost", "root", "********") or die ('Error: '. mysql_error()); mysql_select_db ("ip"); $query = "INSERT INTO ipdo (time, date, ip) VALUES ('"$time"', '"$date"', '"$ip"')"; mysql_query($query) or die ('Error updating database'); echo "Database updated with: " .$ip. "" ; ?> This is the first script I write entirely on my own, so be gentle Help? Quote Link to comment https://forums.phpfreaks.com/topic/225856-an-error-with-a-very-simple-script/ Share on other sites More sharing options...
spaceman12 Posted January 27, 2011 Share Posted January 27, 2011 try this <?php $ip = $_SERVER['REMOTE_ADDR']; $date = date("m.d.y"); $time = time(); $connect=mysql_connect ("localhost", "root", "********") or die(mysql_error()); mysql_select_db("ip", $connect); $query = "INSERT INTO ipdo (time, date, ip) VALUES('$time', '$date', '$ip')"; mysql_query($query) or die (mysql_error()); echo "Database updated with: $ip" ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/225856-an-error-with-a-very-simple-script/#findComment-1165990 Share on other sites More sharing options...
Hangwire Posted January 27, 2011 Author Share Posted January 27, 2011 Thank you, worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/225856-an-error-with-a-very-simple-script/#findComment-1166104 Share on other sites More sharing options...
Hangwire Posted January 27, 2011 Author Share Posted January 27, 2011 I don't want to create a thread about another simple problem, but here it is... <?php $name = $_POST['name']; $pass = $_POST['pass']; // $ip = $_SERVER['ip']; mysql_connect ("localhost", "root", "****") or die ('Error: '. mysql_error()); mysql_select_db ("data"); $query="INSERT INTO data (name, pass) VALUES ('".$name."', '".$pass."')"; mysql_query($query) or die ('Error updating database'); In this case, the script only writes the name in the database, but not the pass. The database fields are identical, both being varchar's. So, what gives? Quote Link to comment https://forums.phpfreaks.com/topic/225856-an-error-with-a-very-simple-script/#findComment-1166233 Share on other sites More sharing options...
jcbones Posted January 27, 2011 Share Posted January 27, 2011 Variables are parsed in a double quoted string. In a single quoted string, they are not. So your query: $query="INSERT INTO data (name, pass) VALUES ('".$name."', '".$pass."')"; Could be: $query="INSERT INTO data (name, pass) VALUES ('$name', '$pass')"; Not that it is wrong, the way you have it written, but this could save you time in the future. As to why you don't have a populated $pass parameter. Have you checked to make sure that $_POST['pass'] is set? Or, is your input from your form named 'password'?. To check, put this at the top of the page, it will tell you all the post variables, and what their names are. echo '<pre>'; print_r($_POST); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/225856-an-error-with-a-very-simple-script/#findComment-1166281 Share on other sites More sharing options...
Hangwire Posted January 27, 2011 Author Share Posted January 27, 2011 Thank you for your time, I fixed it myself. It was a very stupid error on my behalf, in the html input form I put the of it as "password", but $_POST was looking for "pass". Fixed it and everything works like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/225856-an-error-with-a-very-simple-script/#findComment-1166293 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.