post - Php, $_POST method use like variable -


can in php?:

for($i=0; $i <= 5; $i++){     $anyway = $_post['smth'].$i; } 

how use in mysql insert function.

$sql = "insert try (column_1) values ('".$anyway."')"; 

first, recommend storing $_post['smth'] in variable before using in loop.

$smth = $_post['smth']; //remember sanitize strings taken user input $anyway = ""; // declare $anyway before loop avoid overwriting for($i=0; $i <= 5; $i++){     $anyway = $smth.$i; } 

then need set , test database connection:

$mysqli = new mysqli("example.com", "user", "password", "database"); if ($mysqli->connect_errno) {     echo "failed connect mysql: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } 

finally, prepare, bind, , execute query:

$stmt = $mysqli->prepare("insert (column_1) values (?)"); $stmt->bind_param("s", $anyway); if (!$stmt->execute()) {     echo "execute failed: (" . $stmt->errno . ") " . $stmt->error; } 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -