I made a form for pharma products where user select the manufacturers name and write the details of the project. Everything is up and running fine except only this issue. Its been hours and i cant figure it out.
The problem is Its only selects the first row and ignore new entries. What i want is it will select every row or every new entry and insert into second database here the code is working with no errors but update only the first row.
//Select Everything from database
$perm = "SELECT * FROM test";
$result34 = mysqli_query($dbc, $perm);
if ($perm) {
//How many rows
$count = mysqli_num_rows($result34);
//Retrieve data
if($count>=1) {
$rows = mysqli_fetch_array($result34);
$namex= $rows['name'];
$categoryx = $rows['category'];
//takeout the spaces and strip tags
$namey = strip_tags($namex);
$category = str_replace(' ', '', $category);
//INSERT INTO TABLES
$sql34 = "INSERT INTO final1 (Name, Category) VALUES ($namey, $category);";
$result55 = mysqli_query($dbc, $sql34);
}
}
With prepared statement:
$sql2 = "INSERT INTO final1 (Name, Category) VALUES (?, ?);";
$stmt1 = mysqli_stmt_init($dbc);
if (!mysqli_stmt_prepare($stmt1, $sql2)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt1, "ss", $namey, $category);
mysqli_stmt_execute($stmt1);
}