Jump to content

Get from form


smiles

Recommended Posts

In SQL we have this syntax, for i.e ...

SELECT Information FROM Person WHERE Name = 'Peter'

Is there anyway to change 'Peter' to an variable which I get from a formlike this

$result = %_POST['Some_Name_Here'];$result1 = mysql_query("SELECT Information FROM Person WHERE Name = $result ") ;//// these above code not work

thanks !

Link to comment
Share on other sites

If its giving any error, post it ORCheck if query is returning some value.... If you are using the below query, it must not contain unnecessary blank spaces, I put that in the previous post to show single and double quotes.....$sqlstr = "SELECT Information FROM Person WHERE Name='" . $result . "'";

Link to comment
Share on other sites

here is the code, I get no error and no display

<?php include("1stfile.php"); $result1 = $_POST["theName"];$sqlstr = "SELECT Information FROM Person WHERE Name='" . $result1 . "'";$result2 = mysql_query($sqlstr) or die(mysql_error());while ($row = mysql_fetch_array($result2))  {  echo $row["Information"];  }?>

Link to comment
Share on other sites

thanks pulpfiction, but I sure that it hasn't been solved yet :) What I am trying to do is having a drop down form, its items are get from database, when you choose one item and click submit button, the information of that item will appear below it .Anyone has another way better than what I did ?

Link to comment
Share on other sites

If this is really exactly what your query says:

"SELECT Information FROM Person WHERE Name=' Hello '

Then obviously there are spaces around "Hello". Those spaces are probably the problem. You need to trim the spaces off the value, either when you write it out in the <option> tag or when you get it from post here:

$result1 = trim($_POST["theName"]);

You'll also want to escape the value in the query to avoid a SQL attack.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...