CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Resolved PHP Error (http://www.codingforums.com/showthread.php?t=287231)

Jordann 02-07-2013 05:17 AM

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

Quote:

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

Quote:

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 (:

abduraooft 02-07-2013 07:03 AM

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']); 


Jordann 02-07-2013 09:43 AM

Thanks very much for that that certainly got rid of the error!


All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.