• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

displaying data in text boxes (mysql)

I need to know how to display data from a mysql database in text boxes
my query look somethink like this but obviously doesnt display the data in the text boxes (lets call the textboxes -  box_one, box_two, etc.

SELECT col_one, col_two, col_three, col_four  FROM table_name WHERE (name = $_POST["combo1"]) AND ( date= $_POST["combo2"])";

thanks in advance
0
the_third
Asked:
the_third
  • 3
  • 2
  • 2
  • +3
1 Solution
 
Muhammad WasifCommented:
<?
$db_server = "localhost";
$db_user = "root";
$db_pass = "";
$db = "my_db";

$con = mysql_connect($db_server,$db_user,$db_pass) or die("Unable to connect to MySQL");

mysql_select_db($db, $con)

$sql = "SELECT col_one, col_two, col_three, col_four  FROM table_name WHERE (name = ".$_POST["combo1"].") AND ( date= ".$_POST["combo2"].")";

$result=mysql_query($sql)

if ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
        <input type="text" name="box_one" value="<?=$row["col_one"]?>">
        <input type="text" name="box_two" value="<?=$row["col_two"]?>">
        <input type="text" name="box_two" value="<?=$row["col_three"]?>">
<?
}
?>
0
 
Muhammad WasifCommented:
sorry,
change
<input type="text" name="box_two" value="<?=$row["col_three"]?>">
 to
<input type="text" name="box_three" value="<?=$row["col_three"]?>">

text boxes name should not be identical:)

WASIF
0
 
KaritzCommented:
More to WASIF's response, you use the echo command to put the values into the text box as in this example

<input type="text" name="box_two" value="<? echo $row["col_three"]; ?>">

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
the_thirdAuthor Commented:
this is not working, text box just shows --- <? echo $row[ ----- and then my style attribute --- style="font-size: 1em">  i tried it with both echo and =. I should have mentioned this before but where i say combo1 i mean that it is a value selected by a user fron a pull down menu.
0
 
the_thirdAuthor Commented:
sorry, the ---  style="font-size: 1em">   ---- part is displayed below the textbox.
0
 
KaritzCommented:
check to make sure that all the opening and closing tags before, in and  after the text box are well opened and closed


<>......</>

also check to ensure that the query returns some results
0
 
Muhammad WasifCommented:
echo $_POST["combo1"]."<br>";
echo $_POST["combo2"]."<br>";
echo $sql;

check combo1 and combo2 has some values and run that query in MySQL and check whether it returns the results or not

WASIF
0
 
ashooooCommented:
Either you are not closing all the tags <...>, </...> or if you see the <? printed on your browser, PHP may not be working.
0
 
ZontarCommented:
<?php
error_reporting(E_ALL);  //  turn on all PHP warnings and notices

$db_server = "localhost";
$db_user = "root";
$db_pass = "";
$db = "my_db";

$con = mysql_connect($db_server,$db_user,$db_pass)
  or die("<p>MySQL error " . mysql_errno() .  ": " . mysql_error()  .  "</p>");

mysql_select_db($db, $con)
  or die("<p>MySQL error " . mysql_errno() .  ": " . mysql_error()  .  "</p>");

if( !isset($_POST["combo1"]) )
  echo "<p>No combo1 value.</p>";
else $name = $_POST["combo1"];

if( !isset($_POST["combo2"]) )
  echo "<p>No combo1 value.</p>";
else $date = $_POST["combo2"];

$sql = "SELECT col_one, col_two, col_three, col_four FROM table_name WHERE name='$name' AND date='$date'";

if(!$result=mysql_query($sql))
  echo "<p>MySQL error " . mysql_errno() .  ": " . mysql_error()  .  "</p>";

if(mysql_num_rows($result) < 1)
  echo "<p>No rows returned.</p>";
else($row = mysql_fetch_assoc($result))
{
  extract($row, EXTR_PEFIX_ALL, "qry_");
?>
        <input type="text" name="box_one" value="<?php echo $qry_col_one; ?>">
        <input type="text" name="box_two" value="<?php echo $qry_col_two; ?>">
        <input type="text" name="box_three" value="<?php echo $qry_col_three; ?>">
        <input type="text" name="box_four" value="<?php echo $qry_col_four; ?>">
<?php
}
?>

Make sure all HTML attributes are quoted. Don't use shortcuts (1) <? ?> instead of <?php ?> or (2) <?=$myval?> instead of <?php echo $myval; ?> -- the shortcuts may not work on all servers.

Error-check every step of the way -- use mysql_errno() and mysql_error() to generate precise MySQL error codes and messages for debugging. Always check to make sure $_POST, $_GET, $_COOKIE, $_SESSION (etc.) values are getting passed to the script. You can never be too thin or too rich, or do too much error checking. ;-)

View source of the generated page in your browser -- there may be PHP error messages there that don't show up in the browser (they might be in the head of the page, inside the <...> of an HTML tag, etc.).
0
 
andylarksCommented:
Golly, that all looks very confusing:

Try this...
-----------------------------------------
$db_server = "localhost";
$db_user = "root";
$db_pass = "";
$db = "my_db";

$con = mysql_connect($db_server,$db_user,$db_pass) or die("Unable to connect to MySQL");

mysql_select_db($db, $con)

$sql = "SELECT col_one, col_two, col_three, col_four  FROM table_name WHERE (name = ".$_POST["combo1"].") AND ( date= ".$_POST["combo2"].")";
$result=mysql_query($sql)

while ($row=mysql_fetch_assoc($result)) {
   echo "<input type=\"text\" name=\"box_one\" value=\"".$row["col_one"]."\">";
   echo "<input type=\"text\" name=\"box_two\" value=\"".$row["col_two"]."\">";
   echo "<input type=\"text\" name=\"box_three\" value=\"".$row["col_three"]."\">";
}

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now