0

Hello there, Can anyone help me in my problem? My problem is, i need to display a record in the textbox, but it's not working. the record(database) and the textboxes.

Thanks :D

2
Contributors
13
Replies
14
Views
5 Years
Discussion Span
Last Post by phorce
Featured Replies
  • 1

    I'm confused to what you actually want to do here.. Do you want to display a record inside a text box, so like have an input box and its value is from the table? OR display a record from the table onto a page? To me, your code suggests that … Read More

0

Sorry, Here's my code. Thanks

<?php

$empno = $_POST['txtempno']; 
$empname = $_POST['txtename'];
$position = $_POST['txtpos']; 
$salary = $_POST['txtsal']; 
$aname=$_POST['txtaname'];
$address=$_POST['txtadd'];
$relation=$_POST['txtremp'];
$age=$_POST['txtage'];
$sss=$_POST['txtsss'];
$ph=$_POST['txtph'];
$pagibig=$_POST['txtpagibig'];
$tax=$_POST['txttax'];
$total=$_POST['txttotal'];
$sss2=$_POST['txtsss2'];
$ph2=$_POST['txtph2'];
$pagibig2=$_POST['txtpagibig2'];
$tax2=$_POST['txttax2'];
$total2=$_POST['txttotal2'];
$tded=$_POST['txttded'];
$tsal=$_POST['txttsal'];
$allotment=$_POST['txtallotment']; 

		$db=mysql_connect('localhost','root','') or die ('Cannot connect to MYSQL!');
		@mysql_select_db('dbriomra') or die('Cannot connect to database');
		
		$query="SELECT * FROM `profiles`";
		
		if($empno!=NULL || $empname!=NULL || $position!=NULL || $salary!=NULL || $aname!=NULL || $address!=NULL || $relation!=NULL || $age!=NULL || $sss!=NULL || $ph!=NULL || $pagibig!=NULL || $tax!=NULL || $total!=NULL || $sss2!=NULL || $ph2!=NULL || $pagibig2!=NULL || $tax2!=NULL || $total2!=NULL || $tded2!=NULL || $tsal2!=NULL || $allotment!=NULL)
					
								if(!mysql_query($query, $db))
								{
									die('Error: ' . mysql_error());
								}
								header('Location: index.php');
					
							mysql_close($db);

?>
1

I'm confused to what you actually want to do here..

Do you want to display a record inside a text box, so like have an input box and its value is from the table?

OR display a record from the table onto a page?

To me, your code suggests that you're passing data from a form, selecting every record from the table, checking to see if the query executes..

0

Right, well, you can't SELECT everything and expect EVERYTHING to display in a text box (Well, you can, but it's not practical lol):

<?php
	$id = (int) 1;
	
	$db=mysql_connect('localhost','root','') or die ('Cannot connect to MYSQL!');
	@mysql_select_db('dbriomra') or die('Cannot connect to database');
		
	$query="SELECT * FROM `profiles` WHERE profile_id='$id'";
	$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="field" value="' .$row['name']. '">';
		}
		echo '</form>';
	}else{
		
	  echo 'There are no records to fetch';
	}
?>

This example selects everything from the table profile, where the profile_id is 1 and if there is a record, displays a text box that has the value of the name.. For example "Phillip"

Hope this helps :)

0

What error does it give?

It was just an example since I don't have access to your database, I cannot tell what fields you have.. =) Maybe provide some extra details?

0
<?php

$empno = $_POST['txtempno']; 
$empname = $_POST['txtename'];
$position = $_POST['txtpos']; 
$salary = $_POST['txtsal']; 
$aname=$_POST['txtaname'];
$address=$_POST['txtadd'];
$relation=$_POST['txtremp'];
$age=$_POST['txtage'];
$sss=$_POST['txtsss'];
$ph=$_POST['txtph'];
$pagibig=$_POST['txtpagibig'];
$tax=$_POST['txttax'];
$total=$_POST['txttotal'];
$sss2=$_POST['txtsss2'];
$ph2=$_POST['txtph2'];
$pagibig2=$_POST['txtpagibig2'];
$tax2=$_POST['txttax2'];
$total2=$_POST['txttotal2'];
$tded=$_POST['txttded'];
$tsal=$_POST['txttsal'];
$allotment=$_POST['txtallotment']; 

		$db=mysql_connect('localhost','root','') or die ('Cannot connect to MYSQL!');
		@mysql_select_db('dbriomra') or die('Cannot connect to database');
		
		$query="SELECT * FROM `profiles`";
		
		if($empno!=NULL || $empname!=NULL || $position!=NULL || $salary!=NULL || $aname!=NULL || $address!=NULL || $relation!=NULL || $age!=NULL || $sss!=NULL || $ph!=NULL || $pagibig!=NULL || $tax!=NULL || $total!=NULL || $sss2!=NULL || $ph2!=NULL || $pagibig2!=NULL || $tax2!=NULL || $total2!=NULL || $tded2!=NULL || $tsal2!=NULL || $allotment!=NULL)
					
								if(!mysql_query($query, $db))
								{
									die('Error: ' . mysql_error());
								}
								header('Location: index.php');
					
							mysql_close($db);

?>

these are only my codes.. details?

0

-stares blankly- :P

Ok, ok

I'm guessing this is one of your field names "empno"?

So you could correct the code like this:

<?php
	$id = (int) 1;
	
	$db=mysql_connect('localhost','root','') or die ('Cannot connect to MYSQL!');
	@mysql_select_db('dbriomra') or die('Cannot connect to database');
		
	$query="SELECT * FROM `profiles` WHERE empno='$id'";
	$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="field" value="' .$row['empname']. '">';
		}
		echo '</form>';
	}else{
		
	  echo 'There are no records to fetch';
	}
?>

I asked for your field names, not your code.. You need to be more descriptive with your problem, otherwise it's hard to help you.

0

These are my field names,

employeeno
employeename
position
salary
allotteename
address
relation
age

Edited by shielaolid: n/a

0
<?php
	$id = (int) 1;
	
	$db=mysql_connect('localhost','root','') or die ('Cannot connect to MYSQL!');
	@mysql_select_db('dbriomra') or die('Cannot connect to database');
		
	$query="SELECT * FROM `profiles` WHERE txtempno='$id'";
	$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="field" value="' .$row['txtename']. '">';
		}
		echo '</form>';
	}else{
		
	  echo 'There are no records to fetch';
	}
?>

Should return a value =) I don't know why you're posting stuff if you want to display something in a text box.. e.g:

<?php

$empno = $_POST['txtempno']; 
$empname = $_POST['txtename'];
$position = $_POST['txtpos']; 
$salary = $_POST['txtsal']; 
$aname=$_POST['txtaname'];
$address=$_POST['txtadd'];
$relation=$_POST['txtremp'];
$age=$_POST['txtage'];
$sss=$_POST['txtsss'];
$ph=$_POST['txtph'];
$pagibig=$_POST['txtpagibig'];
$tax=$_POST['txttax'];
$total=$_POST['txttotal'];
$sss2=$_POST['txtsss2'];
$ph2=$_POST['txtph2'];
$pagibig2=$_POST['txtpagibig2'];
$tax2=$_POST['txttax2'];
$total2=$_POST['txttotal2'];
$tded=$_POST['txttded'];
$tsal=$_POST['txttsal'];
$allotment=$_POST['txtallotment'];
1

No problem :) Please mark this thread as solved and give rep points to those who have helped you (Click on the arrow buttons by their name) - Best of luck :)

Votes + Comments
good
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.