Updating MSSQL with entry.


I’m not much on PHP, but I’m making a project to store data in a site, rather then a ton of .xls files. I’m putting network data into MSSQL, servers/devices. I have everything cranked out except for adding a name entry. I’ve used the same method to add a new Network, or delete one, both successfully. But when trying to make updates to an added one, I haven’t been able to figure it out.


<?php //Get list of Networks. include("connDB.php"); //Listing Networks in the DB. $objNetworkRange = (!empty($_REQUEST['NetworkObject']) ? $_REQUEST['NetworkObject'] : ''); $qryNetworkList = "select NetworkRange from dbo.Networks"; $lstNetworks = mssql_query($qryNetworkList) or die('A error occured: ' . mssql_get_last_message()); echo "Select target network: "; echo ""; while($list = mssql_fetch_assoc($lstNetworks)) { foreach($list as $netObject) { echo "$netObject"; } } echo ""; //Listing Network octets. $objNetworkOctet = (!empty($_REQUEST['OctetObject']) ? $_REQUEST['OctetObject'] : ''); echo "Select destination IP: "; echo ""; for($i = 1; $i <= 254; $i++) { echo "$i"; } echo ""; echo "
"; //Data for Network Octet. echo '

'; $objData = (!empty($_REQUEST['DataObject']) ? $_REQUEST['DataObject'] : ''); echo "Enter the name for this device: "; ?> Data:
<? // Write the data.. //echo "Setting $objNetworkRange as $objNetworkOctet to $objData"; $writeNewObject = "update dbo.Networks set $objNetworkOctet=('$objData') where NetworkRange=('$objNetworkRange')"; $writeAction = mssql_query($writeNewObject) or die('An error occured: ' . mssql_error()); echo "Added $objData to the database ..."; ?>


I used the commented echo to see if it would show that values for each and only $objData is showing. I’ve tried to mash it up at points but can’t find my error. Searched for issues where $_REQUEST were cancelling each other out but doesn’t seem to be the case. I’m sure there are more elegant ways, but being basic and being an internal thing, I wasn’t too worried about it. I’m sure if I get into this much more I’ll be getting better at it. My logic of if it works once, repeat it doesn’t seem to be ~logical…

The error is complaining on the final write, " message: Incorrect syntax near ‘=’.". I’ve changed it up a few ways, (), (’’), also with []. As before, the same method writes a new entry as well as delete, but this one has a bit more, by an existing field (column) in an existing row.

Well, thanks for listening and thanks for you’re help.


I´m not familiar with MSSQL but i would try to change this:
[php]$writeNewObject = “update dbo.Networks set $objNetworkOctet=(’$objData’) where NetworkRange=(’$objNetworkRange’)”;[/php]
to this:
[php]$writeNewObject = “update dbo.Networks set $objNetworkOctet=’$objData’ where NetworkRange=’$objNetworkRange’”;[/php]


Appreciate the reply. I’ve gone through a few attempts at formatting it, trying different combinations. I did find out something, I’m pulling for the list so its writing the octet field as a number, the columns are IP(number) I’m don’t think that’s my core problem since I can’t echo the first two variables, just the third. I did some research on rewriting/concatenating to set that properly.

Thanks much.

hello mmcc0912, use below update query $writeNewObject = "update dbo.Networks set $objNetworkOctet='".$objData."' where NetworkRange='".$objNetworkRange."'";

Note: $objNetworkOctet this is the name of table filed than fine else you have to replace $objNetworkOctet this field with field name of table.
one more thing if you are going to update integer field than you have remove single quote.
i hope this will helpful for you,