0

Hi,

I am trying to get something up where by:
-> It dynamically displays input text fields that can be edited.
-> However I need the current id as well as the current value to display
-> when a person submits the form, it updates all / or only each one that has been altered.
Q:
-> I need to use both the id and new value or old value when updating the database. How can this be done?

Code below: of what i have attempted so far.

$sql5 = "SELECT * FROM $tableName";
$functions=array();
foreach ($conn->query($sql5) as $row5) {
	$functions[]=<<<END 
	<input type="hidden" name="row5TextID[]" id="row5TextID[]" value="$row5[id]" />
	<input type="text" maxlength="20" value="$row5[page_name]" id="pageName[]" name="pageName[]" onFocus=this.value='' />
	Layout Setting: $row5[page_type]
	Change setting to:
 	<select id="layoutSetting" name="layoutSetting" >
		<option value="Content">Content</option>
		<option value="Gallery">Gallery</option>
		<option value="Notes">Notes</option>
	</select>
	Remove <input type="checkbox" id="remove[]" name="remove[]" value="$row5[id]" />

END;
	}
	$functions=implode("\r\n",$functions);


if (isset($_POST['saveChanges'])){
	foreach($_POST['remove'] as $removed)
		$sqlRemove = "DELETE FROM $tableName WHERE id = $removed";
		$done = $conn->exec($sqlRemove);	
	}
	if($done) { // Update all the text fields. using the new / old value and the entry id. 
		foreach($_POST['pageName'] as $pageName) {
			$pageNameID = $_POST['row5TextID'];
			$sqlUpdate = "UPDATE $tableName SET page_name = $pageName WHERE id = $pageNameID";
			$done = $conn->exec($sqlUpdate);	
		}	
	
	}
}

Is there a way to do this?

Thanks for your help

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by QWaz
0

Hello

first : when used html with php you must write : echo "html code here";

you wrote :

foreach ($conn->query($sql5) as $row5) {    $functions[]=<<<END    <input type="hidden" name="row5TextID[]" id="row5TextID[]" value="$row5[id]" />  <input type="text" maxlength="20" value="$row5[page_name]" id="pageName[]" name="pageName[]" onFocus=this.value='' />

This is not correct

The correct is :

foreach ($conn->query($sql5) as $row5) {
    $functions[]=<<<END
    echo '<input type="hidden" name="row5TextID[]" id="row5TextID[]" value="$row5[id]" />';  
echo '<input type="text" maxlength="20" value="$row5[page_name]" id="pageName[]" name="pageName[]" onFocus=this.value='' />';

secondly :

you can use the Ajax technical for solution the your problem[/B]

Edited by mike_2000_17: Fixed formatting

0

Hello

first : when used html with php you must write : echo "html code here";

you wrote :

This is not correct

The correct is :

foreach ($conn->query($sql5) as $row5) {
    $functions[]=<<<END
    echo '<input type="hidden" name="row5TextID[]" id="row5TextID[]" value="$row5[id]" />';  
echo '<input type="text" maxlength="20" value="$row5[page_name]" id="pageName[]" name="pageName[]" onFocus=this.value='' />';

secondly :

you can use the Ajax technical for solution the your problem

Thanks for the reply, however I just echo the $functions var down later. this is just the code.
I have never used Ajax before. hence the questions was how could I do it in php?
Any ideas?

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.