Php cannot delete records in mssql-php Tutorial

Source: Internet
Author: User
Php cannot delete records in mssql. php cannot delete records in mssql.

The table structure in mssql is as follows:



Because hr_id is a string in the uniqueidentifier format generated by mssql, I cannot use php to read this string. it is a word value queried by mssql. now, for example, if I want to delete the first value, you cannot delete this record after Clicking delete:


The code for deleting a link on the previous page is as follows:
// ================================================ =
Echo"Delete | modify";
========================================================== =

The del statement is as follows:

Require_once ("c_class.php ");
Require_once ("c_init.php ");


$ Db = new msSQL ($ db_IP, $ db_user, $ db_sa, $ db_dbName, "conn ");
// Mssql_query ("set names 'utf-8 '");
// Mssql_query ('set NAMES GB2312 ');
$ SQL = "delete from". $ tablea. "where recv_time =". urldecode ($ _ GET [recv_time]);
$ Del = mysql_query ($ SQL );
If ($ del ){
Echo "script" alert ('successful '); history. back (); script ";
} Else {
Echo "script" alert ('fales'); history. back (); script ";
}

========================================

The deletion fails.

How can this problem be solved ??

In addition, how can I specify only one record for a php operation (such as modification or deletion? Mysql can use the SQL statement limit to limit the SQL statement, but it seems that mssql does not have this limit parameter to limit the SQL statement. how can I write the SQL statement to operate mssql in php ??


Reply to discussion (solution)

$sql = "delete from ".$tablea." where recv_time =  '".urldecode($_GET[recv_time])."'";
The single quotation marks are missing.

The record cannot be deleted because it remains the same after correction.

The record cannot be deleted because it remains the same after correction.


Print $ SQL.

The $ SQL statement output by echo is as follows:
Delete from hr_atd_recv where recv_time = '2017-03-27 17:44:00'

You can run it correctly in the mssql query analyzer.



Somehow, php cannot run. Dizzy !!

I have done it myself. I used the wrong function on the first floor. Mysql_query should be written as mssql_query.

Careless.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.