Jump to content

SQL statement isn't working, with no error.


Hacym

Recommended Posts

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.

		$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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.