Jump to content

PHP MySQL insert into a feild


SamDOD

Recommended Posts

I am wanting to add each users IP address into the database along side each users name. I have this code so far that gets the IP address and adds it into the database. I am not sure how to tell it to add the IP address for each user that is loged in.

 

<?php
include("adminpro_config.php");
include("adminpro_class.php");
include("adminuser_config.php");
$servername=$globalConfig['dbhost'];
$dbusername=$globalConfig['dbuser'];
$dbpassword=$globalConfig['dbpass'];
$dbname=$globalConfig['dbase'];
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
$ip=@$REMOTE_ADDR;
$strSQL= "INSERT INTO myuser(ip) VALUES ('$ip')";
       
$test=mysql_query($strSQL);


$prot=new protect("1","1");
if ($prot->showPage) {
$db=new mysql_dialog("1");
$db->connect($globalConfig['dbhost'],$globalConfig['dbuser'], $globalConfig['dbpass'], $globalConfig['dbase']);
$SQL="SELECT ".$globalConfig['tblUserName']." as userName, ";
$SQL.=$globalConfig['tblIsAdmin']." as isAdmin";
$SQL.=" FROM ".$globalConfig['tbl'];
$db->speak($SQL);
$option=""; //for the select tag normal users
$optionad=""; //for the select tag admins
$action=""; //main navigation
$editName="";
$userName="";
$allusers=0; //count all normal users
$alladmins=0; //count all admins


while ($data=$db->listen()){
$option.="<option value=\"".$data['userName']."\">".$data['userName'];
if ($data['isAdmin']==1){
$alladmins++;
}
else{
$allusers++;
}
}
extract($_POST);
?> 

 

the first connection at the top is the one i am concered with. The econd works as it should. I know it there is a way to tell it to insert the IP addres into the user who is loged in but how. Please Help thank you!

 

 

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.