I have a form which has two different actions, one to delete the corresponding MySQL row, the other save it to another database. The delete function works fine, but the save function does not. I'm kind of at a loss at what exactly is wrong, any help is appreciated!
Here's the save/delete code:
if (isset($_POST['save'])) {
include('publishmod.php');
} elseif (isset($_POST['delete'])) {
include('deleterequest.php');
} else {
}
while ($row = mysqli_fetch_assoc($result)) {
If statements omitted, unimportant to question. Here is the form:
echo "<form name=\"editmod\" id=\"editmod\" method=\"post\">";
echo "<tr class='modlist'>";
echo "<td>".$row['id']."</td>";
echo "<td><div class=\"edit\" id=\"div_1\">".$row['title']."</div></td>";
echo "<td><div class=\"edit\" id=\"div_2\"><a href=".$row['mod_url'].">".$row['mod_url']."</a></div></td>";
echo "<td><div class=\"edit\" id=\"div_3\">".$row['developer']."</div></td>";
echo "<td><div class=\"edit\" id=\"div_4\">".$row['type']."</div></td>";
echo "<td><div class=\"edit\" id=\"div_5\">".$v162."$nbsp".$v164."$nbsp".$v172."</div></td>";
echo "<td><div class=\"edit\" id=\"div_6\">".$row['title'].",$nbsp".$row['developer']."</div></td>";
echo "<td><input type=\"submit\" name=\"save\" value=\"Save\" id=\"save\"></td>";
echo "<td><input type=\"submit\" name=\"delete\" value=\"Delete\" id=\"delete\"></td>";
echo "</tr>";
echo '<input type="hidden" name="title" value="', htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="mod_url" value="', htmlspecialchars($row['mod_url'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="developer" value="', htmlspecialchars($row['developer'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="type" value="', htmlspecialchars($row['type'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="v162" value="', htmlspecialchars($row['v162'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="v164" value="', htmlspecialchars($row['v164'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="v172" value="', htmlspecialchars($row['v172'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="id" value="', htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8'), '" />';
echo "</form>";
Yes, I am aware it has some HTML tag problems, working on that later.
publishmod.php (the save page) code:
$title = $_POST['title'];
$desc = "HowToInstallMods.com installation tutorial for '.$title.'";
$url = ereg("^[A-Za-z_\-]+$", $title) + ".php";
$keywords = "'.$title.','.$_POST['developer'].'";
// Query
Simple MySQLi connection and error check omitted.
$stmt = $mysqli->prepare("INSERT INTO search (title, description, url, keywords, type, mod_url, developer, v162, v164, v172) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssssiii", $_POST['title'], $desc, $url, $keywords, $_POST['type'], $_POST['mod_url'], $_POST['developer'], $_POST['v162'], $_POST['v164'], $_POST['v172']);
$stmt->execute();
$stmt->close();
Thanks is advance.
UPDATES:
A solution has not yet been found, but here are the changes that have been made so far from people's fixes/suggestions:
- Fixed unmatched $_POST values (thanks to gfrobenius)
- Fixed mistake from previous code, which was an if statement, and converted to regular variable (thanks to Arian)
- Added missing single quotes between values in query (thanks to damok6)
$stmt->execute();, no error was shown, and after the$stmt->close();separately, still no error. I still would not rule out that the statement isn't being run for some reason, but as far as I can see the statement seems like it be being executed.