Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring getting and storing IP address
    primarykey
    data
    text
    <p>I currently have a function that stores a query that has been entered into a form. I am trying to save the IP address of the user that submits the form along with the input.</p> <p>Currently this is the function:</p> <pre><code> function userIP(){ $ip = $_SERVER['REMOTE_ADDR']; if($ip){ if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; $ipis = ip2long($ip); } return $ip; } return false; } public function __construct( $data = array() ) { if( isset( $data['text'] ) ) $this-&gt;text = stripslashes( strip_tags( $data['text'] ) ); if( isset( $data['ipis'] ) ) $this-&gt;ipis = stripslashes( strip_tags( $data['ipis'] ) ); } public function storeFormValues( $params ) { $this-&gt;__construct( $params ); } public function store() { $correct = false; try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "INSERT INTO tbl(content, ip) VALUES(:text, :ipis)"; $stmt = $con-&gt;prepare( $sql ); $stmt-&gt;bindValue( "text", $this-&gt;text, PDO::PARAM_STR ); $stmt-&gt;bindValue( "ipis", $this-&gt;ipis, PDO::PARAM_STR ); $stmt-&gt;execute(); return "Added"; }catch( PDOException $e ) { return $e-&gt;getMessage(); } } </code></pre> <p>}</p> <p>However it currently only stores the "text" that was input and just adds NULL to the database for IP. The MYSQL for the IP row is set up as an unsigned INT 11. Any ideas on fixing the issue?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload