Jump to content

[SOLVED] bind_param() ?


Boo-urns

Recommended Posts

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

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.