0

<div align="center">

  <div = id="demo"></div>

      <script>
	  
var txt = "";
txt += "<p>User-agent: " + navigator.userAgent + "</p>";
txt += "<p>Browser Language: " + navigator.language + "</p>";
txt += "<p>Mi resolución de pantalla es: " + screen.width + " px por "+screen.height + " px </p>";

document.getElementById("demo").innerHTML = txt;

<?php
$servername = "mysql.midominio.com";
$database = "database"; 
$username = "$username";
$password = "0000000";
$sql = "mysql:host=$servername;dbname=$database;";
$dsn_Options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];

// Create a new connection to the MySQL database using PDO, $my_Db_Connection is an object
try { 
  $my_Db_Connection = new PDO($sql, $username, $password, $dsn_Options);
  echo "Connected successfully";
} catch (PDOException $error) {
  echo 'Connection error: ' . $error->getMessage();
}

// Set the variables for the person we want to add to the database
$Useragent = "+ navigator.userAgent +";
$Browser_Language = "+ navigator.language +";
$Resolución_de_pantalla = "+ screen.width + +screen.height +";
$Pixel_ratio = "";

// Here we create a variable that calls the prepare() method of the database object
// The SQL query you want to run is entered as the parameter, and placeholders are written like this :placeholder_name
$my_Insert_Statement = $my_Db_Connection->prepare("INSERT INTO useragent (Useragent, Browser Language, Resolución de pantalla, Pixel ratio) VALUES (:Useragent, :Browser_Language, :Resolución_de_pantalla, :Pixel_ratio)");

// Now we tell the script which variable each placeholder actually refers to using the bindParam() method
// First parameter is the placeholder in the statement above - the second parameter is a variable that it should refer to
$my_Insert_Statement->bindParam(:Useragent, $Useragent);
$my_Insert_Statement->bindParam(:Browser_Language, $Browser_Language);
$my_Insert_Statement->bindParam(:Resolución_de_pantalla, $Resolución_de_pantalla);
$my_Insert_Statement->bindParam(:Pixel_ratio, $Pixel_ratio);

// Execute the query using the data we just defined
// The execute() method returns TRUE if it is successful and FALSE if it is not, allowing you to write your own messages here
if ($my_Insert_Statement->execute()) {
  echo "New record created successfully";
} else {
  echo "Unable to create record";
}

// At this point you can change the data of the variables and execute again to add more data to the database
$Useragent = "+ navigator.userAgent +";
$Browser_Language = "+ navigator.language +";
$Resolución_de_pantalla = "+ screen.width + +screen.height +";
$Pixel_ratio = "";
$my_Insert_Statement->execute();

// Execute again now that the variables have changed
if ($my_Insert_Statement->execute()) {
  echo "New record created successfully";
} else {
  echo "Unable to create record";
}

?>

      </script>
	  
</div>

3
  • 1
    Primeramente, te recomendaría enérgicamente, no utilizar tildes en tu código ni utilizarlas para nombrar columnas de la base de datos. Retíralos y vuelve a probar.
    – ivan.depi
    el 23 ene. 2019 a las 7:41
  • Gracias por tu respuesta, pero aun me da error. el 23 ene. 2019 a las 16:13
  • @RodriguezGabriel puedes mostrar el error?
    – mariovzc
    el 25 ene. 2019 a las 13:54

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.