Solved

displaying data in text boxes (mysql)

Posted on 2003-11-13
10
269 Views
Last Modified: 2008-03-06
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
Comment
Question by:the_third
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 9745598
<?
$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
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 9745609
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
 
LVL 5

Expert Comment

by:Karitz
ID: 9745969
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
Independent Software Vendors: 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!

 

Author Comment

by:the_third
ID: 9746223
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
 

Author Comment

by:the_third
ID: 9746242
sorry, the ---  style="font-size: 1em">   ---- part is displayed below the textbox.
0
 
LVL 5

Expert Comment

by:Karitz
ID: 9746443
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
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 9746491
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
 
LVL 3

Expert Comment

by:ashoooo
ID: 9751468
Either you are not closing all the tags <...>, </...> or if you see the <? printed on your browser, PHP may not be working.
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9755998
<?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
 

Accepted Solution

by:
andylarks earned 100 total points
ID: 9763870
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question