Update Multiple Records if Form Field is not NULL

I am trying to update multiple records in my database if a person uploads a new file. For some reason, the page will not work. Any suggestions would be great. Thanks

$district_data = new WA_MySQLi_RS("district_data",$sdpc_i,1);
$district_data->setQuery("SELECT *, data.softwareID as thesoftwareID FROM data left join software on data.softwareID = software.softwareID left join districts on districts.districtID = data.districtID where dataID = ?");
$district_data->bindParam("i", "".(isset($_GET['dataID'])?$_GET['dataID']:"")  ."", "-1"); //colname
$district_data->execute();
$softwareID = $district_data->getColumnVal("thesoftwareID");
$originator = $district_data->getColumnVal("originator");

if ($_GET['state'] == 'NY' and $originator == 'Y') {
$newfile = new WA_MySQLi_RS("newfile",$sdpc_i,0);
$newfile->setQuery("SELECT supplemental_info FROM data WHERE dataID = ?");
$newfile->bindParam("i", "".$_GET['dataID']  ."", "-1"); //colname
$subscribers = new WA_MySQLi_RS("subscribers",$sdpc_i,0);
$subscribers->setQuery("SELECT dataID FROM data WHERE originating_dataID = ?");
$subscribers->bindParam("i", "".$_GET['dataID']  ."", "-1"); //colname
$subscribers->execute();
for($i=0;$i<count($subscribers->getColumnVal("dataID"));$i++){
		$supplemental_info = $new_file->getColumnVal("supplemental_info");
		$dataID = $subscribers->getColumnVal("dataID")[$i];
		if($supplemental_info!==''){
	$sql="UPDATE data set supplemental_info = $supplemental_info where dataID = $dataID";
			$stmt=$sdpc_i->prepare($sql);
			$stmt->execute();
		    //echo '<div class="alert alert-success" role="alert">Submitted Successfully</div>';
		
		}}}

Exactly what does occur? Are you getting any php errors? Any database errors? Does the WA database wrapper have error handling?

The only apparent problem is that $supplemental_info is likely a string having something to do with the uploaded file (don’t forget that this is a general php help forum and no one reading this likely has any direct knowledge of the WA coding) and by putting it directly into the sql query statement it is producing an sql error. You should be using a prepared query and in those cases where you are executing a query inside of a loop with different data values, you prepare the query once, before the start of any looping, then simply execute it inside the loop with each different data value.

Remember to adapt this example to your specific database, programming language, table structure, and form data handling.

Many programming languages like Python, Java, or PHP offer libraries and frameworks for interacting with databases. They typically provide methods for executing update queries with conditions based on form field values.

Bumping old threads with non-specific statements having nothing to do with the OPs problem is not helpful. Thread closed.

Sponsor our Newsletter | Privacy Policy | Terms of Service