son.of.the.morning Posted December 5, 2011 Share Posted December 5, 2011 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 More sharing options...
marcelobm Posted December 5, 2011 Share Posted December 5, 2011 One of the problems i see right away is that when you implode the values, you need to do it so values are separated by a comma Link to comment https://forums.phpfreaks.com/topic/252494-insert-function-not-working/#findComment-1294523 Share on other sites More sharing options...
son.of.the.morning Posted December 5, 2011 Author Share Posted December 5, 2011 Thats not an issue there is comma's set within each var. the only issue is that it insert 2 sets of records rather then one. Link to comment https://forums.phpfreaks.com/topic/252494-insert-function-not-working/#findComment-1294525 Share on other sites More sharing options...
litebearer Posted December 5, 2011 Share Posted December 5, 2011 perhaps here... mysql_query($i) or die(mysql_error()); if (!mysql_query($i)) { Link to comment https://forums.phpfreaks.com/topic/252494-insert-function-not-working/#findComment-1294592 Share on other sites More sharing options...
son.of.the.morning Posted December 5, 2011 Author Share Posted December 5, 2011 ? sorry i dont understand were the problem is comming from? Link to comment https://forums.phpfreaks.com/topic/252494-insert-function-not-working/#findComment-1294596 Share on other sites More sharing options...
kicken Posted December 5, 2011 Share Posted December 5, 2011 ? 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. Link to comment https://forums.phpfreaks.com/topic/252494-insert-function-not-working/#findComment-1294650 Share on other sites More sharing options...
son.of.the.morning Posted December 5, 2011 Author Share Posted December 5, 2011 ahh i see! Link to comment https://forums.phpfreaks.com/topic/252494-insert-function-not-working/#findComment-1294651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.