Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Fetching Data and Displaying on Textbox

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Fetching Data and Displaying on Textbox

Postby LiliumVitae » Thu Sep 05, 2013 3:09 am

Hi, I am new here and beginner in PHP. Please help me with my little code.

$searchterm = $_POST['searchterm'];
trim ($searchterm);
if (!$searchterm)
echo '<br><br>Please enter a search term.';
if (!get_magic_quotes_gpc())
$searchterm = addslashes($searchterm);
@ $dbconn = new mysqli('localhost', 'root', '', 'dbname');
if (mysqli_connect_errno())
echo 'Error: Could not connect to database. Please try again later.';
$query = "select * from table_name where first_name like '%".$searchterm."%'";
$result = mysql_query($query);

if(mysql_affected_rows() >= 1)
echo '<form method="post" action="">';
while($row = mysql_fetch_array($result))
echo '<input type="text" name="textbox1" value="' .$row['rowname1']. '">';
echo '<input type="text" name="textbox2" value="' .$row['rowname2']. '">';
echo '</form>';
echo 'There are no records to fetch';

The above code does what I want, that is to search mysql database and display it on textbox However, it creates new Textboxes to show the data. BUT, I want to display the data on those textboxes that I have already created on my HTML Page.

I added [PHP]value = "<?php echo $row['txtname']; ?>" [/PHP] in the HTML code but still does not work. Please help, I need it urgent for my school project.

Thank you.

PS : any advice or changes in my code is warmly welcome :)
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Sep 05, 2013 3:00 am

Re: Fetching Data and Displaying on Textbox

Postby johnj » Sun Sep 08, 2013 2:47 am

if the html is in the same page you can do what you are currently trying to do ELSE you should save the value to a session variable and then try to display it in your html page.
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.