Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Der Versuch, nur eine einzige Spalte in die Datenbank zu schreiben

Versuchen Sie, Binds-Variablen und vorbereitete Anweisungen zu verwenden:

<?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>

Ausgabe:

1 Row inserted.

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