Jump to content

Recommended Posts

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  :rtfm:

Help?

Link to comment
https://forums.phpfreaks.com/topic/225856-an-error-with-a-very-simple-script/
Share on other sites

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" ; 
?>

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?

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>';

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.