Jump to content

PaulRyan

Members
  • Posts

    876
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by PaulRyan

  1. Alternatively, you could add a new column to your database, something like "show_today" and set it as "tinyint" and a length of "1", then default the value to "0". Then create a cron job, to run each day, to firstly select however many videos you'd like displayed that were not shown yesterday I.E. have "show_today" set to 0. Then when you have chosen the 3 videos, reset all rows to have "show_today" set to 0, and then update the table and set the chosen videos to "show_today" to 1. Then when displaying the page, you just need to select the videos where "show_today" is set to 1.
  2. *Edit - Back track, need to check something. *Edit edit - Try the following: <?PHP header('Content-Type: application/json; charset=utf-8'); $contents = file_get_contents('http://cdn.content.easports.com/fifa/fltOnlineAssets/C74DDF38-0B11-49b0-B199-2E2A11D1CC13/2014/fut/items/web/198611.json'); echo $contents; ?>
  3. I wouldn't say so, I've used that method for most for the time I've been using PHP. I stay clear of storing massive amounts of data in the session, and its fared me well up to now.
  4. Put the message into a session variable, then redirect. When the redirect is complete, check to see if the message variable exists. If it does, show the message, then unset it.
  5. @mcwee93 - Just because the code works, doesn't mean to say you should use it. CyberRobot made a good point about santizing your data. I myself, had a little time so I had a go at re-creating what you require the way I would do it. <?PHP if($_SERVER['REQUEST_METHOD'] == 'POST') { //### Connection variables $DBUser = 'root'; $DBPass = ''; $DBHost = '127.0.0.1'; $DBName = 'test'; //### Connect to database $mysqli = mysqli_connect($DBHost, $DBUser, $DBPass, $DBName) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); //### Sanitize varaibles $_POST['title'] = isset($_POST['title']) ? strtolower(trim($_POST['title'])) : FALSE ; $_POST['name'] = isset($_POST['name']) ? strtolower(trim($_POST['name'])) : FALSE ; $_POST['surname'] = isset($_POST['surname']) ? strtolower(trim($_POST['surname'])) : FALSE ; $_POST['phone'] = isset($_POST['phone']) ? strtolower(trim($_POST['phone'])) : FALSE ; $_POST['email'] = isset($_POST['email']) ? strtolower(trim($_POST['email'])) : FALSE ; //### Check over the incoming data //### Check title if(empty($_POST['title'])) { $errors[] = 'You must enter your salutation.'; } //### Check name if(empty($_POST['name'])) { $errors[] = 'You must enter your name.'; } //### Check surname if(empty($_POST['surname'])) { $errors[] = 'You must enter your surname.'; } //### Check phone if(empty($_POST['phone'])) { $errors[] = 'You must enter your phone number.'; } //### Check email if(empty($_POST['email'])) { $errors[] = 'You must enter your e-mail address.'; } else if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $errors[] = 'You have entered an invalid e-mail address.'; } else { //### Escape email $_POST['email'] = mysqli_real_escape_string($mysqli, $_POST['email']); //### Check to see if e-mail address if already in use $checkEmailQuery = "SELECT `email` FROM `competition` WHERE `email` = '{$_POST['email']}'"; $checkEmail = mysqli_query($mysqli, $checkEmailQuery); //### Check for mysqli error if(mysqli_error($mysqli)) { $processError = 'An error occured processing your request, please try again.'; } else if(mysqli_num_rows($checkEmail)) { $errors[] = 'The e-mail address you have entered it already in use.'; } } //### Check to see if there are any process errors if(isset($processError)) { echo $processError.'<br>'; //### Check to see if there are any data errors } else if(isset($errors)) { echo 'One or more errors occured processing your data: <br>'; foreach($errors AS $error) { echo $error.'<br>'; } //### No errors, proceed with processing request } else { //### Escape varaibles $_POST['title'] = mysqli_real_escape_string($mysqli, $_POST['title']); $_POST['name'] = mysqli_real_escape_string($mysqli, $_POST['name']); $_POST['surname'] = mysqli_real_escape_string($mysqli, $_POST['surname']); $_POST['phone'] = mysqli_real_escape_string($mysqli, $_POST['phone']); //### Insert record in to database table $insertRecordQuery = "INSERT INTO `competition` (`title`, `name`, `surname`, `phone`, `email`) VALUES ('{$_POST['title']}', '{$_POST['name']}', '{$_POST['surname']}', '{$_POST['phone']}', '{$_POST['email']}')"; $insertRecord = mysqli_query($mysqli, $insertRecordQuery); //### Check for mysqli error if(mysqli_error($mysqli)) { echo 'An error occured saving your data, please try again. <br>'; } else { //### Redirect, to prevent form submission from refreshing header('Location: ?success=true'); exit; } } } ?> <form method="POST" action="?"> <?PHP if(isset($_GET['success'])) { echo 'Thanks you! Your details have been successfully added to the system. <br>'; } ?> Title: <input type="text" name="title"> <br> Name: <input type="text" name="name"> <br> Surname: <input type="text" name="surname"> <br> Contact Number: <input type="text" name="phone"> <br> E-mail Address: <input type="text" name="email"> <br> <input type="submit" value="Submit"> </form>
  6. You are making more work for yourself, if you have to repeat data, it's probably not correctly written. Something like this: <?PHP $candy = array('chocolate' => array('Mars', 'M&Ms', 'Reese\'s'), 'gummy' => array('Worms', 'Bears')); foreach($candy AS $type => $typeArray) { if($type == 'chocolate') { foreach($typeArray AS $specific) { echo $specific.' <br>'; } } else { foreach($typeArray AS $specific) { echo $specific.' '.$type.' <br>'; } } } ?>
  7. Why don't you just use preg_replace? Example: <?PHP $number = '<script>07123456789</script>'; $number = preg_replace('/[^0-9]/', '', $number); echo $number; ?>
  8. Try this: <?PHP //### Check if form has been posted if($_SERVER['REQUEST_METHOD'] == 'POST') { //### Assign incoming numbers $number1 = isset($_POST['number_1']) ? $_POST['number_1'] : NULL ; $number2 = isset($_POST['number_2']) ? $_POST['number_2'] : NULL ; //### Check to see if either field is empty if($number1 == NULL) { $message = 'Number 1 field is empty.'; } else if($number2 == NULL) { $message = 'Number 2 field is empty.'; } else { //### Check if numbers match if($number1 == $number2) { $message = 'Yes, those numbers match.'; } else { $message = 'No, those do not numbers match.'; } } } ?> <form method="POST"> <?PHP if(isset($message)) { echo '<p>'. $message .'</p>'; } ?> <p> Number 1 Info <br> <input type="text" name="number_1" value="<?PHP if(isset($number1)) { echo htmlentities($number1, ENT_QUOTES); } ?>"> </p> <p> Number 2 Info <br> <input type="text" name="number_2" value="<?PHP if(isset($number2)) { echo htmlentities($number2, ENT_QUOTES); } ?>"> </p> <p> <input type="submit" value="Check if they match?"> </form>
  9. In my experience (which is limited I might add), I've seen that affiliates send data via POST to a specific file on your server, you set the link up with them on their system usually. The file they POST to will include all the data you need to process whether or not the user completed the offer successfully. It's up to you to develop the code to process that data. If you start writing some code, then we can help out, but we won't just write code for you, as you won't learn anything. If you don't want to write the code yourself, then you should head over to the Freelance Section of the site.
  10. Try something like this, it provides some errors if data is missing or the query does not execute etc. <?PHP require('edb.php'); //### Assign and santize data $id = isset($_GET['id']) ? (int)$_GET['id'] : FALSE ; $activateCode = isset($_GET['ActivateCode']) ? mysql_real_escape_string(trim($_GET['ActivateCode'])) : FALSE ; //### Check to make sure both are set if(empty($id)) { echo 'ID is empty.'; } else if(empty($activateCode)) { echo 'Activate Code is empty.'; } else { //### Find the user $findUserQuery = "SELECT * FROM `eusers` WHERE `id` = {$id} AND `ActivateCode` = '{$ActivateCode}'"; $findUser = mysql_query($findUserQuery) or die(mysql_error()); //### Check if a row exists if(!mysql_num_rows($findUser)) { echo 'Error: Data Not Found.'; } else { //### Process the data $user = mysql_fetch_assoc($findUser); //### Display data for usage echo '<pre>'; print_r($user); echo '</pre>'; //### Now do whatever else needs done } } ?> I'd advise you move away from MySQL and move to MySQLi or PDO as soon as possible. MySQL will be removed from one of the upcoming versions of PHP.
  11. The code I gave you is not meant to be put into production, it is an EXAMPLE. Modify it to suit your needs? From your other post I saw "order_confirmation.php" You could use <?PHP $orderID = 12345; header('Location: order_confirmation.php?order_id='.$orderID.''); exit; ?> *Edit - I have a feeling I'm missing something...or just not getting what you've said?
  12. You could use a header? Example: <?PHP $name = 'Peter'; $city = 'Canada'; header('Location: file.php?name='.$name.'&city='.$city.'); exit; ?> That would re-direct you to "file.php?name=Peter&city=Canada". You would need to use the above code BEFORE any output.
  13. Could it be the spaces around the ID number in the WHERE part of the query?
  14. If you have 2 different sets of check boxes in a form, you will need to change the name of the check boxes. The set I did was named "custexp[]" for next check boxes, it will need a different name I would imagine.
  15. Seriously though? Trolling or something? You have $$Email_from, should be $Email_from.
  16. You need to post the form code too. That alone is not enough for anyone to even consider helping. If this is related to what I posted in your other thread, instead of creating a new variable for each option, how about using the actual posted array that is created from the form? I even used print_r on the post to show you the out put, just save that array to the session then use it when needed.
  17. Try this: <?PHP if($_SERVER['REQUEST_METHOD'] == 'POST') { echo '<pre>'; print_r($_POST); echo '</pre>'; } //### Put options in array $outsourceArray = array('1' => 'Marketing Agency', '2' => 'PR Agency', '3' => 'Design Studio', '4' => 'Marketing Consultant', '5' => 'Media Agency', '6' => 'Adevertising Agency', '7' => 'Service or Product Design Agency', '8' => 'Customer Experience Agency'); //### Create output $optionOutput = ''; foreach($outsourceArray AS $key => $value) { //### Checks to see if 'outsource' is posted AND whether its an array AND it the value exists i n the posted array $checked = (isset($_POST['outsource']) && is_array($_POST['outsource']) && in_array($key, $_POST['outsource'])) ? 'checked' : '' ; $optionOutput .= '<input type="checkbox" class="checkbox" name="outsource[]" value="'. $key .'" '. $checked .'>'. $value .'<br />'; } ?> <form method="POST"> <?PHP echo $optionOutput;?> <input type="submit"> </form>
  18. <option value="ACT"<?php echo ($State == 'ACT') ? 'selected' : '';?>>ACT</option> Couldn't edit previous post.
  19. <option value="ACT"<?php ($State == 'ACT') ? 'selected' : '';?>>ACT</option> You don't need the double quotes around the value selected.
  20. For that to happen $instance is greater than 0 AND $str does not equal 'LOAD_APP' or 'APP_LOADED'. Looks like you need to add some more debugging inside the function to return an error or something if that occurs.
  21. I did exactly what your previous code looked like it was attempting to do. It seems as though you're trying to change a client side action with a server side output. You need to look into a javascript version of the above code. <script type="text/javascript"> function performAction(){ var button = document.getElementById('actionButton'); var myPlayer = document.getElementById('playerid'); if(button.value.toLowerCase() == 'pause') { button.value = 'Play'; myPlayer.pauseVideo(); } else { button.value = 'Pause'; myPlayer.playVideo(); } } </script> <input type="button" id="actionButton" onClick="performAction();" value="Pause">
  22. <?PHP session_start(); $pause = 1; $btnname = "Pause"; $btntype = "pause"; if($_SERVER['REQUEST_METHOD'] == 'POST') { //### Debug Data //echo '<pre>'; //print_r($_POST); //echo '</pre>'; $postedButton = isset($_POST['button']) ? strtolower($_POST['button']) : '' ; if($postedButton == 'pause') { $play = 1; $btnname = "Play"; $btntype = "play"; } else if($postedButton == 'play') { $pause = 1; $btnname = "Pause"; $btntype = "pause"; } } ?> <form method="POST"> <a href="#" onclick="var myPlayer = document.getElementById('playerid'); myPlayer.<?php echo $btntype; ?>Video();"> <input name="button" type="submit" id="button" value="<?php echo $btnname; ?>" /> </a> </form>
  23. When ever you are using sessions, you need to start it before ANYTHING else just after the opening PHP tags, example: <?PHP session_start(); //### Other code here You apply that to every page that requires sessions to be used. You don't close a session, you destroy it, using the following (personal preference) $_SESSION = array(); session_destroy();
  24. You should not rely on the forms submit button to be sent along with the form, you should use something like this <?PHP //### Check form was submitted if($_SERVER['REQUEST_METHOD'] == 'POST') { //### Check to see if the POST value 'name' was sent $name = isset($_POST['name']) ? trim($_POST['name']) : FALSE ; //### IF the name is empty, display error if(empty($name)) { $nameerror = "<span class=\"feedback\">Please enter valid name</span>"; unset($_SESSION['name']); //### ELSE session name is set and re-direct } else { $_SESSION['name'] = $name; header('Location: page_2.php'); exit; } }
  25. In this query, you have written a column name incorrectly. $sql = mysql_query("SELECT * FROM tbl_student WHERE stud_laneme = '".$_POST["lname"]."' AND stud_fname = ".$_POST["fname"]."',"); $result = mysql_query($sql); It should be like this notice stud_laneme from previous code is now stud_lname. //### Ternary operators, quick and easy $firstname = isset($_POST['fname']) ? mysql_real_escape_string(trim($_POST['fname'])) : FALSE ; $lastname = isset($_POST['lname']) ? mysql_real_escape_string(trim($_POST['lname'])) : FALSE ; //### Check variables if(empty($firstname)) { echo 'Firstname is empty.'; exit; } else if(empty($lastname)) { echo 'Lastname is empty.'; exit; } else { //### Perform query $sql = mysql_query("SELECT * FROM `tbl_student` WHERE `stud_fname` = '{$firstname}' AND `stud_lname` = '{$lastname}'"); $result = mysql_query($sql) or die(mysql_error()); } I have added in some simple error checking too, as you can see it is a lot cleaner and easier to read.
×
×
  • 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.