Hacym Posted September 9, 2012 Share Posted September 9, 2012 I am having a stupid issue with the following code, and I have tried to get it to work in several ways to no avail: if (isset($_POST['catcreate'])) { $catname = $_POST['catname']; $catcheck = $mysqli->prepare("SELECT * FROM categories WHERE name=? LIMIT 1"); $catcheck->bind_param("s", $catname); $catcheck->execute(); $catcheck->store_result(); $catnum = $catcheck->num_rows; $catcheck->close(); if ($catnum > 0) { echo "<div style=\"position:absolute; top:70px; left:300px;\"> Category already exists! </div>"; } else { $catadd = $mysqli->prepare("INSERT INTO categories (name) values (?)"); $catadd->bind_param("s", $catname); $catadd->execute(); $catadd->close(); echo "<div style=\"position:absolute; top:70px; left:300px;\"> Category added. </div>"; } } if (isset($_POST['catdelete'])) { $catname = $_POST['catdropdown']; $catdelete = $mysqli->prepare("DELETE FROM categories WHERE name=?"); $catdelete->bind_param("s", $catname); $catdelete->execute(); $catreset = $mysqli->prepare("UPDATE articles SET category='Uncategorized' WHERE category=?"); $catreset->bind_param("s", $catname); $catreset->execute; echo "<div style=\"position:absolute; top:70px; left:300px;\">Category deleted!</div>"; } } } It successfully deletes the category, but it doesn't reset the categories in the articles table. My var_dump says this: object(mysqli_stmt)#8 (9) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(1) ["field_count"]=> int(0) ["errno"]=> int(0) ["error"]=> string(0) "" ["sqlstate"]=> string(5) "00000" ["id"]=> int(7) } The SQL statement works in PHPMyAdmin. I'm sure it's a stupid, easy thing I am missing, but I've tried several things and nothing seems to work. Quote Link to comment https://forums.phpfreaks.com/topic/268187-sql-statement-isnt-working-with-no-error/ Share on other sites More sharing options...
kicken Posted September 9, 2012 Share Posted September 9, 2012 $catreset = $mysqli->prepare("UPDATE articles SET category='Uncategorized' WHERE category=?"); $catreset->bind_param("s", $catname); $catreset->execute; You're missing the () after execute, which means your never executing the query. Quote Link to comment https://forums.phpfreaks.com/topic/268187-sql-statement-isnt-working-with-no-error/#findComment-1376479 Share on other sites More sharing options...
Hacym Posted September 9, 2012 Author Share Posted September 9, 2012 -.- Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/268187-sql-statement-isnt-working-with-no-error/#findComment-1376480 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.