xryan Posted July 28, 2011 Share Posted July 28, 2011 I've been messing with this over a week and it's driving me nuts.. I'm still very new at php! It's entering it into mysql four timeS, the number of variables I have. I'm guessing the problem is in the "foreach," I've tried it about 30 different ways with no luck. include "database.php"; $cleaned_file = array("1","2","3","4"); $sql = "INSERT INTO test (ONE, TWO, THREE, FOUR) VALUES (?,?,?,?)"; $stmt = $db->prepare($sql) or die ("ERROR: " . implode(":", $db->errorInfo())); $stmt->bindParam (1, $ONE); $stmt->bindParam (2, $TWO); $stmt->bindParam (3, $THREE); $stmt->bindParam (4, $FOUR); foreach($cleaned_file as $enter_data) { $stmt->execute($cleaned_file) or die ("ERROR: " . implode(":", $stmt->errorInfo())); } echo "Record(s) successfully added."; Link to comment https://forums.phpfreaks.com/topic/243046-help-with-pdo-using-more-than-two-vars/ Share on other sites More sharing options...
jcbones Posted July 28, 2011 Share Posted July 28, 2011 Try: include "database.php"; $cleaned_file = array("1","2","3","4"); $sql = "INSERT INTO test (ONE, TWO, THREE, FOUR) VALUES (?,?,?,?)"; $stmt = $db->prepare($sql) or die ("ERROR: " . implode(":", $db->errorInfo())); $stmt->bindParam (1, $cleaned_file[0]); $stmt->bindParam (2, $cleaned_file[1]); $stmt->bindParam (3, $cleaned_file[2]); $stmt->bindParam (4, $cleaned_file[3]); $stmt->execute($cleaned_file) or die ("ERROR: " . implode(":", $stmt->errorInfo())); echo "Record(s) successfully added."; Link to comment https://forums.phpfreaks.com/topic/243046-help-with-pdo-using-more-than-two-vars/#findComment-1248295 Share on other sites More sharing options...
xryan Posted July 28, 2011 Author Share Posted July 28, 2011 Thx for giving it a shot! It's doesn't appear to be using the binding with this method. Link to comment https://forums.phpfreaks.com/topic/243046-help-with-pdo-using-more-than-two-vars/#findComment-1248307 Share on other sites More sharing options...
xryan Posted July 28, 2011 Author Share Posted July 28, 2011 OK, so if I take out the "cleaned_file" portion from $stmt->execute($cleaned_file) it binds.. Thank you!!! I still have a way to go to figure out how to loop in new info to the array. But it's a start. Link to comment https://forums.phpfreaks.com/topic/243046-help-with-pdo-using-more-than-two-vars/#findComment-1248342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.