Richard Korts
asked on
php error I cannot find
I have this line of php code
The attached file says there are syntax errors. From php code checker.
What is wrong?
php_checker.JPG
$qryn = "INSERT into projects (ruid, pid, project_name, date) VALUES ($_SESSION['ruid'] . ", " . $npid . ", '" . $pname . "', '" . date('Y-m-d') . ")'";
The attached file says there are syntax errors. From php code checker.
What is wrong?
php_checker.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Looks like hielo beat me to it. And he's correct - prepared statements are a little more code-y but they're much safer.
ASKER
gr8gonzo,
What is the difference between what you say & what is already there?
VALUES (" . $_SESSION['ruid'] .
What is the difference between what you say & what is already there?
VALUES (" . $_SESSION['ruid'] .
If by "what is already there" you're referring to hielo's suggestion - we suggested the same thing a few seconds apart - I was just typing up my response while he was finishing his.
If you're referring to what you already had in your original question, the issue was simply that you had not closed out of your quoted string. This is what you had:
So in that code, PHP thinks that your quoted string goes all the way to the second " that it finds, so it thinks the quoted string is:
And then after that ", you had a comma, which isn't valid PHP syntax at that location, so that's why you were getting the error. By putting the extra quote and period before your $_SESSION, you finished the quoted string at its proper place, so the initial quoted string became:
...and then the rest of the code worked fine.
If you're referring to what you already had in your original question, the issue was simply that you had not closed out of your quoted string. This is what you had:
$qryn = "INSERT into projects (ruid, pid, project_name, date) VALUES ($_SESSION['ruid'] . ", " . $npid . ",...etc...
So in that code, PHP thinks that your quoted string goes all the way to the second " that it finds, so it thinks the quoted string is:
"INSERT into projects (ruid, pid, project_name, date) VALUES ($_SESSION['ruid'] . "
And then after that ", you had a comma, which isn't valid PHP syntax at that location, so that's why you were getting the error. By putting the extra quote and period before your $_SESSION, you finished the quoted string at its proper place, so the initial quoted string became:
"INSERT into projects (ruid, pid, project_name, date) VALUES ("
...and then the rest of the code worked fine.
($_SESSION['ruid']
to:
(" . $_SESSION['ruid']