Solved

displaying data in text boxes (mysql)

Posted on 2003-11-13
10
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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.

726 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