Jump to content

[SOLVED] Prepopulating a form from the results of an SQL query.


paulsinclair

Recommended Posts

I am only new to PHP and MYSQL but have used SQL before. 

 

I am trying to build a process that will default a form to the current contents of a row, and then allow the user to modify the data and resave it.  Everything is going fine, except that the Description is only populating the first word of the description to the form.

 

I am guessing it is something simple, but I can't figure it out.

 

Thanks for any help you can give me.

 

<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?
  	if($_REQUEST['action']=="edit")
{

    	$result=mysql_query("SELECT `MaterialsID`,`CODE`,`Description`,`buyprice`,`buildprice`,`buyunit`,`buildunit`, supplierid FROM `materials` WHERE materialsid={$_REQUEST['materialsid']};");
        $i=0;
        while( $row=mysql_fetch_array($result) )
            {

            echo "<form action=list_materials.php method=get>";
            echo "<table border=0 cellpadding=0 cellspacing=0 align=center>";
            echo "<tr><td></td><td></td></tr>";
            echo "<tr><td></td><td><input type=hidden size=20 name=MaterialsID value=".$row['MaterialsID']." ></td></tr>";
            echo "<tr><td><b>CODE:</b></td><td><input type=text size=20 name=CODE value=".$row['CODE']." ></td></tr>";
            //The next line is only putting the first word of the description in the input field.
            echo "<tr><td><b>Description: </b></td><td> <input type=text size=50 name=description value=".$row['Description']."  ></td></tr>";
            echo "<tr><td><b>Buy Price:</b></td><td> <input align=right type=text size=20 name=buyprice  value=".$row['buyprice']." ></td></tr>";
            echo "<tr><td><b>Buy Unit:</b></td><td> <input type=text size=20 name=buyunit  value=".$row['buyunit']." ></td></tr>";
            echo "<tr><td><b>Build Price:</b></td><td> <input type=text size=20 name=buildprice  value=".$row['buildprice']." ></td></tr>";
            echo "<tr><td><b>Build Unit:</b></td><td> <input type=text size=20 name=buildunit  value=".$row['buildunit']." ></td></tr>";
            echo "<tr><td><b>Supplier #:</b></td><td> <input type=text size=20 name=supplierid  value=".$row['supplierid']." ></td><td></td></tr>";
            echo "<tr><td></td><td><input type=submit border=0 value=\"Submit\"></td></tr>";
            echo "</table>";
            echo "</form>";

            }
    }


?>
</BODY>
</HTML>

Right now it will look like:

value=blah blah blah

You need quotes.

value="blah blah blah"

 

So...

 

 

echo "<tr><td><b>Description: </b></td><td> <input type=text size=50 name=description value=\"".$row['Description']."\"  ></td></tr>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.