Jump to content

old_blueyes

Members
  • Content Count

    14
  • Joined

  • Last visited

Community Reputation

0 Neutral

About old_blueyes

  • Rank
    Member
  1. That's what I thought, i've had another go and it's now working, thank you for all your help!!
  2. Thanks very much Jacques!! I don't suppose you know how the wp_update_post() function would be implemented into your solution?? Thanks
  3. Hi, I am having a small issue with a front end html form, which through a series of looped input fields will update multiple WordPress posts at once, on submisson. The issue i'm having currently, is on submission it's only updating 1 post. I have found a solution to my problem, here: http://wordpress.stackexchange.com/questions/206372/how-to-handle-dynamic-form-data-with-repeating-fields But as i am still a bit of a novice, I have tried to apply the max_id solution to my code below, so far i've not got it to work. Using the solution on the above link, I don't suppose someone could show/tell me, what the code should be in it's entirety?? Including the foreach section, thanks! foreach( $testArray as $value ) { $post_information = array( 'post_title' => $value, 'post_status' => 'publish', // Choose: publish, preview, future, draft, etc. 'post_type' => 'predictions' //'post',page' or use a custom post type if you want to ); //update post wp_update_post($post_information);
  4. Hi, Just wondering if someone could point me in the right direction, I have a simple PHP MySQL login script which passes/stores data via sessions. It works fine, there is no problem with it. All I would like to do is pass some additional data from the users MySQL table. Currently it users just username and password, but I would like it to pass firstname and surname data as well. So when a user logs in with their username and password, on the next page it might say Welcome, Michael Smith. The script below is originally setup for the username to be a persons name, as it's used in the login welcome message in the login.php But I might change the username to be an email address, if I can pull in the additional data. config.php <?php /***************************** File: includes/config.php Written by: Frost of Slunked.com Tutorial: User Registration and Login System ******************************/ // start the session before any output. session_start(); // Set the folder for our includes $sFolder = '/predictor/login'; /*************** Database Connection You will need to change the user (user) and password (password) to what your database information uses. Same with the database name if you used something else. ****************/ mysql_connect('localhost', 'root', '') or trigger_error("Unable to connect to the database: " . mysql_error()); mysql_select_db('football') or trigger_error("Unable to switch to the database: " . mysql_error()); /*************** password salts are used to ensure a secure password hash and make your passwords much harder to be broken into Change these to be whatever you want, just try and limit them to 10-20 characters each to avoid collisions. ****************/ define('SALT1', '24859f@#$#@$'); define('SALT2', '^&@#_-=+Afda$#%'); // require the function file require_once($_SERVER['DOCUMENT_ROOT'] . $sFolder . '/includes/functions.php'); // default the error variable to empty. $_SESSION['error'] = ""; // declare $sOutput so we do not have to do this on each page. $sOutput=""; ?> login.php <?php /***************************** File: login.php Written by: Frost of Slunked.com Tutorial: User Registration and Login System ******************************/ require($_SERVER['DOCUMENT_ROOT'] . '/predictor/login/includes/config.php'); // If the user is logging in or out // then lets execute the proper functions if (isset($_GET['action'])) { switch (strtolower($_GET['action'])) { case 'login': if (isset($_POST['username']) && isset($_POST['password'])) { // We have both variables. Pass them to our validation function if (!validateUser($_POST['username'], $_POST['password'])) { // Well there was an error. Set the message and unset // the action so the normal form appears. $_SESSION['error'] = "Bad username or password supplied."; unset($_GET['action']); } }else { $_SESSION['error'] = "Username and Password are required to login."; unset($_GET['action']); } break; case 'logout': // If they are logged in log them out. // If they are not logged in, well nothing needs to be done. if (loggedIn()) { logoutUser(); $sOutput .= '<h1>Logged out!</h1><br />You have been logged out successfully. <br /><h4>Would you like to go to <a href="index.php">site index</a>?</h4>'; }else { // unset the action to display the login form. unset($_GET['action']); } break; } } $sOutput .= '<div id="index-body">'; // See if the user is logged in. If they are greet them // and provide them with a means to logout. if (loggedIn()) { $sOutput .= '<h1>Logged In!</h1><br /><br /> Hello, ' . $_SESSION["username"] . ' how are you today?<br /><br /> <h4>Would you like to <a href="login.php?action=logout">logout</a>?</h4> <h4>Would you like to go to <a href="index.php">site index</a>?</h4>'; }elseif (!isset($_GET['action'])) { // incase there was an error // see if we have a previous username $sUsername = ""; if (isset($_POST['username'])) { $sUsername = $_POST['username']; } $sError = ""; if (isset($_SESSION['error'])) { $sError = '<span id="error">' . $_SESSION['error'] . '</span><br />'; } $sOutput .= '<h2>Login to our site</h2><br /> <div id="login-form"> ' . $sError . ' <form name="login" method="post" action="login.php?action=login"> Username: <input type="text" name="username" value="' . $sUsername . '" /><br /> Password: <input type="password" name="password" value="" /><br /><br /> <input type="submit" name="submit" value="Login!" /> </form> </div> <h4>Would you like to <a href="login.php">login</a>?</h4> <h4>Create a new <a href="register.php">account</a>?</h4>'; } $sOutput .= '</div>'; // lets display our output string. echo $sOutput; ?> functions.php <?php /***************************** File: includes/functions.php Written by: Frost of Slunked.com Tutorial: User Registration and Login System ******************************/ /*********** bool createAccount (string $pUsername, string $pPassword) Attempt to create an account for the passed in username and password. ************/ function createAccount($pUsername, $pPassword, $pFirstname, $pSurname) { // First check we have data passed in. if (!empty($pUsername) && !empty($pPassword) && !empty($pFirstname) && !empty($pSurname)) { $uLen = strlen($pUsername); $pLen = strlen($pPassword); $fLen = strlen($pFirstname); $sLen = strlen($pSurname); // escape the $pUsername to avoid SQL Injections $eUsername = mysql_real_escape_string($pUsername); $sql = "SELECT username FROM users WHERE username = '" . $eUsername . "' LIMIT 1"; // Note the use of trigger_error instead of or die. $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); // Error checks (Should be explained with the error) if ($uLen <= 4 || $uLen >= 11) { $_SESSION['error'] = "Username must be between 4 and 11 characters."; }elseif ($pLen < 6) { $_SESSION['error'] = "Password must be longer then 6 characters."; }elseif (mysql_num_rows($query) == 1) { $_SESSION['error'] = "Username already exists."; }else { // All errors passed lets // Create our insert SQL by hashing the password and using the escaped Username. $sql = "INSERT INTO users (`username`, `password`, `firstname`, `surname`) VALUES ('" . $eUsername . "', '" . hashPassword($pPassword, SALT1, SALT2) . "', '" . $pFirstname . "', '" . $pSurname . "');"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); $sql2 = "INSERT INTO predictions (userID, predictionID, week) SELECT LAST_INSERT_ID(), id, week FROM fixtures"; $query = mysql_query($sql2) or trigger_error("Query Failed: " . mysql_error()); if ($query) { return true; } } } return false; } /*********** string hashPassword (string $pPassword, string $pSalt1, string $pSalt2) This will create a SHA1 hash of the password using 2 salts that the user specifies. ************/ function hashPassword($pPassword, $pSalt1="2345#$%@3e", $pSalt2="taesa%#@2%^#") { return sha1(md5($pSalt2 . $pPassword . $pSalt1)); } /*********** bool loggedIn verifies that session data is in tack and the user is valid for this session. ************/ function loggedIn() { // check both loggedin and username to verify user. if (isset($_SESSION['loggedin']) && isset($_SESSION['userID']) && isset($_SESSION['username'])) { return true; } return false; } /*********** bool logoutUser Log out a user by unsetting the session variable. ************/ function logoutUser() { // using unset will remove the variable // and thus logging off the user. unset($_SESSION['username']); unset($_SESSION['userID']); unset($_SESSION['loggedin']); return true; } /*********** bool validateUser Attempt to verify that a username / password combination are valid. If they are it will set cookies and session data then return true. If they are not valid it simply returns false. ************/ function validateUser($pUsername, $pPassword) { // See if the username and password are valid. $sql = "SELECT * FROM users WHERE username = '" . mysql_real_escape_string($pUsername) . "' AND password = '" . hashPassword($pPassword, SALT1, SALT2) . "' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); // If one row was returned, the user was logged in! if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $_SESSION['username'] = $row['username']; $_SESSION['userID'] = $row['userID']; $_SESSION['password'] = $row['password']; $_SESSION['loggedin'] = true; return true; } return false; } ?> USERS TABLE ID username password firstname surname 1 rich 12345 Richard Branson 2 alan 67898 Lord Sugar
  5. great many thanks, forever in your debt
  6. I apologise, I probably should of been more specific in the first place. I understand it's a big ask, but I don't suppose rewriting the query, is something you'll be able to help me with?? This is ultimately the last piece in the jigsaw of my project. I would forever be in your debt!!
  7. thanks for looking at it again, it's practically there now however this_rank seems to be tied to the end score column?? rather than the overall column, I don't know if the prev_rank column is as well, but you'll see that the highest scores in the end score column of 3 points are given the position of 1st in the this_rank column, rather than the 11 points of the overall column. i can see in the two subqueries there are the lines: @prevscorea := score as score ORDER BY score DESC @prevscoreb := score as score ORDER BY score DESC i've tried changing these to overall but it doesn't get recognised??
  8. not ideal, but i've attached my sql tables in a screenshot including the output with the proposed solution. as far as I can see i'm not missing any users or any weeks, so I dont understand the reasons for the return of NULL maybe you will see something im missing
  9. I apologise for another reply, I cannot seem to find an edit function on my previous reply. Ok, i have it working a little better now. Changes to my table structure arn't required. It was a case, that there wasn't scores of all users in my table which i've since updated and it's fixed the shortcomings i had before. However as a test i've added in a 2nd and 3rd week of points to try out the current rank/prev rank. The good news, is the prev rank column does get populated however in both rank columns, but some NULL values are returned?? So they are blank, additionally the returned table also seems to be ordered by the weekly total and not the overall?? Thanks
  10. thanks, do i have to edit my points table i.e. add any extra colums for the above to work? or change my php code, below?? <?php $rank=0; $temp_score=0; ?> <?php if(mysql_num_rows($result) > 0): ?> <table> <tr> <th style="text-align:left;">CHANGE</th> <th style="text-align:left;">CURRENT RANK</th> <th style="text-align:left;">PREV RANK</th> <th style="text-align:left;">NAME</th> <th style="text-align:left;">PTS</th> <th style="text-align:left;">TW</th> <tr> <?php while($row = mysql_fetch_assoc($result)): if($temp_score!=$row['overall']) $rank++; ?> <tr> <td><!-- CHANGE ICON OR TEXT --></td> <td><?php echo "#".$rank; ?></td> <td><!-- PREVIOUS RANK --></td> <td><?php echo $row['firstname']; ?> <?php echo $row['surname']; ?></td> <td style="font-weight: bold; color: #008AFF;"><?php echo $row['overall']; ?></td> <td><?php echo $row['total']; ?></td> </tr> <?php $temp_score=$row['total']; endwhile; ?> </table> <?php endif; mysql_close(); ?>
  11. Hi, I am trying to visually show the difference in "ranking" (rank) when I update the "score" value in my database. I wish to output the current rank in one column then in the next column show the prev rank followed by maybe an icon (up/down arrows) or text (UP, DOWN, SAME) in another column as a visual key for changes in rank. The score changes on a weekly basis, this is determined by a week no in my points database table: POINTS id | userID | week | score 1 | 1 | 1 | 4 2 | 2 | 1 | 1 3 | 3 | 1 | 3 4 | 1 | 2 | 0 5 | 2 | 2 | 4 6 | 3 | 2 | 1 Getting this ranking function to work is the final piece in the coding jigsaw on the project i'm working on. Here is my current code (which works) but it works with only current ranking: <?php $result = mysql_query("SELECT firstname , surname , week AS gameweek , SUM(score) AS total , tot.overall FROM points INNER JOIN users ON users.userID = points.userID INNER JOIN ( SELECT userID , SUM(score) as overall FROM points GROUP BY userID ) as tot ON points.userID = tot.userID WHERE week = (SELECT MAX(week) FROM points) GROUP BY points.userID ORDER BY overall DESC") or die(mysql_error()); ?> <?php $rank=0; $temp_score=0; ?> <?php if(mysql_num_rows($result) > 0): ?> <table> <tr> <th style="text-align:left;">CHANGE</th> <th style="text-align:left;">CURRENT RANK</th> <th style="text-align:left;">PREV RANK</th> <th style="text-align:left;">NAME</th> <th style="text-align:left;">PTS</th> <th style="text-align:left;">TW</th> <tr> <?php while($row = mysql_fetch_assoc($result)): if($temp_score!=$row['overall']) $rank++; ?> <tr> <td><!-- CHANGE ICON OR TEXT --></td> <td><?php echo "#".$rank; ?></td> <td><!-- PREVIOUS RANK --></td> <td><?php echo $row['firstname']; ?> <?php echo $row['surname']; ?></td> <td style="font-weight: bold; color: #008AFF;"><?php echo $row['overall']; ?></td> <td><?php echo $row['total']; ?></td> </tr> <?php $temp_score=$row['total']; endwhile; ?> </table> <?php endif; mysql_close(); ?>
  12. Thanks for the proposed solutions above, I haven't had chance to test them yet as i'm at work. But on first look I don't think this solution will give me an overall total (cumulative total of all weeks score) as well as weekly total (single score value taken from max week no) I think it's my own fault for not explaining it properly, but what I had in mind for the final output table was: firstname surname | weekly total | overall total
  13. Hi, i have my query 95% working, it returns a list of users ordered by total score SELECT firstname, surname, SUM(score) AS total, score AS gameweek FROM users INNER JOIN points ON users.userID = points.userID GROUP BY users.userID ORDER BY total DESC however I wish to display a current weekly score (gameweek), separately from the overall score I thought I could get it to work by querying the MAX week and displaying the score but so far i'm having no luck. my tables are as follows: USERS userID | username | password | firstname | surname POINTS id | userID | week | score 1 | 1 | 1 | 4 2 | 2 | 1 | 1 3 | 3 | 1 | 3 4 | 1 | 2 | 0 5 | 2 | 2 | 4 6 | 3 | 2 | 1
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.