Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

displaying data in text boxes (mysql)

Posted on 2003-11-13
10
Medium Priority
?
275 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 400 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If 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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 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