Jump to content

Delete from Database


jat421

Recommended Posts

Hi,

 

I am trying to delete a row that has be read. Below is the code. I can't figure out how to delete it after it has been printed on the screen. Any help is much appreciated. Thanks!

 

<?php
echo "Today is " . date("Y/m/d");


$server = "Computer\\test";
$options = array(
  "UID" => "sa",
  "PWD" => "root",
  "Database" => "SetNo"
);

$conn = sqlsrv_connect($server, $options);
if ($conn === false) die("<pre>".print_r(sqlsrv_errors(), true));

$result=sqlsrv_query($conn, "select * from tblCus");
[color=red]$delete=sqlsrv_query($conn, "delete from tblCus where result.row[1]");[/color]

$row = sqlsrv_fetch_array($result);
echo "<br />";
echo "<br />";
echo "<br />";
echo "Number:" . " " . $row[1];
echo "<br />";



sqlsrv_close($conn);

?>

Link to comment
https://forums.phpfreaks.com/topic/221163-delete-from-database/
Share on other sites

1. $row only exists after

$row = sqlsrv_fetch_array($result);

You can't use it before that point.

 

2. "where result.row[1]" is not a valid condition in T-SQL. You need something like "where field = value".

 

3. Are you trying to display the whole table or just the first row?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.