简体   繁体   中英

MySqli adding multiple rows to db

I'm sending data to a db from a web form but every time I run it the data is stored in the db in six new rows rather than just one.

The form is just a standard form with inputs for email/password and a submit button. The action of the form runs this:

<?php
// connect to db
$link = new mysqli("localhost", "root", "", "db_name");
if (!$link) {die('Database Error: Could not connect: ' . mysql_error());}

// username and password sent from form
$email = $_POST['email'];
$password = ($_POST['password']);

// encrypt
$salt = substr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), 0, 16);
$em = crypt($email, '$6$'.$salt);
$pw = crypt($password, '$6$'.$salt);

// insert to db
$insert = "INSERT INTO users (email, password) VALUES ('$em', '$pw')";
$link -> query($insert);

// check succes/fail
if ($link->query($insert) === TRUE) {
    echo "New record created successfully";}
else {
    echo "Error: " . $sql . "<br>" . $link->error;
}

// close the db connection
$link->close();

I know this brings up a question about sanitizing inputs with encryption/salting. This page says that it's a reasonable method. Please feel free to bring that up, but I'm not really looking for an argument over best practices for sanitizing user inputs.

I'm wondering if anyone cal tell me why the data would be stored 6 times instead of just once. I changed the $6$ to $1$ but it still added 6 rows.

您的网站上有一些愚蠢的seo友好链接实现,使其在每次请求时都运行php代码,并在html中提供了5个指向不存在资源的链接。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM