Can I do something like in PHP?:
for($i=0; $i <= 5; $i++){
$anyway = $_POST['smth'].$i;
}
How do I use this in Mysql insert into function.
$sql = "INSERT INTO try (column_1) VALUES ('".$anyway."')";
Can I do something like in PHP?:
for($i=0; $i <= 5; $i++){
$anyway = $_POST['smth'].$i;
}
How do I use this in Mysql insert into function.
$sql = "INSERT INTO try (column_1) VALUES ('".$anyway."')";
First, I would recommend storing $_POST['smth'] in a variable before using it in your for loop.
$smth = $_POST['smth']; //remember to sanitize strings taken from user input
$anyway = ""; // Declare $anyway before the for loop to avoid overwriting it
for($i=0; $i <= 5; $i++){
$anyway = $smth.$i;
}
Then you will need to set up and test your database connection:
$mysqli = new mysqli("example.com", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
Finally, prepare, bind, and execute your query:
$stmt = $mysqli->prepare("INSERT INTO (column_1) VALUES (?)");
$stmt->bind_param("s", $anyway);
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}