Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: PHP Error

  1. #1
    New Coder
    Join Date
    Aug 2012
    Location
    New Zealand
    Posts
    52
    Thanks
    2
    Thanked 4 Times in 4 Posts

    PHP Error

    Im trying to code a events manager off but im coming across this error and unsure how to fix it... Im also new to this whole mysqli thing so if you spot anything out of place feel free to tell me x]

    The error im getting is this

    syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/cookie/public_html/private/clients/planit/includes/post.php on line 61
    Heres my code line for line 61

    mysqli_real_escape_string($_POST['name']),
    PHP Code:
    <?php      

            $user 
    'user';            
        
    $db_user 'database';             
        
    $db_password 'password';     
        
    $db_host 'localhost';   
                 
    function 
    get_ip() {
            if (
    $_SERVER['HTTP_X_FORWARD_FOR']) {
                return 
    $_SERVER['HTTP_X_FORWARD_FOR'];
            } else {
                return 
    $_SERVER['REMOTE_ADDR'];
            }
        }
        
        function 
    default_val(&$var$default) {
            if (
    $var=='') {
                
    $var $default;
            }
        }
        
        function 
    check_mail($email) {
            if(
    preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/"$email)) {
                list(
    $username,$domain)=split('@',$email);
                if(!
    checkdnsrr($domain,'MX')) {
                    return 
    false;
                } else {
                    return 
    true;
                }
            } else {
                return 
    false;
            }
        }
        
    if (
    $_POST['submit']) {
        
            
    $conn new_mysqli($db_hostdb_user$db_password$db_database) or die ('Error connecting to mysql');
            
                       if (
    mysqli_connect_errno()) {
       die(
    "<font color='red'>Eeeek! Cannot connect user $user, " .
               
    " password $password </font>");
    }
                    
            
                if (
    check_mail($_POST['email'])) {
                    if (
    $_POST['name']) {
                        if (
    strstr($_POST['name']," ")) {
                            
    $passed true;
                        } else {
                            
    $message "Please enter your name.";
                        }
                    } else {    
                        
    $message "Please enter your name.";
                    }
                } else {
                    
    $message "Please enter a valid email address.";
                }
    }
    $query "INSERT INTO rsvp (ip, name, email, attend, phone, cell)
    VALUES
    mysqli_real_escape_string(get_ip()),
    mysqli_real_escape_string($_POST['name']),
    mysqli_real_escape_string($_POST['email']),
    mysqli_real_escape_string($_POST['attend']),
    mysqli_real_escape_string($_POST['phone']),
    mysqli_real_escape_string($_POST['cell'])"
    ;
                                           
    mysql_query($query);

                        
    mysql_close($conn);
    ?>
    Any help is very much appreciated (:
    Last edited by Jordann; 02-07-2013 at 10:43 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    The error is due to the use of associative PHP array variable inside the string. You should also put PHP functions out of the string.
    PHP Code:
    $query "INSERT INTO rsvp (ip, name, email, attend, phone, cell)
    VALUES
    "
    .mysqli_real_escape_string(get_ip()).",
    "
    .mysqli_real_escape_string($_POST['name']).",
    "
    .mysqli_real_escape_string($_POST['email']).",
    "
    .mysqli_real_escape_string($_POST['attend']).",
    "
    .mysqli_real_escape_string($_POST['phone']).",
    "
    .mysqli_real_escape_string($_POST['cell']); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Jordann (02-07-2013)

  • #3
    New Coder
    Join Date
    Aug 2012
    Location
    New Zealand
    Posts
    52
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Thanks very much for that that certainly got rid of the error!


  •  

    Posting Permissions

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