Solved

displaying data in text boxes (mysql)

Posted on 2003-11-13
10
266 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
Comment Utility
<?
$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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:the_third
Comment Utility
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
Comment Utility
sorry, the ---  style="font-size: 1em">   ---- part is displayed below the textbox.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 5

Expert Comment

by:Karitz
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<?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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now