Jump to content

INSERT function not working


son.of.the.morning

Recommended Posts

I have a class built for an INSERT query but it is passing two sets of records into the database rather than one.

 

class DatabaseInsert {

	function DatabaseConnectionRequire() {
		include("../scrips/php/database.connection.class.php");
		include("../scrips/php/database.settings.php");	
		include("../scrips/php/database.connection.class.invoke.php");	

	}

	function ArticleInsert($values,$fields,$table) {

		$values_imploded = implode("   ",$values);
		$fields_imploded = implode("   ",$fields);
		$i = "INSERT INTO $table ($fields_imploded) VALUES ($values_imploded)";
		mysql_query($i) or die(mysql_error());

		if (!mysql_query($i)) {

	    	echo "Sorry, something whent wrong there...";
		}

		else {
			echo "<strong><p style='color:green;'>Content added sucessfully!!!</p></strong>";
		}

	}
}

Link to comment
https://forums.phpfreaks.com/topic/252494-insert-function-not-working/
Share on other sites

? sorry i dont understand were the problem is comming from?

 

Your executing your insert query twice:

 

mysql_query($i) or die(mysql_error()); // <-- First here

 

if (!mysql_query($i)) {  //<-- Then again here

 

 

That is why your getting a double insert.

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.