Update SQL Server DB in php with stored procedure

Hi,

As the title said, i’m trying to update an SQL Server DB with php. From my code below, you can see that i call once a stored proc to get information who will be in a table. One of the row allow me (supposed to be)(the last row who is an input), to change an other one (row name GL). But with the button save, it seems like nothing change at all. I tried to make some log with console and i can see test1 and test2. So it seems like it can go throught but doesnt ajust anything. I really don’t know anymore and i really need your help. Any ideas or help will be really really appreciate. More on that, i’m not sure if i do it well about sql injection…

[code]<?php if(isset($_POST[“test”]))
{
$NewValue = $_POST[“noGL” . $_POST[“TLZno”]];
$TLZ = $_POST[“TLZ”];?>

<?php $sql1 = "UpdateGL @CIE ='RAL', @TLZ='$TLZ', @NOGL='$NewValue'";?>

<?php } else { echo "Rien!"; } ?>
				<button class="btn btn-success btn-sm dropdown-toggle save" name='submit' id='submit' type="submit" value="Enregistrer">
					<i class="fa fa-floppy-o fa-lg" aria-hidden="true"> Enregistrer</i>
				</button>

Liste des numéros de GL

<?php $sql = "ListeGL"; $result = sqlsrv_query($conn, $sql); $row_count = sqlsrv_num_rows($result); while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { //print_r( $row ); // debug code $couleur='black'; $font= 'normal'; $input="a"; if( strstr($row['HTML_CODE'], "BOLD()")){ $font= 'bold'; } if( strstr($row['HTML_CODE'], "BG()")){ $font2= '#D8D8D8'; } if( strstr($row['HTML_CODE'], "INPUT()")){ $input= 'input'; $font2= '#transparent'; } ?>
		                                <tr>
		                                	<?php echo "<tr style=\"font-weight:$font; color:$couleur; background-color:$font2;\">"; ?>
			                                <td style="text-align: center;"><?php echo ($row['TLZno']); ?></td>
			                                <td style="text-align: left;"><?php echo ($row['TlzDescription']); ?></td>
			                                <td style="text-align: center;"><?php echo ($row['TlzType']); ?></td>
			                                <td style="text-align: center;"><?php echo ($row['noGL']); ?></td>
			                                <td style="font-weight: normal; text-align: left; color: #BDBDBD; ">
			                                	<<?php echo $input . ' name="noGL' . $row['TLZno'] . '"'; ?> type="text" name="new" value="<?php echo ($row['noGL']); ?>" />
			                                	</td>
		                                </tr>
<?php } ?>
              						</tbody>
								</table>
								</form>[/code]
# TLZ Description D/C # GL Nouveau # GL

Prepared statements for one thing. You are not calling the stored proc correctly.

And how does i make it? If i add this:

[code]<?php if(isset($_POST[“test”]))
{
$NewValue = $_POST[“noGL” . $_POST[“TLZno”]];
$TLZ = $_POST[“TLZ”];?>

<?php $sql1 = "UpdateGL @CIE ='RAL', @TLZ='$TLZ', @NOGL='$NewValue'";?>

<?php $stmt = sqlsrv_prepare( $conn, $sql1); if( !$stmt ) { die( print_r( sqlsrv_errors(), true)); $result = sqlsrv_execute($stmt); $row = sqlsrv_fetch_array($stmt); } } else { echo "Rien!"; } ?>[/code]

It’s still doesn’t work. As i show on the result, it explain that TLZno and noGL must be link each others to know exactly with on of GL is change and apply the change. TLZno always stay the same. I must do it because in my request, i used a loop where i don’t have any information how many row will be. I don’t know if you understand what i means?


Execute a Stored Procedure

Sponsor our Newsletter | Privacy Policy | Terms of Service