如何从数据库信息中创建变量

I want to make a PHP variable equal to an entry in a database. The connection to the database is fine because it is doing other things, but the variable isn't showing up.

Here is my variable declaration:

$companyNameRet = mysqli_query($con,"SELECT company_name FROM x6_quote_data WHERE quote_number = '".$getQuote."'") ;

The variable is to be used in the "Placeholder" attribute of an input field, effectively to pre-populate a form with data from a database.

Thanks in advance.

The following should work:

$row=$companyNameRet->fetch_assoc();
$myvariable=$row['company_name'];

good luck!

For multiple variables, $row will be populated $row['column_name'] for as many column names as you have. It can get quite confusing if you are decrypting or doing anything fancy with functions so it may be worth assigning aliases:

SELECT column1 firstcol,column2 secondcol,column3 thirdcol...

In this case, $row would have the aliases as keys: $row['firstcol'], $row['secondcol'] etc... Try var_dump($row) to see what you get. It is most educational to do so.

You can fetch multiple rows by using:

while($row=$companyNameRet->fetch_assoc())
    {
    // $row will contain consecutive rows selected from your db.
    }

W3 Schools provide a decent tutorial on mysqli basics. You would do well to read it.

You cannot get your value right out off the query using raw mysqli API. To do that you have to use some higher level abstraction wrapper, like safeMysql:

$sql = "SELECT company_name FROM x6_quote_data WHERE quote_number = ?s";
$companyNameRet = $db->getOne($sql, $getQuote);

Also note that you should use prepared statements.

your $getQuote is place in the name= "getQuote" not in the placeholder.