0

this is the code that gives user agent and other stuff

 $username = mysqli_real_escape_string($db, $_POST['username']);
 $email = mysqli_real_escape_string($db, $_POST['email']);
 $ip = mysqli_real_escape_string($db, $_SERVER['REMOTE_ADDR']);
 $ua = mysqli_real_escape_string($db, $_SERVER['HTTP_USER_AGENT']); //user agent  
 $password1 = mysqli_real_escape_string($db, $_POST['password1']);
 $password2 = mysqli_real_escape_string($db, $_POST['password2']);

this is when it inserts

    $query = "INSERT INTO users (username, email, password, ip, uagent) 
          VALUES('$username', '$email', '$password', '$ip', '$ua')";
    mysqli_query($db, $query);
    $_SESSION['username'] = $username;
    $_SESSION['success'] = "You are now logged in";
    header('location: index.php');

and this is the table code

    CREATE TABLE `users` (
  `ID` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `Username` varchar(100) NOT NULL,
  `Password` varchar(100) NOT NULL,
  `Email` varchar(100) NOT NULL,
  `IP` varchar(20) NOT NULL DEFAULT '',
  `UAgent` varchar(50) NOT NULL
);

idk why but it doesn't work it doesn't give any data to the database but if I remove the user agent part then it works I get the username, password, email and ip but i want user agent too

Dharman
  • 30,962
  • 25
  • 85
  • 135
wfsec
  • 11
  • 7

2 Answers2

0

You will probably need more than 50 characters for the user agent. I’d suggested increasing the size of the user agent column:

ALTER TABLE users MODIFY UAgent VARCHAR(200) NOT NULL;
G Wilson
  • 11
  • 3
0

you can modify your code and change the varchar(50) to varchar (200)

CREATE TABLE `users` (
  `ID` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `Username` varchar(100) NOT NULL,
  `Password` varchar(100) NOT NULL,
  `Email` varchar(100) NOT NULL,
  `IP` varchar(20) NOT NULL DEFAULT '',
  `UAgent` varchar(200) NOT NULL