Boo-urns Posted February 3, 2009 Share Posted February 3, 2009 Can you use bind_param and execute in a for loop? (With the bind outside of it) <?php // $db is being extended from the mysqli class if($stmt = $db->prepare("INSERT INTO test (fName, lName) VALUES(?, ?)")) { $stmt->bind_param('ss', $fName, $lName); for($i = 1; $i <= $numDeclared; $i++) { // numDeclared is a hidden field to figure out how many forms there are on the page // i am starting on 1 on purpose. $fName = $fName[$i]; $lName = $lName[$i]; // Execute the prepared Statement $stmt->execute(); } // Close the statement $stmt->close(); } It loops properly but is only inserting the first row (if i have multiple). Also is there a built in real_escape_string when preparing queries? (I'm doing it outside of it right now) Thanks! -Corey Link to comment https://forums.phpfreaks.com/topic/143643-solved-bind_param/ Share on other sites More sharing options...
Boo-urns Posted February 4, 2009 Author Share Posted February 4, 2009 Figured it out. My variables $fName etc...was the array name so it was confusing PHP I guess. It works now! Link to comment https://forums.phpfreaks.com/topic/143643-solved-bind_param/#findComment-754363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.