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

Forsøger kun at poste en enkelt kolonne i databasen

Prøv at bruge bindevariabler og forberedte udsagn:

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

Output:

1 Row inserted.

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




  1. SQL HAVING-klausul for begyndere

  2. CodeIgniter og Oracle-database - ActiveRecord insert() tilføjer dobbelte anførselstegn i forespørgslen

  3. Sådan konverteres tekstkolonne til datetime i SQL

  4. BULK INSERT mangler sidste række?