[text]I am trying to find out the correct syntax to use when I want to use a variable as the value in the "Where" portion of the select clause
All the examples of a where clause that I have checked out have not used a variable as the value.
In the code below the "Select "statement in green works.
When I try to use a variable which has the sme content "Some Company' as in the line in red it doesn't work.
I am very new to PHP , only a few weeks.
Some background
I have a form on screen 1 which has a select drop down box which shows the company name in every record of the database. The company field has the primary key so no company record can be duplicated.
Once the user selects a company and presses the submit button this code is activated and the variable "$selco" is created and the company name selkected is put into the variable using the $_POST(company) variable.
The plan is to get all the rest of the information on the company record onto a form so the user can update the information .
I still have a lot of work to do to create the for and put the values on the form but the echo statements are just the m,eans IO am using to see if the date is being extracted.
Thanks
[/text]
Code: Select all
<?php
//This echo is just to c onfirm during development that
//the company name selected in a previous form is carried as variable. It does
echo $_POST[company];
$selco = $_POST[company];
echo $selco;
include ("conninc.php");
//This select statement works extracting the correct record from the database.
[color=#40BF00]$query1 = "SELECT * FROM companies WHERE company = 'Some Company'";[/color]
//This select statement doesn't work . It uses a variable whose value is the same
//as the string in the other select statement
[color=#FF0000]//$query1 = "SELECT * FROM companies WHERE company = '$selco' ";[/color]
$results1 = mysql_query($query1 , $link) or die (mysql_error());
while ($row1 = mysql_fetch_array($results1)) {
extract ($row1);
}
echo $addressln1;
echo $addressln2;
echo $addressln3;
echo $addressln4;
?>