Beginning Ajax with PHP From Novice to Professional phần 5

Tham khảo tài liệu 'beginning ajax with php from novice to professional phần 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 78 CHAPTER 5 FORMS yourname mysql_real_escape_string strip_tags _POST yourname yourtask mysql_real_escape_string strip_tags _POST yourtask thedate mysql_real_escape_string strip_tags _POST thedate Build a dynamic query. myquery INSERT INTO task taskid yourname thedate description VALUES 0 yourname thedate yourtask Execute the query and send an error message if there is a problem . if mysql_query myquery header Location message There was a problem with the entry. exit If all goes well return. header Location message success When adding information to a database through a PHP processing script there are several important aspects to consider. Of particular importance is the question of what sort of information you want allowed into your database. In this case I have decided that I do not want any excess blank space or HTML code inserted into my database. I therefore prepare the data for entry by using the trim addslashes and htmlspecialchars functions to create a set of data that I will like within my database. The next step is to create a dynamic INSERT query to add a new record to my database. In this case I have altered the table very slightly from the previous chapter by changing the userid field to a TINYTEXT data type field called yourname. This makes it easy for anyone to add a task into the task database. Once the query has been built I simply attempt to execute the query using the mysql_query function. If it fails it will pass back the error message. If it succeeds however it will return to the form and the new task will have been added. Due to the change of the table structure the file has changed slightly to read the names in the database from the task table rather than from the user table. The new code is shown in Listing 5-4. CHAPTER 5 FORMS 79 Listing 5-4. The Code That Will Pop Up As an Auto-Complete Listing php Add in our database connector. require_once And open a database

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
19    85    1    13-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.