TIF Posted September 23, 2016 Share Posted September 23, 2016 Case #1: Variable created from a POST: $identity = $_POST['soarid']; SELECT statement works just fine: $result = mysql_query("SELECT * FROM faculty WHERE id = $identity") or die("Faculty ID Not Found"); Variable created from a db field: $fac_school = $row["school"]; Variable content verified ok Attempt to use that variable in a SELECT statement: $result = mysql_query("SELECT * FROM position WHERE school = $fac_school") or die("Not found");Does not work! Forcing the variable value thusly: $fac_school = "SOBM"; $result = mysql_query("SELECT * FROM position WHERE school = $fac_school") or die("Not found");Still does not work! But this works: $result = mysql_query("SELECT * FROM position WHERE school = 'SOBM' ") or die("Not found"); Case #2: Similar to above but using INSERT INTO. The insert fails when variable values are used but ok when strings are used for values. All examples int the "PHP and MySQL" book use strings and not variables. What am I missing? Link to comment Share on other sites More sharing options...
kleeh Posted September 29, 2016 Share Posted September 29, 2016 Try enclosing the variable names in curly brackets. Like '{$fac_school}' Link to comment Share on other sites More sharing options...
Recommended Posts