php - Workaround for ENCAPSED_AND_WHITESPACE -


i new php programming. have tried googling , searching website fix don't know type google find answer.

i error:

unexpected t_encapsed_and_whitespace, expecting t_string or t_variable or t_num_string 

i unsure can avoid this.i know caused ['userid'] need part of coding.

here code:

<?php include ('auth/userinfo.php');  $servername = "example"; $username = "example_1"; $password = "example"; $dbname = "example_enter";  // create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); }  $userprofile['userid'] = mysqli_real_escape_string($userprofile['userid']);   $sql="insert today (accessed) values ('$userprofile['userid']')";  if ($conn->query($sql) === true) { echo "success"; } else { echo "error: " . $sql . "<br>" . $conn->error; }  $conn->close();  ?> 

in case coding bad no 1 knows attempting do. attempting write mysql db when user has signed in.

the problem caused fact (a) using quotes reference array index inside literal string (b) inserting line break inside same string:

$sql="insert today (accessed) values ('$userprofile['userid']')"; 

what meant write is:

$sql="insert today (accessed) values ('" . $userprofile['userid'] . "')"; 

however problematic due sql injection attacks - recommend read on parameterized queries (mysqli_prepare).


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -