Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'php'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 176 results

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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"); } ?>
  7. (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
  8. 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?
  9. 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])
  10. 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
  11. 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
  12. Hi everyone, I'm building my own shopping website. I haven't figured out how to populate two dropdown lists with available sizes and colors of a product_id from database. Here is the result I've got from querying database. id product_name style size color price image sku stock 1 Neck Top 104 S White $30.00 104.jpg 104-1 5 2 Neck Top 104 S Black $30.00 104.jpg 104-2 5 3 Neck Top 104 M Red $30.00 104.jpg 104-3 10 4 Neck Top 104 L Blue $30.00 104.jpg 104-4 10 5 Neck Top 104 XL Black $30.00 104.jpg 104-5 5 And here are my tables: tblProduct tblSizes tblColors tblSpecific_Products id id id id product_name size color product_id style size_id price color_id image stock category (tops,dresses,bottoms,...) subcategory (bodycon,work,evening,cocktail) Is there any way I can have it done without duplicating the values in each dropdown list? Also for each product_id, how can I store 3 different images (front view,back view and side view) for each color? Does it mean I have to create another attribute table for those images and store their names in database? I'm confused.
  13. 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'); ?>
  14. i have some css tags in the header for my stylesheet and bootstrap and i tried to include the header.html as learnt from the book but it failed to load up instead it load up plain html. -My index.php: <?php require ('includes/config.inc.php'); $page_title = 'Homepage'; include ('includes/header.html'); ?> <?php include ('includes/footer.html'); ?> -My header.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title><?php echo $page_title; ?></title> <link href="../css/bootstrap.min.css" rel="stylesheet"> <link href="nav.css" rel="stylesheet"> <script src="http://cdn.ckeditor.com/4.6.1/standard/ckeditor.js"></script> </head> <body> <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">WEBNAME</a> </div> <div id="navbar" class="collapse navbar-collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="../index.php">Home</a></li> <li><a href="../pages.html">Recent</a></li> <li><a href="../posts.html">Posts</a></li> <li><a href="../users.html">Users</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href="#">Welcome</a></li> <li><a href="login.php">Logout</a></li> </ul> </div><!--/.nav-collapse --> </div> </nav> PLEASE HELP
  15. Good day! First off, great book sofar! I am only on chapter 2 and I love it. (I don't have excel tho so unsure if the database parts will work) Anywho, I am creating different handle_forms to see if I can have it give different responses as I go along. However, it constantly reverts back to handle_form.php even when I go into the html document and change <form action="handle_form.php" method="post"> to <form action="handle_form1.php" method="post"> Am I missing something on how to do that to test different forms?
  16. Hello, Hope you are doing great. I belong to a web development community and recently got hired in a logo design company to manage their site development issues. Basically, the website is designed quite well without any front-end issues but it has some backend issues that needs to be fixed. As they have given me a new task to add up a CMS into the backend of their website. I have already worked on Word press so I know how to configure it but as they want it on Drupal platform, I don’t know much about it. Although I have used Drupal and other CMS sites too but never got a chance to configure it in my previous experiences. So, here is what the error looks like: (see image below) An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /drupal/core/install.? rewrite=ok&langcode=en&profile=standard &continue=1&id=1&op=do_nojs&op=do StatusText: OK ResponseText: Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\drupal\core\lib\Drupal\Core\ Database\Statement.php on line 59 Now, I would really appreciate if you could let me know how to get this issue fixed. Because the website is already built on using PHP so I am sure it won’t be that difficult to handle this error. Looking forward towards your valuable comments.
  17. Hi Larry I thought that I'd post this as it might help other php-ers. I have a website which has many images. To facilitate the download of images, I save a reduced image under a directory name e.g. images/activities/P3451098.jpg for thumbnails and slideshows as well as the full size in e.g. images/raw/P3451098.jpg. Then I can offer an enlarged image using <a href = ***><img src...... target = "_blank"> etc. The problem is that as I send the images up using FTP (Filezilla) I can't be sure if all of the reduced images have the corresponding full sized images thanks to advanced dementia. Therefore, I have written a short routine to compare the two directories.... COMMENTS: 1) I was confused at first as to why it didn't work properly until I discovered that glob() is case sensitive, so that it wasn't finding .JPGs so had to run it twice (there is a variety of both depending on which camera they came from). 2) The search routine is not very elegant as it runs through all of the raw files even though it may have found a match in the first file. 3) I know that I could use glob(images/raw/*.*) instead of glob(images/raw/*.*) and in this case it wouldn't make any difference as all files in these directories are .jpgs - it just seems more precise to use *.jpg. I would appreciate any comments from anybody..... <?php //Declare variable $found to avoid undefined variable errors $found = "No"; //Call header which handles security and error messages include ('adminheader.php'); //Create an array $images which lists all of the relevant image directories on the server.. $images = array('4X4', 'activities', 'almonds', 'alojamiento', 'altiplano', 'archery', 'area', 'artifacts', 'baza', 'castillejar', 'castril', 'caving', 'fiestas', 'flowers', 'history', 'huescar', 'kayaking', 'index', 'markets', 'mountaineering', 'mountains', 'museums', 'photography', 'puebla', 'rafting', 'village', 'wildlife', 'activities/activities', 'activities/caving', 'activities/kayaking', 'activities/mountaineering', 'activities/outdoors', 'activities/rafting'); //Create array $raw which will be a listing of all of the large image files on the server $raw = glob('images/raw/*.jpg'); $raw2 = glob('images/raw/*.JPG'); //Work through the $images array so as to compare whether there is a large matching file in the 'raw' directory... foreach($images as $key => $category) { //Start with a header to ID each category.... echo 'CATEGORY:... ' . $category . '<br /><br />'; //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.jpg'; //create an array of the files in this category.. $listing = glob($getlisting); //Run through the $raw array to see if it contains a file that matches the file in the category... foreach($listing as $key => $value) { //Create variable to use in str_replace.. $directory = 'images/' . $category . '/'; // Remove the unwanted directory details.... $value = str_replace($directory, "", $value); //Reduce any JPGs to jpgs... $value = strtolower($value); //Run through the $raw array to find a match.. foreach($raw as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //Run through the $raw array to find a match.. foreach($raw2 as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //If small and large files don't match, then print out the filename .. if ($found != "Found") { echo $value . "<br /><br />"; } //reset $found to "Not found".. $found = "No"; } //Close individual Category foreach echo "<br /><br />"; } //Close all category foreach echo "ALL DONE!"; include ('footer.php'); ?>
  18. This is related to another question I asked that I haven't managed to resolve, so I'm trying something else! I have an associative array fetched from mysql, and I need to sum values based on the value in a different column. I have created an associative array, and printed to screen and it looks okay. It returns what I need, and looks like [1] => 779700.00 ) Array ( [4] => 868.00 ) Array ( [2] => 102000.00 ) Array ( [2] => 775808.00 My problem is that I need to be able to sum the results for each individual key value pair (so eg '2' would sum to 877808.00) - there are only eight key values, and I need a variable to hold each one. I have read lots of similar questions and have tried the solutions, but have just got myself hopelessly confused. I assume I need a foreach loop, please could somebody point me in the right direction for what I need to do? I'm not sure if I'm barking up the wrong tree or not. Thanks. while($row_outputs=mysqli_fetch_array($run_projects)) { $Id = $row_outputs['id']; $impact = $row_outputs['impact']; $cost = $row_outputs['total_cost']; $summing_array = array($impact=>$cost);
  19. I'm having a bit of a problem which I think I might know the solution, but I'm really struggling to know the correct syntax. If somebody could point me in the right direction I'd be very grateful. I've created an application where users can create projects, and within the projects there are 'outputs' and 'inputs'. All of which is stored in separate MySql tables. It works fine. I have now been asked to create an addition layer, a 'programme' layer, which sits above projects (ie there can be multiple projects within one programme). I think I have got my table normalisation correct, I created 2 tables, 'programmes' which stores programme id and name etc, and 'programmes_projects' which stores only the programme id and the project id. That seems to work ok. What I'm having trouble with, is displaying the results correctly. I need to retrieve information from 4 (actually 5) related MySql tables. Phew. I think I need to create an associative array and a foreach loop, but because of the number of tables and the relationships, I'm getting very confused. I'm not sure if I should be focussing on the sql statements, the php, or what. I tried using while loops, because that's what I know, but wasn't surprised that it didn't work. progId = $_GET['prog']; //get the individual projects from the linking db table $get_projects = "SELECT * FROM programmes_projects WHERE prog_id=$progId"; $run_projects = mysqli_query($conn, $get_projects); $i = 0; while($row_projects=mysqli_fetch_array($run_projects)){ $prog_proj_id = $row_projects['prog_proj_id']; $prog_id = $row_projects['prog_id']; $projectId = $row_projects['proj_id']; $i++; //attempting to collect project details from the outputs table $get_proj_details = "SELECT * FROM projects WHERE project_id=$projectId"; $fetch_projects = mysqli_query($conn, $get_proj_details); $i = 0; while($row_details=mysqli_fetch_array($fetch_projects)){ $proj_name = $row_details['project_name']; $proj_whatever = $row_details['date']; $i++; // project outputs $fetch_outputs = "SELECT * FROM projects_outputs WHERE project_id=$projectId"; $get_outputs = mysqli_query($conn, $fetch_outputs); $i = 0; while($row_outputs=mysqli_fetch_array($get_outputs)){ $out_id = $row_outputs['output_id']; $output_desc = $row_outputs['output_desc']; $i++; }}}?> Please could someone help?? Even if it's just a nudge in the right direction. Thank you very much.
  20. Hi Larry my name is sam can i first start by saying i absolutely love your books. i am currently working on a project where i have built the php side of things and now working on enhancing using javascript. i am adapting your script from your Modern javascript develop and design book on chapter 15, (view.js). But the problem i have is my php script loops through the database to show results and i am trying to pass the id of the data, like you do in your view.php script to the view.js script with, <script> var itemId = ' . $itemid .'; </script> BUT i have a while loop on the php script and the script tags are in the while loop like this, $query = "SELECT `item_id` FROM items"; $results = mysqli_query ($dbc, $query); while (list ($item_id ) = mysqli_fetch_array($results, MYSQLI_NUM)) { // Start the while Loop here ... echo '<form action="" method="post" id="bidForm" class="bidForm"> <input class="button" type="submit" value="Like" title="Like"> <input type="hidden" name="item_id" id="item_id" class="video" value="' . $item_id . '"> </form>'; ?> <script> var itemId = "<?php echo $item_id; ?>"; </script> } // End of while Loop here .. then link to external js script <script src="js/ajaxBid.js"></script> Just so you know this is not exact just example above but it does the exact same thing. So the problem is where it Loops the var itemId gets more then one value so you don't get the value of the button clicked sent to the ajax script. How can i get the id of the button clicked in my js script while still in the while loop???? sorry if this is really confusing i will answer any questions you might have. if you or anyone could explain in the simplest possible way where I'm going wrong as not brilliant at javascript yet, that would be amazing been stuck for ages on this. many thanks, Sam
  21. Hi I'm trying to find out 2 things, 1) how to pass a button value that comes from mysqli while loop to javascript then on to Ajax script. 2) how to pass a php array on to javascript and then onto the Ajax script. I will be really grateful if anyone could help. many thanks sam
  22. Here's a general question... I suspect most of us have done it at some time - I certainly have - uploading a program by mistake to a server, that has an infinite loop in it (usually 'while(){....}') which means that the program whizzes round a million times sending hundreds of error messages to your e-mail address. QUESTION: Eventually the server will kill the program automatically, but is there any way (in php or otherwise server-side) to kill it? I suppose one could add a line in the loop such as $x+; if (x$>'1000'){die()} to save this embarrassment! "To err is human, but it takes a computer to REALLY $&** things up!!"
  23. There is something about php that I have trouble understand coming from using javascript like angular. How does routing in php work exactly? Like how does a php site know about going to a link (/browse/coffee/Dark+Roast/2) or a shop/product link. How does the htacess file works with the site. Currently, when going to a link the /shop/coffee, it responds by not found. I tried to look it up but I don't understand it per say as it different from the way I normally do it in javascript. <body id="page1"> <!-- header --> <div id="header"> <div class="container"> <div class="wrapper"> <ul class="top-links"> <li><a href="/index.php" class="first"><img alt="" src="/images/icon-home.gif" /></a></li> <li><a href="/cart.php"><img alt="" src="/images/icon-cart.gif" /></a></li> <li><a href="/contact.php"><img alt="" src="/images/icon-mail.gif" /></a></li> <li><a href="/sitemap.php"><img alt="" src="/images/icon-map.gif" /></a></li> </ul> <div class="logo"> <h1><a href="/index.php">Coffee</a><span>Wouldn't you love a cup right now?</span></h1> </div> </div> <ul class="nav"> <!-- MENU --> <li><a href="/shop/coffee/">Coffee</a></li> <li><a href="/shop/goodies/">Goodies</a></li> <li><a href="/shop/sales/">Sales</a></li> <li><a href="/wishlist.php">Wish List</a></li> <li><a href="/cart.php">Cart</a></li> <!-- END MENU --> </ul> </div> </div> <!-- content --> <div id="content"> <div class="container"> <div class="inside">
  24. I've just started this book and am really confused with an expression. Can somebody please explain the mechanism behind the expression, given below, used in Script 1.1 - sort.php return ($x < $y) // Creating an array $a = [1, 5]; // creating comparison function using the above expression function comp1($x, $y) { return ($x < $y); } // using uasort() uasort($a, 'comp1'); // output the result echo '<pre>' . print_r($a, 1) . '</pre>'; // creating the same function as above but interchanging the arguments position function comp2($y, $x) { return ($x < $y); } // using uasort() uasort($a, 'comp2'); // output the result echo '<pre>' . print_r($a, 1) . '</pre>'; This outputs Array ( [1] => 5 [0] => 1 ) Array ( [0] => 1 [1] => 5 ) Observation: reversing the position of arguments in function definition reverses the sort output. Can somebody please explain the 'mechanism' about using the expression return ($x < $y) - How and which values are returned.
  25. I am looking to recreate the following function from PDO to MySQLi but having some problems, I've been over the PHP website to read the functions. I'm trying to modularize my code in like the MVC pattern. public function bind($param, $value, $type=''){ if(is_null($type)){ switch(true){ case is_int($value): //Thinking something like, for integer etc $type = mysqli_stmt::bind_param(i); $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; default: $type = PDO::PARAM_STR; } } $this->stmt->bindvalue($param,$value,$type); } Is it as simple as just replacing PDO version line to : $type = mysqli_stmt::bind(i); or just putting $type = i; Then in my class I am trying to call the bind function: $database ->bind($stmt,$ype,$variables); $database->execute(); Any help would be much appreciated Regards My Setup Chrome Windows XP Wamp SublimeText
×