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>"; } } } Quote 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 Quote 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. Quote 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)) { Quote 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? Quote 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. Quote 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! Quote Link to comment https://forums.phpfreaks.com/topic/252494-insert-function-not-working/#findComment-1294651 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.