Mysql
 sql >> Database >  >> RDS >> Mysql

Tentativo di inserire una sola colonna nel database

Prova a utilizzare le variabili di binding e le istruzioni preparate:

<?php
$mysqli = new mysqli("localhost", "user", "pass", "db");

/* check connection */
if (mysqli_connect_errno()) {
  printf("Connect failed: %s\n", mysqli_connect_error());
  exit();
}

if (isset($_POST['scriptname'])) {
  $scriptname = $_POST['scriptname'];

  $stmt = $mysqli->prepare("INSERT INTO appslist(listall) VALUES (?)");
  $stmt->bind_param('s', $scriptname);

  /* execute prepared statement */
  $stmt->execute();

  printf("%d Row inserted.\n", $stmt->affected_rows);

  /* close statement and connection */
  $stmt->close();
 }
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
   Script Name: <input type="text" name="scriptname">
   <input type="submit">
</form>

Uscita:

1 Row inserted.

http://php.net/manual/en/mysqli.quickstart .preparate-statements.php