Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

AdamConder

Members
  • Joined

  • Last visited

Everything posted by AdamConder

  1. Now I'm always getting an incorrect postcode returned? if ((!preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode)) || (!preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/", $postcode)) || (!preg_match("/^GIR0[A-Z]{2}$/", $postcode))) { //die('{status:0,txt:"You haven\'t provided a correct postcode"}'); $response_array['message'] = "You entered an incorrect postcode"; //send the response back echo json_encode($response_array); } elseif (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i", $email)) { //die('{status:0,txt:"You haven\'t provided a valid email"}'); $response_array['message'] = "You entered an incorrect email"; //send the response back echo json_encode($response_array); } else { // create a salt function createSalt() { $string = md5(uniqid(rand(),true)); return substr($string, 0, 3); } // hash password before inserting it into database //convert password to hashkey $hash = hash('sha256', $password); $salt = createSalt(); // has password again with salt added on the end $hash = hash('sha256', $salt . $hash); // get connection $db = pdoDB::getConnection(); $query = $db->prepare("INSERT INTO users (forename, surname, email, houseNum, street, postcode, password, salt) VALUES (:forename, :surname, :email, :houseNum, :street, :postcode, :password, :salt)"); $query->execute(array(':forename' => $forename, ':surname' => $surname, 'email' => $email, ':houseNum' => $house, ':street' => $street, ':postcode' => $postcode, ':password' => $hash, ':salt' => $salt)); //echo '{status:1,txt:"You have successfully registered, you can now login!"}'; $response_array['message'] = "You've successfully registered! You can now login."; //send the response back echo json_encode($response_array); }
  2. If I take out the JSON and simply echo out the errors instead then the form will not post?
  3. Hey, I've got a registration form which is being submitted via AJAX, the form is processed and a JSON response is returned. The problem I've got is that the if statement within processRegistration.php always returns with "fields have not been entered" even when the fields are fully entered. This is the javascript code for the form submission: $.ajax({ type: "POST", url: "includes/registerProcess.php", data: $("registerForm").serialize(), dataType: "json", success: function(msg) { $("#result").html(msg.message); }, error: function(){ $("#result").html("There was an error submitting the form. Please try again."); } }); // make sure the form doesnt post return false; }); And here is the registration validation: <?php /** * * RegisterProcess.php insert registration into database */ session_start(); require_once('pdoDB.class.php'); $forename = $_POST['forename']; $surname = $_POST['surname']; $email = $_POST['email']; $house = $_POST['house']; $street = $_POST['street']; $postcode = $_POST['postcode']; $password = $_POST['password']; // check to see if values are set if (!empty($forename) && !empty($surname) && !empty($email) && !empty($house) && !empty($street) && !empty($postcode) && !empty($password)) { //response array with status code and message $response_array = array(); // escape all html characters $forename = trim(htmlspecialchars($forename)); $surname = trim(htmlspecialchars($surname)); $email = trim(htmlspecialchars($email)); $house = trim(htmlspecialchars($house)); $street = trim(htmlspecialchars($street)); $postcode = trim(htmlspecialchars($postcode)); $password = trim(htmlspecialchars($password)); if (!preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode) || !preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/", $postcode) || !preg_match("/^GIR0[A-Z]{2}$/", $postcode)) { //die('{status:0,txt:"You haven\'t provided a correct postcode"}'); $response_array['message'] = "You entered an incorrect postcode"; } elseif (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i", $email)) { //die('{status:0,txt:"You haven\'t provided a valid email"}'); $response_array['message'] = "You entered an incorrect email"; } else { // create a salt function createSalt() { $string = md5(uniqid(rand(),true)); return substr($string, 0, 3); } // hash password before inserting it into database //convert password to hashkey $hash = hash('sha256', $password); $salt = createSalt(); // has password again with salt added on the end $hash = hash('sha256', $salt . $hash); // get connection $db = pdoDB::getConnection(); $query = $db->prepare("INSERT INTO users (forename, surname, email, houseNum, street, postcode, password, salt) VALUES (:forename, :surname, :email, :houseNum, :street, :postcode, :password, :salt)"); $query->execute(array(':forename' => $forename, ':surname' => $surname, 'email' => $email, ':houseNum' => $house, ':street' => $street, ':postcode' => $postcode, ':password' => $hash, ':salt' => $salt)); //echo '{status:1,txt:"You have successfully registered, you can now login!"}'; $response_array['message'] = "You've successfully registered! You can now login."; } } else { // not all information is set return false //die('{status:0,txt:"You haven\'t filled in each field"}'); $response_array['message'] = "You haven't filled in all the fields!"; } //send the response back echo json_encode($response_array); ?>
  4. That works similar now to what was before, however it does not solve the sliding div situation, cannot get this working for the life of me!
  5. I've changed it so it's now using the on event but it still does not execute the function? $(document).ready(function(){ $(".open").on("click", function() { $("#directionsPanel").animate({right:"0%"},"slow"); $(".open").removeClass().addClass("close"); var src = "images/panelClose.png"; $("#panelControl").attr("src", src); }); $(".close").on("click", function() { $("#directionsPanel").animate({right:"100%"},"slow"); $(".close").removeClass().addClass("open"); var src = "images/panelOpen.png"; $("#panelControl").attr("src", src); }); }); Right 100% is correct for closing it as it works when editing the css directly. <div id="directionsPanel" style="right: 0%"> <img src="images/panelOpen.png" id="panelControl" class="open" alt="Panel control" /> </div> Is what it gets changed to after the first click event.
  6. Hey, I'm currently developing a web application (university project) and I've implemented a div which will open on a click event, it slides open from the right but when I go to click it again it does not close (does not call function). What I'm doing is changing the class name of the icon to open the div to 'close', from here the jquery listen for a click event on this and should close the div. I think the problem lies that the class 'close' does not exist on document ready therefore it will not recognise the class? $(".open").click(function() { $("#directionsPanel").animate({right:"0%"},"slow"); $(".open").removeClass().addClass("close"); }); $(".close").click(function() { $("#directionsPanel").animate({left:"100%"},"slow"); $(".close").removeClass().addClass("open"); }); <div id="directionsPanel"> <img src="images/panelOpen.png" id="panelControl" class="open" alt="Panel control" /> </div> </div>
  7. Apologies for earlier, stressful times put in in an agitated mood. Been trying to solve this for a while now but I can't figure it out. I've got two sets of users, jobseekers and employers (they both have profiles and messaging functionality) however, I need to pull from the jobseekers or employers table depending on what matches in the where clause. freshjobs.txt
  8. Ohh great and how much help was that, if you had of read the question you may have understood my problem? I'm well aware how to join a table(s).
  9. Hey, I'm currently developing a website where it's a job application website. I am currently trying to retrieve messages in a thread system for the messaging system of the website. The problem I'm having is I have jobseekers and employers (different users) stored in two tables, and also a generic users table that link them both. The current query i'm performing is: SELECT userid, userEmail, userAvatar, messageid, senderid, dateSent, timeSent, messageContent, favourite, empName, empDepartment, empIndustry, jsForename, jsSurname, jsEmpStatus FROM users JOIN messages ON (users.userid = messages.senderid) JOIN employers ON (users.userid = employers.empid) JOIN jobseekers ON (jobseekers.jsid = users.userid) WHERE recipientid = '2' recipientid is gathered from a session for the user currently logged in, i.e. all the messages sent to that user. The query works perfectly fine like this: SELECT userid, userEmail, userAvatar, messageid, senderid, dateSent, timeSent, messageContent, favourite, jsForename, jsSurname, jsEmpStatus FROM users JOIN messages ON (users.userid = messages.senderid) JOIN jobseekers ON (jobseekers.jsid = users.userid) WHERE recipientid = '2' And visa versa, however, if I add the fourth table it returns no results. There are results in the database as I've manually added them. The other option I have tried is by using a union to perform the search: SELECT userid, userEmail, userAvatar, messageid, senderid, dateSent, timeSent, messageContent, favourite, empName, empDepartment, empIndustry, NULL , NULL , NULL FROM users JOIN messages ON ( users.userid = messages.senderid ) JOIN employers ON ( users.userid = employers.empid ) WHERE recipientid = '2' UNION SELECT userid, userEmail, userAvatar, messageid, senderid, dateSent, timeSent, messageContent, favourite, NULL , NULL , NULL , jsForename, jsSurname, jsEmpStatus FROM users JOIN messages ON ( users.userid = messages.senderid ) JOIN jobseekers ON ( jobseekers.jsid = users.userid ) WHERE recipientid = '2' However, the column names jsForename, jsSurname and jsEmpStatus are returned as null? Therefore I can't target them when filtering results in while statement.
  10. This fixed it: <?php $post_id = $post->ID; ?> <?php $comments = get_comments(array('post_id' => $post_id)); ?>
  11. Problem now is how can I specify the post id? It's returning all comments something like: <?php $comments = get_comments($post->ID); ?>
  12. Solved: <?php $comments = get_comments(); ?> Thanks for the prompt
  13. I was thinking the same, but everywhere I've looked is the same. Surely need to store a SQL statement inside and check if anything has been returned? Or is $comments a global variable that wp understands?
  14. Hey I've been trying to get this to work for a while now: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="entry"> <h3><?php the_title(); ?><span class="comment_count"><?php comments_number('No Comments','One Comment','% Comments'); ?></span></h3> <?php the_content(); ?> <div class="post_details"> <p>Author: <span class="author"><?php the_author(); ?>.</span></p> <p>Posted On: <span class="date_posted"><?php echo get_the_date(); ?></span></p> </div> </div> <!-- end entry div --> <h3>Comments</h3> <?php if($comments) : ?> <ul class="comments"> <?php foreach($comments as $comment) : ?> <div class="comment_meta"> <?php echo get_avatar(); ?> <span class="name"><a href="<?php comment_author_link(); ?>"><?php comment_author(); ?></a></span> <span class="date"><?php comment_date(); ?></span> </div> <?php if($comment->comment_approved == '0') : ?> <li class="comment_content"><p>Your comment is awaiting approval.</p></li> <?php endif; ?> <li class="comment_content"><?php comment_text(); ?></li> <?php endforeach; ?> </ul> <?php else : ?> <p>No comments currently for this post.</p> <?php endif; ?> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <?php comment_form(); ?>] Can anyone see a fault with the code as all that's ever returned is 'No comments currently for this post.' Or is this method now depreciated with the use of wp_list_comments(); ? Thanks, Adam.
  15. Sorted, this should have been: [code] // take values entered from update form and process into database public function updateRecordResult($shoeName, $size, $colour, $gender, $price, $description, $shoeID, $brand, $brandID) { $query = "update shoe set shoeName = '$shoeName', shoeSize = '$size', colour = '$colour', gender = '$gender', price = '$price', description = '$description' where shoeID = '$shoeID'"; $query2 = "update brand set brandName = '$brand' where brandID = '$brandID'"; $result = mysql_query($query) or die(mysql_error()); $result2 = mysql_query($query2) or die(mysql_error()); echo "<p>Record \"$shoeID\", successfully updated.</p>\n"; echo $shoeID; echo "<p>Record updated on brand table \"$brand\"</p>\n"; }
  16. That's solved the echoing problem however when updating a record from the form it's still replacing all the shoe names with the one entered. There's clearly something wrong with the query but I can't see it?
  17. I'm having a bit of a problem with an updateResult function I have: This one populates the form with results from a database: // populate form fields with data from database public function updateRecordPopulate($shoeID) { $query = "select brandName, shoeID, shoeName, shoeSize, colour, gender, price, description from shoe natural join brand where shoeID = '$shoeID'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $brand = $row['brandName']; $shoeID = $row['shoeID']; $shoeName = $row['shoeName']; $size = $row['shoeSize']; $colour = $row['colour']; $gender = $row['gender']; $price = $row['price']; $description = $row['description']; } echo "<form id=\"updateRecord\" action=\"updateRecordProcess.php\" method=\"get\"> <fieldset> <legend>Update Record</legend> <input type=\"hidden\" name=\"shoeID\" id=\"$shoeID\" /> <label for=\"brand\">Brand:</label><br /> <input type=\"text\" name=\"brand\" value=\"$brand\" id=\"brand\" /><br /> <label for=\"shoeName\">Model:</label><br /> <input type=\"text\" name=\"shoeName\" value=\"$shoeName\" id=\"shoeName\" /><br /> <label for=\"shoeSize\">Size:</label><br /> <input type=\"text\" name=\"shoeSize\" value=\"$size\" id=\"shoeSize\" /><br /> <label for=\"colour\">Colour:</label><br /> <input type=\"text\" name=\"colour\" value=\"$colour\" id=\"colour\" /><br /> <label for=\"gender\">Gender:</label><br /> <input type=\"text\" name=\"gender\" value=\"$gender\" id=\"gender\" /><br /> <label for=\"price\">Price:</label><br /> <input type=\"text\" name=\"price\" value=\"$price\" id=\"price\" /><br /> <label for=\"description\">Description:</label><br /> <input type=\"textfield\" name=\"description\" value=\"$description\" id=\"description\" /><br /> <input type=\"submit\" value=\"Submit\" /> </fieldset> </form>"; } This is where the variables are passed to: $brand = trim($_GET['brand']); $shoeName = trim($_GET['shoeName']); $shoeID = $_GET['shoeID']; $size = trim($_GET['shoeSize']); $colour = trim($_GET['colour']); $gender = trim($_GET['gender']); $price = trim($_GET['price']); $description = trim($_GET['description']); $database->getConnection(); $database->updateRecordResult($shoeName, $size, $colour, $gender, $price, $description, $shoeID, $brand); $database->closeConnection(); And this is the update function: // take values entered from update form and process into database public function updateRecordResult($shoeName, $size, $colour, $gender, $price, $description, $shoeID, $brand) { $query = "update shoe set shoeName = '$shoeName', shoeSize = '$size', colour = '$colour', gender = '$gender', price = '$price', description = '$description' where shoeID = '$shoeID'"; $query2 = "update brand set brandName = '$brand'"; $result = mysql_query($query) or die(mysql_error()); $result2 = mysql_query($query2) or die(mysql_error()); echo "<p>Record \"$shoeID\", successfully updated.</p>\n"; echo $shoeID; echo "<p>Record updated on brand table \"$brand\"</p>\n"; } However, the shoeID is not being passed through the hidden field therefore it's updating all the records in the database with the same shoe name ($brand). Can see here it's not passing: updateRecordProcess.php?shoeID=&brand=G-Star&shoeName=Pro Anyone help?
  18. Okay that seemed to do the trick except I'm not returning anything care to explain what it does? Also my code is: <?php require_once("includes/functions.php"); require_once("includes/database.php"); $brand = isset($_GET['brandName']) ? $_GET['brandName'] : null; $colour = isset($_GET['colour']) ? $_GET['colour'] : null; $size = isset($_GET['shoeSize']) ? $_GET['shoeSize'] : null; $gender = isset($_GET['gender']) ? $_GET['gender'] : null; echo $brand; $filterProcess = new webPage("default.css", "Feet First - Filter Products", "Feet First - Filter"); // parameters: css, title, header $database = new database(); $filterProcess->makeHeader(); $filterProcess->makeNavigation(); $filterProcess->startContent("Filter Results"); //parameter is h1 tag $database->getConnection(); //get database connection $database->filterBrandProcess($brand); //create a filterProcess form again $database->closeConnection(); //close database connection $filterProcess->endContent(); $filterProcess->startSidebar("Filter by Category"); // parameter is h3 tag ?> // filter brand process public function filterBrandProcess($brand) { $query = "select brandName, shoeName, shoeSize, colour, gender, price from shoe natural join brand where brandName = '$brand'"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $brandName = $row['brandName']; $shoeName = $row['shoeName']; $shoeSize = $row['shoeSize']; $colour = $row['colour']; $gender = $row['gender']; $price = $row['price']; echo "<table id=\"table\">\n"; echo "<tr id=\"header\"><td>Brand</<tr><td>Name</td><td>Size</td><td>Colour</td><td>Gender</td><td>Price</td></tr>\n"; echo "<tr><td>$brandName</td><td>$shoeName</td><td>$shoeSize</td><td>$colour</td><td>$gender</td><td>$price</td></tr>\n"; echo "</table>\n"; } }
  19. Anyone? At the moment I have: // filter colour function public function filterColour() { $query = "select distinct colour from shoe"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $colour = $row['colour']; echo "<a href=\"filterProcess.php?colour=$colour\"><li>$colour</li><a/>"; } } // filter size function public function filterSize() { $query = "select distinct shoeSize from shoe order by shoeSize asc"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $size = $row['shoeSize']; echo "<a href=\"filterProcess.php?size=$size\"><li>$size</li><a/>"; } } //filter gender function public function filterGender() { $query = "select distinct gender from shoe"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $gender = $row['gender']; echo "<a href=\"filterProcess.php?gender=$gender\"><li>$gender</li><a/>"; } } Etc... And on the form processing page I have: <?php $brand = $_GET['brandName']; $colour = $_GET['colour']; $size = $_GET['shoeSize']; $gender = $_GET['gender']; echo $gender; echo $colour; echo $size; echo $brand; ?> Of course, using the method above I get an undefined variable error for the one that has not been sent. Anyway to check to see if there has indeed been one sent?
  20. I'm wondering if it's possible to pass a variable though an anchor tag, then use this to determine a sql query: //filter gender function public function filterGender() { $query = "select distinct gender from shoe"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $gender = $row['gender']; echo "<a href=\"filterProcess.php?gender=$gender\"><li>$gender</li><a/>"; } } Something like that? If possible, how do I then get this variable? Like, $_GET['whatever']; ?
  21. CLOSED - It's working now. Thanks.
  22. Hey, I'm trying to create a search form that will pull back information from the database depending on what's entered: // get value sent from the form $search = trim($_GET['search']); // check to see if string is empty if($search == "") { echo "<p>Please enter a valid search term</p>"; } else { $database->searchResults($search); } $searchProcess->endContent(); $searchProcess->makeSidebar("Filter by Category"); // parameter is h3 tag $searchProcess->makeFooter(); ?> public function searchResults($search) { $query = "select brandName, shoeName, shoeSize, colour, gender, price from shoe natural join brand where brandName = '$search' or shoeName = '$search' or shoeSize = '$search' or colour = '$search' or gender = '$search'"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $brandName = $row['brandName']; $shoeName = $row['shoeName']; $shoeSize = $row['shoeSize']; $colour = $row['colour']; $gender = $row['gender']; $price = $row['price']; echo "<table id=\"table\">\n"; echo "<tr id=\"header\"><td>Brand</<tr><td>Name</td><td>Size</td><td>Colour</td><td>Gender</td><td>Price</td></tr>\n"; echo "<tr><td>$brandName</td><td>$shoeName</td><td>$shoeSize</td><td>$colour</td><td>$gender</td><td>$price</td></tr>\n"; echo "</table>\n"; } } However, I'm getting an error on the mysql_fetch_assoc and can't see why?
  23. Yes because If I use a procedural method: $database->getconnection(); echo "<table>"; echo "<tr id=\"tableHeader\"><td>Shoe ID</td><td>Brand ID</td><td>Name</td><td>Size</td><td>Colour</td><td>Gender</td><td>Price</td><td>Description</td></tr>\n"; while($row = mysql_fetch_assoc($result)) { $shoeID = $row['shoeID']; $brandID = $row['brandID']; $shoeName = $row['shoeName']; $shoeSize = $row['shoeSize']; $colour = $row['colour']; $gender = $row['gender']; $price = $row['price']; $description = $row['description']; echo "<tr><td>$shoeID</td><td>$brandID</td><td>$shoeName</td><td>$shoeSize</td><td>$colour</td><td>$gender</td><td>$price</td><td>$description</td></tr>\n"; } echo "</table>"; } It works correctly. Basically I need something that will do that but in oop? classes etc. But if I do it this way I can't add it to my $product->addToContent() function and it renders outside the html.
  24. Okay I've came up with this: $database = new database(); $database->getConnection(); $database->query("Select * from shoe"); $database->getRow($result); $database->fetchRow($result); public function query($query) { $this->query = $query; $result = mysql_query($query) or die("Query Failed" . mysql_error()); return $result; } public function getRow($result) { $this->result = $result; return mysql_fetch_assoc($result); } public function fetchRow($result) { $this->result = $result; return mysql_fetch_array($result); } public function closeConnection() { mysql_close($this->connection); } But get this error message: Notice: Undefined variable: result in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_v010093/public_html/feetfirst/products.php on line 15 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_v010093/public_html/feetfirst/includes/database.php on line 23 Notice: Undefined variable: result in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_v010093/public_html/feetfirst/products.php on line 16 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_v010093/public_html/feetfirst/includes/database.php on line 28

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.