[英]Insert IP address into table from form
When my PHP form is submitted I am trying to get the end users IP address and insert it into the database table with the record. 提交我的PHP表单时,我试图获取最终用户的IP地址,并将其插入带有记录的数据库表中。
My form posts to another php page.: 我的表单发布到另一个php页面。
<form name="contact_form" method="post" action="http://x.com/promotions/boston_mailer.php">
<table border="0"> ...etc...
I set my boston_mailer.php to grab the IP address: 我将我的boston_mailer.php设置为获取IP地址:
$ipaddress = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO
ucm_signup
( fname, lname, email, phone, iama, buyfrom, ipaddress )
VALUES
( '$_POST[fname]', '$_POST[lname]', '$_POST[mail]', '$_POST[phone]',
'$_POST[iama]', '$_POST[buyfrom]', '$_SERVER[$ipaddress]')";
My DB table (phpMyAdmin) has a column named "ipaddress" and is set as VARCHAR with 30 size. 我的数据库表(phpMyAdmin)有一个名为“ ipaddress”的列,并设置为VARCHAR,大小为30。
When I submit the form the IP address is nil. 当我提交表格时,IP地址为零。 "".
“”。 What am I missing?
我想念什么? Do I need to put something in my form.php page?
我需要在form.php页面中放入一些内容吗? Thank you
谢谢
Instead of $_SERVER[$ipaddress]
on your query just send $ipaddress
, because $_SERVER[$ipaddress]
is undefined. 而不是对您的查询
$_SERVER[$ipaddress]
只是发送$ipaddress
,因为$_SERVER[$ipaddress]
是未定义的。
The right way... 正确的方式...
$ipaddress = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO
ucm_signup
( fname, lname, email, phone, iama, buyfrom, ipaddress )
VALUES
( '$_POST[fname]', '$_POST[lname]', '$_POST[mail]', '$_POST[phone]',
'$_POST[iama]', '$_POST[buyfrom]', '$ipaddress')";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.