Link to home
Start Free TrialLog in
Avatar of jseaman12
jseaman12

asked on

PHP Variable to prefill text box

I want to be able to take a textbox and prefill it with the variable from mysql query.

I want to use the variable from this section; and prefill a textbox
$ifs = mysql_query("SELECT final_sale
FROM oetable_backup WHERE upper($field)='$find'");

Textbox;
<input type="text" name="sales" value="<?php echo $ifs; ?>">
      Ship Date:

How do I do this??

Thanks,
Jeff
<?php
// Turn off all error reporting
error_reporting(0);
 
include("include/phpgrid.php");
 
 
 
 
$hostName = "localhost";
$userName = "jmichels";
$password = "hug344";
$dbName	  = "thstew_orders";
?>
<html>
<head>
<title>Invoice</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<?php
 
$idresult = mysql_query("SELECT id
FROM oetable_backup WHERE upper($field)='$find'");
 
$ifs = mysql_query("SELECT final_sale
FROM oetable_backup WHERE upper($field)='$find'");
 
 
 
 
 
$dg = new C_DataGrid($hostName, $userName, $password, $dbName);
 
// We preform a bit of filtering
$find = mysql_real_escape_string($_POST['find']);
$field = mysql_real_escape_string($_POST['field']);
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
 
 
$dg -> set_gridpath     ("include/");
$dg -> set_sql          ("SELECT
entry_date,territory,principle,customer,po,part_no,qty,initial_sale,due_to_ship,ship_date,qty_shipped,comm,invoice,comm_due,type_ind,id
FROM oetable_backup WHERE upper($field)='$find'");
 
 
 
$dg -> set_sql_table    ("oetable_backup");
 
// change column titles
//$dg -> set_col_title    ("EmployeeId", "Employee ID");
//$dg -> set_col_title    ("LastName", "Last Name");
//$dg -> set_col_title    ("FirstName", "First Name");
 
// set background and mouse over color
$dg -> set_alt_bgcolor  ("#ffffff, #e9eff2");
$dg -> set_onmouseover  ("lightyellow");
 
// hide a column
$dg -> set_col_hidden   ("Notes");
 
// display URL as hyperlink
$dg -> set_col_link    ("ReportsTo",                         
						"/query.php?EmployeeId=",                         
						"EmployeeId",                         
						"target='_new'"); 
 
// set page size
$dg -> set_page_size(10);
 
// sum up columns
$dg -> set_col_sum_enabled(true);
$dg -> set_col_sum      ("initial_sale");
$dg -> set_col_sum      ("final_sale");
$dg -> set_col_sum      ("qty");
$dg -> set_col_sum      ("comm");
 
$dg -> set_theme("sweet");
 
// make the datagrid editable
$dg -> set_allow_actions(true);
 
$dg -> set_action_type ("V,E");
 
// turn on inline-editing with Ajax enabled
//$dg -> set_inlineedit_enabled(true, true);
 
//$dg -> set_ok_showcredit(true);
$dg -> set_allow_export(true);
$dg -> set_toolbar_enabled(FALSE);
 
$dg -> debug();
 
$dg -> display();
echo "<b>Searched For:</b> " .$ifs;
?>
 
 
<h2 align="center"> </h2>
<h2 align="center"> </h2>
<h2 align="center"><strong><font color="#006600"> </font></strong></h2>
<h2 align="center"><strong><font color="#006600"> </font></strong></h2>
<h2 align="center"><strong><font color="#006600"><img src="http://www.thstewart.com/images/invoice.gif" alt="" title="">TH Stewart Co.</font></strong><strong><font color="#006600"><font size="3"></font></font></strong></h2>
<div align="center">
<form action="new.php" method="post">
<div> </div>
<div align="left">
  <p align="center">Final Sale:
 
 
      <input type="text" name="sales" value="<?php echo $ifs; ?>">
      Ship Date:
        <input type="text" name="sdate"> 
        Qty Shipped:
        <input type="text" name="qtys"> 
        ID:
        <input type="text" name="tid">
        
        </p>
 
  <p align="center"> Invoice#:
		    <input type="text" name="seek">
   
        
 
        <br>
        <br>
</p>
  </div>
<div> </div>
<div> </div>
<div>
<input type="hidden" value="yes" name="searching">
<input type="submit" value="Invoice" name="search"></div></form></div>

Open in new window

Avatar of jodibean28
jodibean28
Flag of United States of America image

This should work...

$ifs = mysql_query("SELECT final_sale
FROM oetable_backup WHERE upper($field)='$find'"); 
 
if ($row = mysql_fetch_assoc($ifs))
     $finalsale = $row[0];
 
<input type="text" name="sales" value="<?=$finalsale?>"> 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jseaman12
jseaman12

ASKER

It worked. I just had to place my php code in the front and end because that part of the page is HTML. But I been trying to figure this out for months. This is the best news. Thanks a lot...

<?php
  echo "<input type=\"text\" name=\"sales\" value=\"$finalsale\" /> \n";
  ?>
Great!  Thanks for the points and thanks for using EE! ~Ray