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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -