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
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?

Link to comment
Share on other sites

I got it working thanks for your help!

 

I assigned $row[1] to a variable and provided that as a sql delete paramater.

 

Just one more question. I want only one person reading and writing to the table at one time. How can that be done? Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.