Why doesn't separating the dollar sign work
Posted 05 May 2013 - 09:03 PM
Posted 05 May 2013 - 09:58 PM
$ in php marks the calling of a var weather it be array or what not if the $ is used improperly it will error out
$query .= "($" . "rel_student_uid, '$detention_date')";
reads the $ as a var call with no var name
$query .= "($rel_student_uid, '$detention_date')";
reads the $rel_student_uid as a var for php to call
any $ inside " " will be treated as a php var to avoid this if you are thing $ as just a character use mysql escape or enclose it in ' '
this making any $ inside a ' ' reas as text unless code escaped with ' ' . $var . ' ' or for doubles " " . $var . " " i personally always code escape my var and use mysql escape
i hope this helps
Posted 06 May 2013 - 01:36 PM
Thanks it helps a bit though still haven't quite grasped. Tried making the original array variable have the $ instead of after the fact and using the mysql escape but still get the variable name $rel_student_uid instead of the actual uid.
INSERT INTO tbl_detentions (rel_student_uid, detention_date) VALUES ('$rel_student_uid', '2013-3-3')
Posted 06 May 2013 - 02:15 PM
Yea, I'm starting to see that treating ' and " the same has finally caught up and bit me. I tended to do it to avoid escape characters so I could have quotes inside quotes without the confusion of \ all over the place. Still haven't figured out the right combination yet. I can break things worse but can't seem to go in the other direction.
Posted 06 May 2013 - 02:20 PM
In some cases, you may want to consider removing the quotes altogether.
$database_info = array("db_table_name" => tbl_detentions, "db_field_names" => array("rel_student_uid", "detention_date"), "form_fields" => array($rel_student_uid, $detention_date));
Blogging about PHP and other web-related topics at ScorpBytes.com
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users