Results 1 to 1 of 1

Thread: php is returning nothing when validating single quote ( ' ) using preg_match

  1. #1
    Join Date
    Nov 2009
    Thanked 2 Times in 2 Posts

    Default php is returning nothing when validating single quote ( ' ) using preg_match


    I am trying to validate a variable using a regex and preg_match. I want it to do a query if the preg_match passes. Trying to allow letters, spaces, hyphens, and apostrophes (single quotes). Not sure what my problem is as I am a bit of a noob with regex. My code is as follows any help is appreciated or advice if there is a better way to accomplish this. Thanks:

    PHP Code:
     $lastname $_GET['last'];
    preg_match("/^[A-Za-z\\- \']+$/"$lastname)){
    $query "SELECT * FROM main WHERE last LIKE '$lastname%' ORDER BY last, first, middle ASC";

     if (
    $result $mysqli->query($query)):
    $row_cnt mysqli_num_rows($result);
    $row_cnt 0){
    '<table border="1">';
    '<tr><th>Last Name</th><th>First Name</th><th>Middle Name</th><th>Date of Birth</th><th>Street</th><th>City</th></tr>';
        while (
    $obj $result->fetch_object()) {
    printf ('<tr><td>'."%s".'</td>'$obj->last);
    printf ('<td>'."%s".'</td>'$obj->first);
    printf ('<td>'."%s".'</td>'$obj->middle);
    printf ('<td>'."%s".'</td>'$obj->dob);
    printf ('<td>'."%s".'</td>'$obj->street);
    printf ('<td>'."%s".'</td></tr>'$obj->city);
    Last edited by itivae; 11-29-2013 at 07:39 PM.

Similar Threads

  1. mySQL Single Quote Issue
    By jdadwilson in forum MySQL and other databases
    Replies: 1
    Last Post: 07-24-2013, 01:11 AM
  2. Help with a preg_match
    By nicmo in forum PHP
    Replies: 33
    Last Post: 11-29-2010, 10:47 PM
  3. Preg_match help
    By jmace in forum PHP
    Replies: 2
    Last Post: 10-27-2010, 06:41 PM
  4. Replies: 5
    Last Post: 12-30-2008, 08:52 AM
  5. preg_match
    By Dennis_Gull in forum PHP
    Replies: 9
    Last Post: 07-30-2007, 03:21 PM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts