Hướng dẫn change div content php - thay đổi nội dung div php

OK, tôi đã tìm kiếm xung quanh và thấy câu hỏi này vẫn chưa được trả lời sau 2 tháng. Đây đi.

Đầu tiên tắt: Truy vấn của bạn trong tệp thứ hai có vẻ ổn, nếu (và chỉ khi)

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
0 là một số. Nhưng vì bạn không thực hiện bất kỳ trích dẫn hoặc thoát hoặc xác nhận về giá trị ở đây, bạn không thể đảm bảo điều đó. Đặt
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
1 thíchif (and only if)
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
0 is a number. But since you're not doing any quoting or escaping or validation on the value here, you can't guarantee that. Set
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
1 like
$msg_id = intval($_POST['msg_id']);
if (and only if)
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
0 is a number
. But since you're not doing any quoting or escaping or validation on the value here, you can't guarantee that. Set
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
1 like
$msg_id = intval($_POST['msg_id']);

Để chăm sóc vấn đề đó nếu

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
2 nên là một int. Bất cứ điều gì không phải là một số sẽ trở thành không, cho phép bạn dễ dàng kiểm tra các giá trị mở hoặc không hợp lệ nếu bạn quan tâm. .
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";

Thứ hai: Kiểm tra để đảm bảo

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
5 có giá trị và HTML được tạo bởi tập lệnh đầu tiên là chính xác. Ngoài ra, bạn nên thoát khỏi nó (sử dụng
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
6, như trên) trước khi sử dụng nó trong truy vấn của bạn, đặc biệt nếu nó đến từ người dùng. Vì bạn không thực sự đăng bất cứ điều gì về điều đó ở đây, nên đó là điều bạn sẽ cần tự làm. Những gì bạn đang cố gắng làm trông khá kỳ quặc, thực sự ... các trường ẩn không hữu ích trừ khi bạn gửi biểu mẫu họ đang ở (sẽ tải lại trang, đánh bại mục đích của tất cả các công cụ AJAX).Check to make sure
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
5 has a value, and that the HTML that's generated by the first script is correct. Also, you should escape it (using
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
6, as above) before using it in your query, especially if it came from the user. Since you didn't really post anything about that here, it's something you'll need to do yourself. What you're trying to do looks pretty odd, really...hidden fields aren't very useful unless you're submitting the form they're in (which would reload the page, defeating the purpose of all the ajax stuff).Check to make sure
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
5 has a value, and that the HTML that's generated by the first script is correct.
Also, you should escape it (using
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
6, as above) before using it in your query, especially if it came from the user. Since you didn't really post anything about that here, it's something you'll need to do yourself. What you're trying to do looks pretty odd, really...hidden fields aren't very useful unless you're submitting the form they're in (which would reload the page, defeating the purpose of all the ajax stuff).

Thứ ba: Để thực hiện truy xuất và thay thế thực tế, tôi muốn giới thiệu jQuery.

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
7 là phổ biến, nhưng không tiêu chuẩn. Một số trình duyệt hỗ trợ nó, một số không ... và jQuery che giấu những khác biệt đó (cũng như che giấu sự phức tạp của việc xử lý các bài đăng biểu mẫu async và như vậy). Mã jQuery mẫu (có thể hoặc không cần thay đổi nhỏ; Tôi không có công cụ kiểm tra tiện dụng):To do the actual retrieval and replacement, i'd recommend jQuery.
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
7 is common, but not standard. Some browsers support it, some don't...and jQuery hides those differences (as well as hiding the complexity of handling async form posts and such). Sample jQuery code (which may or may not need minor changes; i don't have test stuff handy):
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
3To do the actual retrieval and replacement, i'd recommend jQuery.
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
7 is common, but not standard. Some browsers support it, some don't...and jQuery hides those differences (as well as hiding the complexity of handling async form posts and such). Sample jQuery code (which may or may not need minor changes; i don't have test stuff handy):
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
3

Tôi không có ý định đi vào cách làm điều đó trong vani js. . Nội dung của Div với công cụ của riêng bạn).

Thứ tư:

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
30 và bạn bè là cách, vượt qua thời kỳ đỉnh cao của họ, và nên bị kéo ra và bắn. . Cả hai đều cung cấp một tính năng được gọi là "Câu lệnh được chuẩn bị" cho phép bạn tách truy vấn và dữ liệu của mình. Sự tách biệt đó cung cấp một số lợi ích - một bản mà bạn có thể xây dựng và chạy truy vấn một cách an toàn mà không phải lo lắng nhiều về dữ liệu của bạn trông như thế nào. . )Google for
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
31 (PHP Data Objects) and/or
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
32; both provide a feature known as "prepared statements" which allows you to separate your query and your data. That separation provides a number of benefits -- one being that you can build and run a query safely without having to worry much about what your data looks like. (As long as you're not one of those idjits that relies on magic quotes. If you do, frankly, you're pretty well screwed. Magic quotes do the wrong thing when you least expect it, making SQL injection pretty much unavoidable.)Google for
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
31 (PHP Data Objects) and/or
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
32
; both provide a feature known as "prepared statements" which allows you to separate your query and your data. That separation provides a number of benefits -- one being that you can build and run a query safely without having to worry much about what your data looks like. (As long as you're not one of those idjits that relies on magic quotes. If you do, frankly, you're pretty well screwed. Magic quotes do the wrong thing when you least expect it, making SQL injection pretty much unavoidable.)

Dù sao, tôi thích PDO, nhưng cũng tốt hơn các hàm

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
33.

Tham khảo: w3schools.com

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
8

https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/replaceWith

2019 Update:

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
9

In the specific case of this question, I would recommend using

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
34 with a clone of the node OP wishes to swap in. This could look like:

This would probably present an issue the next time you go to swap the element, but you could adapt this solution to fit your needs.

Original Post:not use not use

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
7, due to possible unforseen side effects. The best way to do this would be to:
  • The best way to do this would be to not use
    $msg_id_sql = mysql_real_escape_string($msg_id);
    $query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
    
    7, due to possible unforseen side effects. The best way to do this would be to:
  • First clone the desired div
  • Second empty the main div

Third append the clone into the main div

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
3

This would look very much like the following:

Do not allow yourself to fall into the many pitfalls of using

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
7; cloning a node has a much better chance of doing exactly what you're expecting it to do.

Some of the problems with

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
7 are that it only copies the HTML, and not the DOM, meaning that you do not copy over anything on that DOM node, like event listeners, properties (like value), etc. Cloning a node (and its children) clone that DOM node, which clones its properties respectively.

It is also considered poor practice (by most) to use inline event handlers on your HTML; separation of concerns!

Phương thức 

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
38 có chức năng tìm kiếm một chuỗi con hoặc một biểu thức chính quy nào đó trong chuỗi sau đó thay thế nó bằng một giá trị được cung cấp bởi người dùng. Phương thức sẽ trả về chuỗi đã được thay thế mà không hề thay đổi chuỗi gốc.freetuts.net, không được copy dưới mọi hình thức.freetuts.net, không được copy dưới mọi hình thức.

Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

Cú pháp

Cú pháp: 

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
70: 0

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
80

Trong đó:::

Bài viết này được đăng tại [free tuts .net]

  • searchvalue giá trị sẽ được tìm kiếm trong chuỗi string.
  • newvalue là giá trị sẽ được thay thế cho searchvalue trong chuỗi mới mà phương thức trả về.

Cách sử dụng

Ví dụ: sử dụng phương thức 

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
98 để thay thế giá trị trong chuỗi.: sử dụng phương thức 8 để thay thế giá trị trong chuỗi.: sử dụng phương thức 

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
38 để thay thế giá trị trong chuỗi.
$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
1

Kết quả

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
2

Ví dụ 2: Thay thế tất cả các chuỗi con tìm thấy trong chuỗi gốc.: Thay thế tất cả các chuỗi con tìm thấy trong chuỗi gốc.: Thay thế tất cả các chuỗi con tìm thấy trong chuỗi gốc.

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
3

Kết quả

$msg_id_sql = mysql_real_escape_string($msg_id);
$query = "SELECT * from workflow WHERE msg_id = '$msg_id_sql'";
4

Ví dụ 2: Thay thế tất cả các chuỗi con tìm thấy trong chuỗi gốc.: Thay thế tất cả các chuỗi con tìm thấy trong chuỗi gốc.

Ví dụ 2: Thay thế tất cả các chuỗi con tìm thấy trong chuỗi gốc.