Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JonnoTheDev

  1. Since these are the guys who created the core PHP engine, it is probably the best standard to adopt, especially if you are going to release code. However, as others have said, there is no right or wrong with this subject.
  2. preg_match_all()
  3. Yes there are. They use regular expressions as parameters. Regular expressions are difficult at first, but they are essential when you are working with text strings. http://uk.php.net/manual/en/function.preg-match.php http://uk.php.net/manual/en/function.preg-match-all.php Here is a good starting point. http://www.webcheatsheet.com/php/regular_expressions.php
  4. Welcome. Did you enjoy the World Cup?
  5. See http://www.php.net/manual/en/function.setcookie.php#94030
  6. You are better using array cookies as opposed to using multiple cookies <?php setcookie("data[gcg_user]", $userid); setcookie("data[gcg_name]", $username); setcookie("data[gcg_pass]", $password); ?> To view the data <?php print $_COOKIE['data']['gcg_user']; ?> On another note, what you are doing is highly insecure for a login based system. You are setting a users username / password & id in a text cookie file that is stored on their pc. If there is any kind of trojan or virus on that users pc it may read the information inside the cookie. This would give it access to your site. Also if the user uses the same username / password combo on other sites such as Internet banking then they could be in real trouble. You should never store usernames / passwords in cookie files. You should use sessions to authenticate users. Even then you do not have to save the user data to session variables. After a successful login just set a session variable flag i.e $_SESSION['loggedin'] = true; and test for it on pages that require the user to be logged in. If you do want to use a cookie so the user stays permanently logged in then you should use some kind of hash value that identifies the user to the site.
  7. Simple enough. Once you have written the CSV data to file use either the PEAR:Mail_Mime library or Swiftmailer to attach the file to an email. http://swiftmailer.org/ http://pear.php.net/package/Mail_Mime/
  8. Thank God. I'm going home now! <?php /* insert new row */ $sql = "INSERT INTO fallLeague10 SET nameFirst='".mysql_real_escape_string($nameFirst)."', nameLast='".mysql_real_escape_string($nameLast)."', school='".mysql_real_escape_string($school)."', confirm='y', email='".mysql_real_escape_string($email)."', addressHome='".mysql_real_escape_string($addressHome)."', stateHome='".mysql_real_escape_string($stateHome)."', zipHome='".mysql_real_escape_string($zipHome)."', phoneHome='".mysql_real_escape_string($phoneHome)."', phoneMobile='".mysql_real_escape_string($phoneMobile)."', coachSchool='".mysql_real_escape_string($coachSchool)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } ?>
  9. Run this query directly in mysql server / phpMyAdmin whatever you use to look at the database records. Does it return a row? SELECT id FROM fallLeague10 WHERE nameFirst='Jim' AND nameLast='Reamer' AND school='Carmel'
  10. What does it display on screen with the code I have just given you.
  11. No the code is correct. Simple test. I am adding this in to print the number of rows returned. It will also print the query to the screen. Look in your database to see if it matches up. <?php $sql = "SELECT id FROM fallLeague10 WHERE nameFirst='".mysql_real_escape_string($nameFirst)."' AND nameLast='".mysql_real_escape_string($nameLast)."' AND school='".mysql_real_escape_string($school)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } print "I have found ".mysql_num_rows($result)." matching the following query<br />".$sql; exit(); ?> So the whole thing looks like <?php /* connect to database */ if(!$con = mysql_connect("localhost","jwrbloom_","redcoach")) { die("Could not connect to database: ".mysql_error()); } mysql_select_db("jwrbloom_wpMIB", $con); $nameFirst = $_POST['nameFirst']; $nameLast = $_POST['nameLast']; $email = $_POST['email']; $addressHome = $_POST['addressHome']; $stateHome = $_POST['stateHome']; $zipHome = $_POST['zipHome']; $phoneHome = $_POST['phoneHome']; $phoneMobile = $_POST['phoneMobile']; $school = $_POST['school']; $grade = $_POST['grade']; $coachSchool = $_POST['coachSchool']; $feet = $_POST['feet']; $inshces = $_POST['inches']; /* search for existing row */ $sql = "SELECT id FROM fallLeague10 WHERE nameFirst='".mysql_real_escape_string($nameFirst)."' AND nameLast='".mysql_real_escape_string($nameLast)."' AND school='".mysql_real_escape_string($school)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } print "I have found ".mysql_num_rows($result)." matching the following query<br />".$sql; exit(); if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); /* update existing row */ $sql = "UPDATE fallLeague10 SET confirm='y', email='".mysql_real_escape_string($email)."', addressHome='".mysql_real_escape_string($addressHome)."', stateHome='".mysql_real_escape_string($stateHome)."', zipHome='".mysql_real_escape_string($zipHome)."', phoneHome='".mysql_real_escape_string($phoneHome)."', phoneMobile='".mysql_real_escape_string($phoneMobile)."', coachSchool='".mysql_real_escape_string($coachSchool)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' WHERE id='".$row['id']."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } else { /* insert new row */ $sql = "INSERT INTO fallLeague10 SET nameFirst='".mysql_real_escape_string($nameFirst)."', nameLast='".mysql_real_escape_string($nameLast)."', confirm='y', email='".mysql_real_escape_string($email)."', addressHome='".mysql_real_escape_string($addressHome)."', stateHome='".mysql_real_escape_string($stateHome)."', zipHome='".mysql_real_escape_string($zipHome)."', phoneHome='".mysql_real_escape_string($phoneHome)."', phoneMobile='".mysql_real_escape_string($phoneMobile)."', coachSchool='".mysql_real_escape_string($coachSchool)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } /* redirect user */ header("Location:/fall-league/payment"); exit(); ?>
  12. The code is 100% correct. 'similar' is incorrect. It is looking for an EXACT match of firstname, lastname and school name. If there is no match it will insert a new record.
  13. Sorry, my mistake <?php /* connect to database */ if(!$con = mysql_connect("localhost","jwrbloom_","redcoach")) { die("Could not connect to database: ".mysql_error()); } mysql_select_db("jwrbloom_wpMIB", $con); $nameFirst = $_POST['nameFirst']; $nameLast = $_POST['nameLast']; $email = $_POST['email']; $addressHome = $_POST['addressHome']; $stateHome = $_POST['stateHome']; $zipHome = $_POST['zipHome']; $phoneHome = $_POST['phoneHome']; $phoneMobile = $_POST['phoneMobile']; $school = $_POST['school']; $grade = $_POST['grade']; $coachSchool = $_POST['coachSchool']; $feet = $_POST['feet']; $inshces = $_POST['inches']; /* search for existing row */ $sql = "SELECT id FROM fallLeague10 WHERE nameFirst='".mysql_real_escape_string($nameFirst)."' AND nameLast='".mysql_real_escape_string($nameLast)."' AND school='".mysql_real_escape_string($school)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); /* update existing row */ $sql = "UPDATE fallLeague10 SET confirm='y', email='".mysql_real_escape_string($email)."', addressHome='".mysql_real_escape_string($addressHome)."', stateHome='".mysql_real_escape_string($stateHome)."', zipHome='".mysql_real_escape_string($zipHome)."', phoneHome='".mysql_real_escape_string($phoneHome)."', phoneMobile='".mysql_real_escape_string($phoneMobile)."', coachSchool='".mysql_real_escape_string($coachSchool)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' WHERE id='".$row['id']."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } else { /* insert new row */ $sql = "INSERT INTO fallLeague10 SET nameFirst='".mysql_real_escape_string($nameFirst)."', nameLast='".mysql_real_escape_string($nameLast)."', confirm='y', email='".mysql_real_escape_string($email)."', addressHome='".mysql_real_escape_string($addressHome)."', stateHome='".mysql_real_escape_string($stateHome)."', zipHome='".mysql_real_escape_string($zipHome)."', phoneHome='".mysql_real_escape_string($phoneHome)."', phoneMobile='".mysql_real_escape_string($phoneMobile)."', coachSchool='".mysql_real_escape_string($coachSchool)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } /* redirect user */ header("Location:/fall-league/payment"); exit(); ?>
  14. It is your insert query that is causing the error because you are not escaping the post data. If the post data contains any special characters such as ' they will break the query. I do not normally do this but I have cleaned and rewritten your entire script, commenting each section. I strongly advise you learn the basics of php / mysql through a good book. <?php /* connect to database */ if(!$con = mysql_connect("localhost","jwrbloom_","redcoach")) { die("Could not connect to database: ".mysql_error()); } mysql_select_db("jwrbloom_wpMIB", $con); $nameFirst = $_POST['nameFirst']; $nameLast = $_POST['nameLast']; $email = $_POST['email']; $addressHome = $_POST['addressHome']; $stateHome = $_POST['stateHome']; $zipHome = $_POST['zipHome']; $phoneHome = $_POST['phoneHome']; $phoneMobile = $_POST['phoneMobile']; $school = $_POST['school']; $grade = $_POST['grade']; $coachSchool = $_POST['coachSchool']; $feet = $_POST['feet']; $inshces = $_POST['inches']; /* search for existing row */ $sql = "SELECT id FROM fallLeague10 WHERE nameFirst='".mysql_real_escape_string($nameFirst)."' AND nameLast='".mysql_real_escape_string($nameLast)."' AND school='".mysql_real_escape_string($school)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); /* update existing row */ $sql = "UPDATE fallLeague10 SET confirm='y', email='".mysql_real_escape_string($email)."', addressHome='".mysql_real_escape_string($addressHome)."', stateHome='".mysql_real_escape_string($stateHome)."', zipHome='".mysql_real_escape_string($zipHome)."', phoneHome='".mysql_real_escape_string($phoneHome)."', phoneMobile='".mysql_real_escape_string($phoneMobile)."', coachSchool='".mysql_real_escape_string($coachSchool)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' WHERE id='".$row['id']."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } else { /* insert new row */ $sql = "INSERT INTO fallLeague10 SET nameFirst='".mysql_real_escape_string($nameFirst)."', nameLast='".mysql_real_escape_string($nameLast)."', confirm='y', email='".mysql_real_escape_string($email)."', addressHome='".mysql_real_escape_string($addressHome)."', stateHome='".mysql_real_escape_string($stateHome)."', zipHome='".mysql_real_escape_string($zipHome)."', phoneHome='".mysql_real_escape_string($phoneHome)."', phoneMobile='".mysql_real_escape_string($phoneMobile)."', coachSchool='".mysql_real_escape_string($coachSchool)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' WHERE id='".$row['id']."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } /* redirect user */ header("Location:/fall-league/payment"); exit(); ?>
  15. You should always escape data that comes from URLS or forms before querying or updating database records. It would also help to print your query to the screen so you can see where the error is. Use mysql_real_escape_string() on all data as follows: <?php $result = mysql_query("UPDATE fallLeague10 SET confirm='y', email='".mysql_real_escape_string($email)."', addressHome='".mysql_real_escape_string($addressHome)."', stateHome='".mysql_real_escape_string($stateHome)."', zipHome='".mysql_real_escape_string($zipHome)."', phoneHome='".mysql_real_escape_string($phoneHome)."', phoneMobile='".mysql_real_escape_string($phoneMobile)."', coachSchool='".mysql_real_escape_string($coachSchool)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' WHERE id='".$row['id']."'"); ?>
  16. If you name the form file fields such as image1 through to image 10 then it is easy. You need to put your upload functions within the loop, but I guess if you are uploading 10 images in 1 form there is already a loop in your script. You should be able to understand this code: <?php // loop from 1 to 10 and upload each image for($x = 1; $x <= 10; $x++) { // if file field has been completed if(strlen($_FILES['image'.$x]['name'])) { // code here to upload file // .......... // this needs completing // $upload = true / false // test if file upload was successful if($upload == true) { // add to database $result = mysql_query("INSERT INTO photo_uploads SET date=NOW(), photo_name='".mysql_real_escape_string($_FILES['image'.$x]['name'])."'"); } } } ?>
  17. Can you please post this request in the Mod Rewrite board. http://www.phpfreaks.com/forums/index.php/board,50.0.html
  18. The exact syntax has been posted in my second reply to this thread. When you perform the initial SELECT you do not want to select all fields (*). You only want to select the primary key i.e id. If returned you use it in your UPDATE query. Look again at my second post. The solution is right there.
  19. http://www.phpclasses.org/package/5439-PHP-Crawl-a-site-and-retrieve-the-the-URL-of-all-links.html
  20. You still haven't answered my question: The issue here is that you are not making it clear what you are trying to do. I don't think you know yourself. This makes it incredibly difficult to help you even though what you are trying to do is so simple. Here is something that will help you write your code. Use PSEUDO code first before writing any PHP! This makes it much easier to get the logic in the right order. http://www.minich.com/education/wyo/stylesheets/pseudocode.htm Example: 1. Connect to database 2. Query the database for an existing record by using the POST data 2a. If a record exists update something 2b. If no record exists, insert a new record with POST data 3. Close database connection 4. Redirect user Now write your PHP code over the pseudo code, completing each stage.
  21. Admins, this topic should be moved to mod-rewrite board.
  22. No, no, no. You only need 1 404 ErrorDocument definition. The 403 rule is simply to redirect users to the url you specify if they try to access any pages/directories on your website that are forbidden! Its just force of habbit to put that in. Are you familiar with HTTP header codes? For the 404 rule you will need to create the file you specify after the rule i.e missing.html When a user trys to access a page that no longer exists they will be redirected to missing.html and a 404 header will be thrown. Here is an example of a 404 page: http://www.google.com/jhvjhvjhv.html If you want to start redirecting old urls to new urls, this is done using 301 redirects. You will have to get all the urls ready that you want to redirect to add into a .htaccess file like you stated. # redirect from old urls to new urls redirect 301 /i-am-old-poor/URL1.htm /i-am-old-poor/NEW-URL1.htm redirect 301 /i-am-old-poor/URL2.htm /i-am-old-poor/NEW-URL2.htm # redirect users to this file if they try to access a page that does not exist ErrorDocument 404 /missing.html # redirect users to this url if they try to access a resource that is forbidden ErrorDocument 403 http://www.disney.com
  23. Your first port of call should be the php manual. There are also loads of examples here. http://uk.php.net/filemtime
  24. You do not use php for this. Use a .htaccess file If the URLS no longer exist simply define a 404 error document page ErrorDocument 404 /missing.html ErrorDocument 403 http://www.disney.com
×
×
  • 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.