CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Custom INSERT into SQL with IP Address

Print topic Send  topic

Author Message
sorinbuda

Posts: 27
Posted: 06/13/2010, 1:17 PM

What is the right syntax to do something like that in PHP?

Res = CCExecSQL ("INSERT INTO bla_track VALUES ('" & Request.ServerVariables("REMOTE_HOST") & "',1,1,DATEADD( hh , +3, GETDATE()) );", Conn, true) 

I found the code above at
http://forums.yessoftware.com/posts.php?post_id=73107


Thank you in advance,
Sorin
View profile  Send private message
magus

Posts: 98
Posted: 06/14/2010, 4:22 AM

Hi,

{

$db = new clsDBdatabasename();

$SQL = "INSERT INTO bla_track (column_name1,column_name2,column_name3,column_name4) ".
"VALUES (". $db->ToSQL($_SERVER['REMOTE_HOST'],ccsText) .", 1, 1,". time() .")";

$db->query($SQL);
$db->close();

}


Will probably work when you name your columns. It inserts the current unix timestamp. For other date formats look up the date() function in the php manual.

Regards,
Don A
View profile  Send private message
sorinbuda

Posts: 27
Posted: 06/14/2010, 6:06 AM

Something does not work:

   
{  
  
  $db = new clsDBdbname();  
  $SQL = "INSERT INTO tablename (ip) ".   
         "VALUES (". $db->ToSQL($HTTP_SERVER_VARS["REMOTE_HOST"],ccsText)  .")";  
  
  $db->query($SQL);  
  $db->close();  
    
}  
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 06/15/2010, 5:05 PM

sorinbuda,
Is (ip) suppose to be a variable?? If it is then it should be $ip.

Also, you could echo out the generated query to make sure that it is correctly being generated (just an suggestion).
View profile  Send private message
magus

Posts: 98
Posted: 06/16/2010, 9:36 AM

Hi,

What doesn't work is that you are using double quotes for two separate purposes in a single statement.

Use single quotes around REMOTE HOST and you should see an improvement.

Regards,
Don A
View profile  Send private message
sorinbuda

Posts: 27
Posted: 06/19/2010, 4:12 AM

Now the code looks as follows:

  
{    
    
  $db = new clsDBdbname();    
  $SQL = "INSERT INTO tablename (ip) ".     
         "VALUES (". $db->ToSQL($HTTP_SERVER_VARS['REMOTE_HOST'],ccsText)  .")";    
    
  $db->query($SQL);    
  $db->close();    
      
}  
yet no inproovements. No IP address registered in the database.
View profile  Send private message
magus

Posts: 98
Posted: 06/19/2010, 5:18 AM

Hi sorinbuda,

Have you tested that

$HTTP_SERVER_VARS['REMOTE_HOST']

works as opposed to:

$_SERVER['REMOTE_HOST']

that I recommended.

Also,
Do you have the correct new clsDBdbname();
Is the tablename correct?
Is the column named 'ip'

Regards,
Don
View profile  Send private message
sorinbuda

Posts: 27
Posted: 06/19/2010, 5:37 AM

Yes, I've tryed that in the very beginning.
The other settings are correct because all other information is inserted in the database. The full scipt is:

  
{  
  
  $db = new clsDBfsmanagement();  
  $SQL = "INSERT INTO utilizatori_statistici_acces (login,parola,ip,data_ora_acces) ".   
         "VALUES (". $db->ToSQL(CCGetParam("login",0),ccsText) .",". $db->ToSQL(CCGetParam("password",0),ccsText) .",". $db->ToSQL($HTTP_SERVER_VARS['REMOTE_HOST'],ccsText) .",". $db->ToSQL(CCGetParam("data_ora_acces",0),ccsText) .")";  
  
  $db->query($SQL);  
  $db->close();  
    
}  

the only thing which is not inserted in the database is the IP address.

Thank you in advance,
Sorin
View profile  Send private message
magus

Posts: 98
Posted: 06/19/2010, 6:24 AM

and if you echo the $SQL what is the statement being sent to the server?

echo $SQL;

Is there anything obviously wrong with the generated syntax?

$db->query($SQL);
View profile  Send private message
sorinbuda

Posts: 27
Posted: 06/21/2010, 5:17 AM

I have solved the problem with a small piece of javascript. However I am looking forward to find a solution for making the script above to work because the javascript I have implemented now is affecting the menu of the page.


Quote :
and if you echo the $SQL what is the statement being sent to the server?

echo $SQL;

Is there anything obviously wrong with the generated syntax?

$db->query($SQL);

Sorry I am a begginer I do not anderstand your piece of advise.
I get no errors in the page. And after executing the script above I can find in the database all data but the IP address. (user, pasword, data)
View profile  Send private message
magus

Posts: 98
Posted: 06/26/2010, 5:33 AM

Hi Sorinbuda,

Sorry I missed your previous message.

If you're not getting anything back it generally means you have a syntax error in your php. Look for unclosed (), {}, "", '' pairs, and make sure that each statement ends with a semicolon. ; A comma instead of a fullstop and vice versa will also cause problems.

The advice above is to echo $SQL statement to screen so you can see what is being sent to the database server.

Include

echo $SQL;
exit();

in the code previously recommended before your

$db->query($SQL);

statement.

This will print the sql to your screen and you can then try it in a tool like phpmyadmin to see if the sql works.

Regards,
Don A
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.