Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'php'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



  1. Hi Larry, I am following your design in part 3 of the book to create a cart which is all fine - great guidance! But the website owner insists that the payment will be via PayPal (PP). I have looked at part 2 where you use PayPal but with fixed amounts. I am trying to create a button/link to PP for a variable amount and in Australian dollars. The code works fine as long as I do not try to change the currency. I also need to add 'thankyou' and 'cancel' links back to the website but I can't seem to do that either. I have Googled for hours without finding the solution. <!-- now the button --> <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value="xxxx@yyyy.com.au"> <input type="hidden" name="item_name" value="Item Description"> <input type="hidden" name="item_number" value=""> <input type="hidden" name="amount" value="$total"> <input type="hidden" name="handling" value="0.00"> <input type="hidden" name="shipping" value="0.00"> <!-- <input type="hidden" name="currency_code" value="AUD"> --> <input type="hidden" name="lc" value="AU"> <input type="hidden" name="bn" value="PP-BuyNowBF"> <input type="image" src="https://www.paypalobjects.com/en_AU/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1"> <input type="hidden" name="add" value="1"> </form> You can see that I have commented the currency out - with it 'in' I get an error from PP. Any guidance will be much appreciated. Best regards from Oz :-)
  2. I am new at php. I am trying to loop a number in each click of a button. See attached picture for reference. 1 should iterate after the click of the button and will stop to iterate when it gets to 5. Here is my code: <!DOCTYPE html> <html> <body> <div>Question <?php $num = 5; $n = 1; $n <= $num; echo $n; ?> of <?php echo $num;?></div> <form method="post"> <button id="button" class="button" value="add" name="add">Click</button> </form> </body> </html> If I try to loop it this way, <!DOCTYPE html> <html> <body> <div>Question <?php $num = 5; for($i = 1; $i <= $num; $i++){ echo $i; } ?> of <?php echo $num;?></div> <form method="post"> <button id="button" class="button" value="add" name="add">Click</button> </form> </body> </html> the result is Question 12345 of 5.
  3. How do we easily get rid of people who register but do not activate their account? I just found out that I cannot schedule an event in the database because I am on a shared web hosting plan. I am seemingly getting a lot of "fake" registrants that are taking up space.
  4. Hello! Please explain to me how gender validations from scripts 2.3 differ from the nested one in script 2.4. I have this in 2.3 (updated with NULL coalescing operator while practicing Pursue section): $gender = $_REQUEST['gender'] ?? NULL; if ($gender == 'M') { $greeting = '<p><strong>Good day, Sir!</strong></p>'; } elseif ($gender == 'F') { $greeting == '<p><strong>Good day, Madam!</strong></p>'; } else { $gender = NULL; echo '<p class="error">Gender must be either "M" or "F"!</p>'; /* You may wonder how this last case may be possible, considering the values are set in the HTML form. If a malicious user creates their own form that gets submitted to your handle_form.php script (which is very easy to do), they could give $_REQUEST[‘gender’] any value they want. */ } and this in 2.4: if (isset($_REQUEST['gender'])) { $gender = $_REQUEST['gender']; if ($gender = 'M') { $greeting = '<p><strong>Good day, Sir!</strong></p>'; } elseif ($gender = 'F') { $greeting = '<p><strong>Good day, Madam!</strong></p>'; } else { $gender = NULL; echo '<p class="error">Gender must be either "M" or "F"!</p>'; /* You may wonder how this last case may be possible, considering the values are set in the HTML form. If a malicious user creates their own form that gets submitted to your handle_form.php script (which is very easy to do), they could give $_REQUEST[‘gender’] any value they want. */ } } else { // $_REQUEST['gender'] is not set. $gender = NULL; echo '<p class="error">You forgot to select your gender!</p>'; } It seems that these scripts do the same job, or I just can't figure out the difference, please help me to understand it. And also I want to if we could use NULL coalescing operator in script 2.4 some way. Thank you!
  5. I have studied php introduction and php advanced object oriented programming, Was able to get my hands on small projects such as building small websites, Buiding forums. I will like to know which project book is the best php project book guide to guide developers on building dynamic applications(such as social media platforms, educational platform, online libraries...etc) using php. Which is the best with detail and straight forward explanation.
  6. <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <?php $string_array = explode(' ' , $_POST['words']); $array_string = implode(',<br>' , $string_array); $array_string = ucwords(strtolower($array_string)); print "<p> Alphabetized:<br><br>$array_string</p>"; ?> </body> </html>
  7. I have this stored procedure that has 2 parameters, the first one is the cartId(which is the IN) and I have the newOrderId(which is the OUT). Now, I know that the inCartId is the cart id which will come from the form or whatever means the cart is been access but I don't understand the OUT newOrderId since that is what MySQL will return. Now, in the PHP calling this Stored procedure, it will look like this. $sql = 'CALL create_order(:cart_id, "What will be here")// The cart_id is what PHP will pass to MySQL, but what will be passed to the 2nd argument since does not before hand what MySQL will return. CREATE PROCEDURE create_order( IN inCartId int, OUT newOrderId int ) BEGIN -- Insert a new record into orders and obtain the new order ID INSERT INTO orders (created_on) VALUES (NOW()); -- Obtain the new Order ID SELECT LAST_INSERT_ID() INTO newOrderId; -- Insert order details in order_detail table INSERT INTO order_detail ( order_id, product_id, attributes, product_name, quantity, unit_cost ) SELECT orderId, p.id, sc.attributes, p.name, sc.quantity, COALESCE( NULLIF( p.discounted_price, 0 ), p.price ) AS unit_cost FROM shopping_cart sc INNER JOIN products p ON sc.product_id = p.id WHERE sc.cart_id = inCartId AND sc.buy_now; -- Save the order's total amount UPDATE orders SET total_amount = ( SELECT SUM( unit_cost * quantity ) FROM order_detail WHERE order_id = orderId ) WHERE id = orderId; -- Clear the shopping cart CALL shopping_cart_empty(inCartId); END
  8. Please I need your help, I am new to PHP and I need your help in inserting multiple select array into the database in the form of this.This is what I want to achieve. My table has 5 columns (id, examno, subjects, grades, results). I want results column to be inform of subjects grades, subjects grades.........depending on the numbers of subjects and grades users select (e.g English C6, Mathematics C6) all in one column results. This is my html codes <form action="insert.php"> <div class="form-group"> <label>Exam Number</label> <input type="text" class="form-control" name="examno" id="examno"> </div> <table width="100%" cellpadding="0" cellspacing="0" border="0" class="table table-borderless" id="example"> <tr> <td width="12%"><label class="control-label">S/NO</label></td> <td width="53%"><label class="control-label">SUBJECTS</label></td> <td width="35%"><label class="control-label">GRADE</label></td> </tr> <tr> <td>1</td> <td> <select name="subjects[]" class="form-control" id="subject"> <option value="" selected="selected">Select subject</option> <option value="English">English</option> <option value="Mathematics">Mathematics</option> </select> </td> <td> <select name="grades[]" class="form-control"> <option value=""> Select</option> <option value="A1">A1</option> <option value="B2">B2</option> </select> </td> </tr> </table> <input type="submit"> </form> I have about 8 subjects and grades to be inserted like that Also this is my insert.php if(isset($_POST['submit'])){ $examno = mysqli_real_escape_string($conn, $_POST['examno']); foreach($_POST['subjects'] as $row=>$subjects){ $subjects = mysqli_real_escape_string($conn, $subjects); $grades = mysqli_real_escape_string($conn, $_POST['grades'][$row]); $results = $subjects." ".$grades; } $sql = "INSERT INTO qualifications(examno, subjects, grades, results) VALUES('".$examno."', '".$subjects."', '".$grades."', '".$results."')"; $result = mysqli_query($conn, $sql); if($result){ header("location:declaration.php"); // user will be taken to the success page } else{ echo "Oops. Something went wrong. Please try again"; } } Nothing was inserted into the subjects, grades, and results. Please help me as I am new to php/mysqli
  9. This part of the login code does not seem to be working. I know the information is in the database and the activation field says NULL. I believe that the browser - Firefox on a Mac - is accepting cookies. I have tried this with several users and they all have the same password. I am getting the error message that indicates that the Email and Password does not match those on file. I am set up to use PHP 7. // Query the database: $q = "SELECT user_id, first_name, user_level, pass FROM users WHERE email='$e' AND active IS NULL"; $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br>MySQL Error: " . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { // A match was made. // Fetch the values: list($user_id, $first_name, $user_level, $pass) = mysqli_fetch_array($r, MYSQLI_NUM); mysqli_free_result($r);
  10. I believe that I have followed the code to create a "Forget Password" link. However, I am getting an error that seems to indicate that I am asking for a password hash twice - Fatal error: Cannot redeclare get_password_hash() (previously declared in /hermes/bosnacweb04/bosnacweb04aj/b717/nf.xxxxxxxxxxxx/public_html/xxxxxxxxxxxx/TBRMobile/mysqli.inc.php:28) in /hermes/bosnacweb04/bosnacweb04aj/b717/nf.xxxxxxxxxx/public_html/xxxxxxx/TBRMobile/mysqli.inc.php on line 33 ---- I have x'd out certain areas of this error on purpose. My config file and mysqli file are almost exact. I do not use a header file.
  11. Hey guys. I need help with the program. I get error Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\index.php on line 15 Here is my code: 1st file. <?php include_once 'includes/DuombazesInfo.php' ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php $sql = "SELECT * FROM vartotojai"; $result = mysqli_query($con, $sql); $resultCheck = mysqli_num_rows($result); if ($resultCheck > 0) { while ($row = mysqli_fetch_assoc($result)) { echo $row['vartotojas_vardas']; } } ?> </body> </html> 2nd file. <?php $dbServername = "localhost"; $dbUsername = "root"; $dbPassword = ""; $dbName = "duombaze"; $con = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbPassword);
  12. In chapter 3.2 the code was introduced: <title><?php echo $page_title; ?></title> Having now contructed a website based on this I'm having error now using the header() function such as redirecting and form submission. Each page includes the header file and defines the page title: // include the header file: include ('../includes/my_header.inc.php'); // Create the page title: $page_title = 'My Page Title'; //line #13 Whenever I use the header() now I get this error: Warning: Cannot modify header information - headers already sent by (output started at /home/mydomain/public_html/includes/my_header.inc.php:13) Is there a way round this or do I have to redesign the website?
  13. Please, who have any resources on twig and doctrine ORM should please share me links
  14. I have been updating a website with the scripting from this book. A piece of code I have is not working with the new php and I have reworked this several times. The following is the error message that I get in the server error log - PHP Fatal error: Can't use function return value in write context in /hermes/bosnacweb04/bosnacweb04aj/b717/nf.xxxxxxxxx/public_html/xxxxxxxx.com/Login.php on line 137 Line 37 would be the following - if (mysqli_num_rows($r) = $username) { <?php // Show the user info or the login form: if (isset($_SESSION['user_id'])) { // Show basic user options: $q = "SELECT user_id, username FROM users WHERE user_id={$_SESSION['user_id']}"; $r = mysqli_query ($db, $q); //if (mysqli_num_rows($r) > 0) { if (mysqli_num_rows($r) = $username) { //while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { while ($r = mysqli_fetch_array($r, MYSQLI_NUM)) { // Display the username and heading echo "<p><h2a>Hello $username!</p>"; } } Thanks
  15. Am trying to put mysqli result set into an array for later use and this is how I did it(but is not working) $split = []; $sql_money = "SELECT j_id, amount_invested FROM j_members WHERE j_activated = 1 LIMIT 5"; $result_money = mysqli_query($conn, $sql_money); while($data = mysqli_fetch_assoc($result_money)){ $split[] = ['id' => $data['id'], 'invest' => $data['amount_invested']]; //echo $data['j_id']; } foreach($split as $s){ echo $s['id'] . '<br>'; } Who can put me through
  16. I wrote a forum app sometimes ago and am trying to improve it . I have an issue that is hard for me to solve(I don’t even know how to solve it, I just have the idea), how can I create a notification menu like the one on this site, sitepoint, stackoverflow etc that display at the top of the menu for a user about messages that were received on thread or post he start or comment on. The forum was created using PHP
  17. I have surf the web but still don’t find an explaining tutorial on how to use either google map or php google map to automatically detect the location of a user. This is what I want to achieve, during registration, a user current location will be extracted using either the js version of the map or the php version(depending on the one I saw a good way of using it), and extraction, the current town or city or village with also the country. Who can really put me through on how to use any of the above library
  18. Sir I don't know if you can give us an update on the gateway api as much has change since the time you did the last update
  19. I'm trying to run a query of existing employee records in order to update their information, and am receiving the error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/schill54/public_html/Capstone/htdocs/Home/updateform.php on line 8 Below is my script. I've tweaked the query several times with no luck. Originally I had it set to SELECT * from my users table but then realized there was 1 column that I didn't want it to return and therefore I didn't account for it in my form, so then listed the desired columns individually but still getting the error. From the google searching I've done so far I realize there is probably still something wrong with my query but can't figure out what it is. <?php { include ("../includes/header.php"); require_once ('../../mysqli_connect.php'); $lname=$_GET['last_name']; $query = "SELECT first_name, last_name, phone, username, pass, admin FROM users WHERE last_name='$lname'"; $result = mysqli_query ($dbc, $query); $num = mysqli_num_rows($result); if ($num > 0) { // If it ran OK, display all the records. while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){ ?> <form action="updatemp.php" method="post"> <p>First Name: <input name="text" size=30 value="<? echo $row['first_name']; ?>"></p> <p>Last Name: <input name="text" size=30 value="<? echo $row['last_name']; ?>"></p> <p>Phone Number: <input name="text" size=30 value="<? echo $row['phone']; ?>"></p> <p>User Name: <input name="text" size=30 value="<? echo $row['username']; ?>"></p> <p>Password: <input name="text" size=30 value="<? echo $row['pass']; ?>"></p> <p>Admin Access?: <input name="text" size=30 value="<? echo $row['admin']; ?>"></p> </form> <? } //end while statement } //end if statement mysqli_close($dbc); //include the footer include ("../includes/footer.php"); } ?>
  20. (Using the example in Modern javascript) Am trying to submit data for processing and insertion into the database using php but it could not work and I don't why and these are the steps taking so far. 1. Using php alone, am able to insert data into the database an d this is the php code. <?php try { $linkas = 2; require_once 'db/DBConnect.php'; $errors = []; $good = true; if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['testimony'])): $testimony = filter_input(INPUT_POST, 'testimony', FILTER_SANITIZE_STRING); if (strlen($testimony) < 20): //report error and do not go $errors[] = 'It has to be more than 20 characters' . '<br>'; $good = false; else: $good = true; if ($good): $insertTestimony = 'INSERT INTO testimony(content, j_member_id, time_send) '; $insertTestimony .= 'VALUES (:testimony, :user_id, NOW())'; $insert = $conn1->prepare($insertTestimony); $insert->bindValue(':testimony', $testimony, PDO::PARAM_STR); $insert->bindValue(':user_id', $linkas, PDO::PARAM_INT); $insert->execute(); if ($insert->rowCount() == 1): //success message $_SESSION['msg'] = 'Thanks for the testimony'; header('Location: index.php'); exit(); else: //fail message echo 'Something is wrong, please resubmit'; endif; endif; endif; endif; } catch (Exception $e) { echo 'Database error: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); } ?> After testing the php and seeing that it works, I proceeded to create the html page which is below <html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <section class=""> <article> <div id="testifyForm"> <form action="" method="post" id="testimony" accept-charset="utf-8"> <fieldset> <legend>Your testimony</legend> <label for="testimony"></label> <textarea id="testimony" name="testimony" maxlength="300"></textarea> </fieldset> <input type="submit" name="testify" id="testify" value="Testify"> </form> </div> </article> </section> <script src="js/ajax.js"></script> <script src="js/testify.js"></script> </body> </html> Finally, I created the ajax.js script and testify.js script and placed them inside the js folder and link them to the html which you can see above. This is the testify script function validateForm() { 'use strict'; var testimony = document.getElementById('testimony'); if ((testimony.value.length > 20)) { var ajax = getXMLHttpRequestObject(); ajax.onreadystatechange = function () { if (ajax.readyState == 4) { if ((ajax.status >= 200 && ajax.status < 300) || (ajax.status == 300)) { //return ajax.responseText document.getElementById('testifyForm').innerHTML = ajax.responseText; } else { document.getElementById('theForm').submit(); //return ajax.statusText }//End of status ajax = null; }//End of readyState };//End of onreadystatechange //return true; ajax.open('POST', 'empty.php', true); ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var data = 'testimony=' + encodeURIComponent(testimony.value); ajax.send(data); return false; } else { document.getElementById('error').innerHTML = 'Characters must be more than 20 words'; return false; }//End of testimony } function init() { 'use strict'; if (document && document.getElementById) { var testifyForm = document.getElementById('testifyForm'); testifyForm.onsubmit = validateForm; } } window.onload = init; And this is the ajax script function getXMLHttpRequestObject() { var ajax = null; if (window.XMLHttpRequest) { ajax = new XMLHttpRequest(); } else if (window.ActiveXObject) { // Older IE. ajax = new ActiveXObject('MSXML2.XMLHTTP.3.0'); } return ajax; } The problem now is that ajax refuses to submit those data for processing and saving(which I believe PHP should handle). I also tried debugging it if there is any error by checking the console with ctrl+shift+j on chrome(that is the only step taken so far about debbuging) P.s. This is pure JavaScript and ajax not jquery
  21. This codes works on local server(XAMPP) but does not seems to work on live server. And I can't really figure out what the problem is since there no error is output in the errorlog. In the script, I tried to use the--pre--tag but also nothing gets displayed <?php session_start();?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Testimony</title> </head> <body> <?php try { $linkas = 2; require_once 'db/DBConnect.php'; $errors = []; $good = true; if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['testimony'])): $testimony = /*filter_input(INPUT_POST, 'testimony', FILTER_SANITIZE_STRING)*/$_POST['testimony']; echo $testimony; if (strlen($testimony) < 20): //report error and do not go $errors[] = 'It has to be more than 20 characters' . '<br>'; $good = false; else: echo $testimony; $good = true; if ($good): $insertTestimony = 'INSERT INTO testimony(content, j_member_id) '; $insertTestimony .= 'VALUES (:testimony, :user_id)'; $insert = $conn1->prepare($insertTestimony); $insert->bindValue(':testimony', $testimony, PDO::PARAM_STR); $insert->bindValue(':user_id', $linkas, PDO::PARAM_INT); $insert->execute(); if ($insert->rowCount() == 1): //success message //$_SESSION['msg'] = 'Thanks for the testimony'; header('Location: index.php'); else: //fail message echo 'Something is wrong, please resubmit'; endif; endif; endif; endif; } catch (Exception $e) { echo 'Database error: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); } ?> <section class=""> <article> <form action="" method="post" id="testimony" accept-charset="utf-8"> <fieldset> <legend>Your testimony</legend> <label for="testimony"></label> <textarea id="testimony" name="testimony" maxlength="300"><?php if (isset($_POST['testimony'])): echo htmlspecialchars($testimony); endif; ?></textarea> </fieldset> <input type="submit" name="testify" id="testify" value="Testify"> </form> </article> </section> </body> </html> And this is the database connection string which I used to connect to the database and its located inside the db folder <?php //Db connection 1 $username ="XXXXX"; // censored for SO $password = "XXXXX"; // censored for SO //$database = "xzelanet_180days"; //$server="localhost"; $conn1 = new PDO('mysql:host=localhost;dbname=xzeere_30days; charset=utf8', $username, $password); $conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); After the form submission, the form refuses to insert into the database(the form displayed but does not submit[i think the problem should be inside the code processing the form])
  22. Dear, I'm in Rio de Janeiro, Brazil. I bought the E-Commerce Book with PHP and MySQL. My version of PHP 7 and MySQL 5.7.21, I use WampServer 3.13. I do not know if with the PHP 7 version, I'll be able to follow the book. But I'm trying. I'm already on page 100. Before asking informs that I do not intend to create the site to sell some produro, I am only practicing for study and testing site (on my home computer) I am in doubt about the following: a) I created the ecommer1 database through phpMyAdmin, I imported the sql.sql file from the ex1 folder; a) As I use WampServer, the files are in c: \ wamp \ www and I have to custom create a folder indicating the book that refers to the study and looks like this: c: \ wamp \ www \ studybybook \ bookecommerce \ ex1. Inside the folder ex1 I will create the other html folders, pdfs and save the file mysql.inc according to the downloaded source files. Then I'll create the c: \ wamp \ www \ studybybooks \ bookecommerce \ ex2. Do you have any problems? Can I do it?
  23. Hello Larry and Hello Community, I bought book php and mysql for dynamic web sites in english from USA since i didn't see it in my native language. I gave a look all book for make general feeling and then i will read better and careful example and teching suggestions. Book is very very good in my opinion. My question is about what is best techinque to store html inside mysql database. I'm studying a bit how work CKeditor, but i think many html editor work more or less in same way, and it use a textarea to collect the html, so what you really need to do after a submit or similar processes is simply get the value of texarea and use php to store html in database. I'm asking how handle security, quote and double symbols or other problems. If i have understand i can use directly mysql_real_escape when i get textarea, simply before send html inside mysql or i can use prepared statement and in this case i think i can't use mysql_real_escape so i need pheraps to use htmlentities. I'm a little confuse about conflict you could have use both htmlentities, prepared statement, mysql_real_escape, etc.. I'm not exactly sure how i is best way general speaking in term of 100% secutiry and in term or not ruin html inside mysql and also i'm not sure what is procedure to make the contrary, i mean get html from mysql and serve i in page. Thanks very much. Andrea
  24. I don't know if anybody can put me through how to install composer on live server as I find little or no success at all on the net about how to do it
  25. Script 10#4 works for pagination, in my case 6 pages. Script 10#5 sort on First Name and Last Name work on the initial page display after selected column heading but not for selecting pages after the sort selection. My url shows view_users_3.php as I save each iteration of the scripts to review. Viewing my page then selecting sort by last name shows: url = view_users_3.php?sort=ln The first page of results displays correctly by last name. selecting the page 2: url = view_users_3.php?s=10&p=6&sortln The second page of results is showing user_id's 10 to 19 so has not sorted by last_name. The same situation occurs when I use First Name and Date Registered. I rechecked the code and noted lines 68-70 with the href tags (also from forum Sep 2013) not highlighted but cannot find any other difference with my code. My code: <?php # Chapter 10: Script 10.5: view_users_3.php //This script retrievs all the records from the users table. //This 10.5 version allows results to be sorted in different ways. $page_title = 'View the Current Users'; include ('../includes/header.html'); echo '<h1>Registered Users</h1>'; // Page header require_once ('../includes/mysqli_connect.php'); // Connect to the db. // Number of records to show per page. $display = 10; // Determine how many pages there are ... if (isset($_GET['p']) && is_numeric ($_GET['p'])) { // Already been determined. $pages = $_GET['p']; } else { // Need to determine. // Count the number of records. $q = "SELECT COUNT(user_id) FROM users"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calcualte the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil ($records/$display); } else { $pages = 1; } } // End of p IF. // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric ($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Determine the sort... // Default is by registration date. $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd'; // Determine the sorting order. switch ($sort) { case 'ln': $order_by = 'last_name ASC'; break; case 'fn': $order_by = 'first_name ASC'; break; case 'rd': $order_by = 'registration_date ASC'; break; default: $order_by = 'registration_date ASC'; $sort = 'rd'; break; } // Define the query: $q = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr, user_id FROM users ORDER BY $order_by LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // run the query. // Table header. echo '<table align="center" cellspacing="3" cellpadding="3" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="view_users_3.php?sort=ln">Last Name</a></b></td> <td align="left"><b><a href="view_users_3.php?sort=fn">First Name</a></b></td> <td align="left"><b><a href="view_users_3.php?sort=rd">Date Registered</a></b></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the initial background color. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user.php?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> '; } // End of WHILE loop. echo '</table>'; //Close the table. mysqli_free_result ($r); // Free up the resources. mysqli_close($dbc); // Close the database connection. // Make the links to other pages, if necessary. if ($pages > 1) { echo '<br /><p>'; // Add some spacing and start a paragraph. $current_page = ($start/$display) + 1; // Determine what page the script is on. // If it's not the first page, make a previous link: if ($current_page != 1) { echo '<a href="view_users_3.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_users_3.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort' . $sort . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next button. if ($current_page != $pages) { echo '<a href="view_users_3.php?s=' . ($start + $display) . '&p=' . $pages . '&sort' . $sort . '">Next</a>'; } echo '</p>'; // Close the paragraph. } // End of links section. include ('../includes/footer.html'); ?>
  • Create New...