TAILIEUCHUNG - Giải pháp thiết kế web động với PHP - p 35

CONNECTING TO MYSQL WITH PHP AND SQL 2. If you load the page into a browser, you ll see a drop-down menu that lists the files in the images folder like this: 3. Insert the following code immediately after the closing tag. The code is the same for both MySQLi and PDO, apart from one line. query($sql); $row = $result-fetch_assoc(); ? " The conditional statement checks whether image_id has been sent through the $_GET array. If it has, the next conditional statement uses the logical Not operator with is_numeric() to check whether it s not numeric. The is_numeric() function applies. | CONNECTING TO MYSQL WITH PHP AND SQL 2. If you load the page into a browser you ll see a drop-down menu that lists the files in the images folder like this 3. Insert the following code immediately after the closing form tag. The code is the same for both MySQLi and PDO apart from one line. php if isset _GET image_id if is_numeric _GET image_id image_id 1 else image_id int _GET image_id sql SELECT filename caption FROM images WHERE image_id image_id result conn- query sql row result- fetch_assoc figure img src . images php echo row filename figcaption php echo row caption figcaption figure php The conditional statement checks whether image_id has been sent through the _GET array. If it has the next conditional statement uses the logical Not operator with is_numeric to check whether it s not numeric. The is_numeric function applies a strict test accepting only numbers or numeric strings. It doesn t attempt to convert the value to a number if it begins with a digit. If the value submitted through the query string isn t numeric a default value is assigned to a new variable called image_id. However if _GET image_id is numeric it s assigned to image_id using the int casting operator. Using the casting operator is an extra precaution in case someone tries to probe your script for error messages by submitting a floating point number. Since you know image_id is an integer it s safe to insert directly in the SQL query. Because it s a number it doesn t need to be wrapped in quotes but the string assigned to sql needs to use double quotes to ensure the value of image_id is inserted into the query. 321 CHAPTER 11 The new query is submitted to MySQL by the query method and the result is stored in row. Finally row filename and row caption are used to display the image and its caption in the page. 4. If you are using the PDO version locate this line row result- fetch_assoc Change it to this row result- fetch 5. Save the page and load it into a browser. When the page first loads .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.