# Update Multiple Records if Form Field is not NULL

**URL:** <https://www.phphelp.com/t/update-multiple-records-if-form-field-is-not-null/35979>\
**Category:** Beginners - Learning PHP\
**Created:** [January 15, 2024, 8:40pm UTC](https://www.phphelp.com/t/update-multiple-records-if-form-field-is-not-null/35979 "2024-01-15T20:40:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwaters5](https://www.phphelp.com/letter_avatar_proxy/v4/letter/l/e9c0ed/32.png) [@lwaters5](https://www.phphelp.com/u/lwaters5)\
**Post date:** [January 15, 2024, 8:40pm UTC](https://www.phphelp.com/t/update-multiple-records-if-form-field-is-not-null/35979/1 "2024-01-15T20:40:53Z")

</div>

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

```auto
$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>';
		
		}}}

```

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [January 16, 2024, 3:36pm UTC](https://www.phphelp.com/t/update-multiple-records-if-form-field-is-not-null/35979/2 "2024-01-16T15:36:22Z")

</div>

> [@lwaters5](#):
>
> the page will not work

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.

---

<div class="post-metadata">

**Author:** ![alexcray](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@alexcray](https://www.phphelp.com/u/alexcray)\
**Post date:** [January 26, 2024, 4:54am UTC](https://www.phphelp.com/t/update-multiple-records-if-form-field-is-not-null/35979/3 "2024-01-26T04:54:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexcray](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@alexcray](https://www.phphelp.com/u/alexcray)\
**Post date:** [February 9, 2024, 3:02am UTC](https://www.phphelp.com/t/update-multiple-records-if-form-field-is-not-null/35979/4 "2024-02-09T03:02:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [February 9, 2024, 4:30am UTC](https://www.phphelp.com/t/update-multiple-records-if-form-field-is-not-null/35979/5 "2024-02-09T04:30:30Z")

</div>



---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [February 9, 2024, 4:31am UTC](https://www.phphelp.com/t/update-multiple-records-if-form-field-is-not-null/35979/6 "2024-02-09T04:31:44Z")

</div>

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