Jump to content
Larry Ullman's Book Forums

Recommended Posts

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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...