Hello does anyone know how to bring details from a database into a textbox? becuase ive got the login working and it displays whos logged in but i want the postcode to appear in a textbox, the postcode is kept in mysql table called address.

/after connecting to mysql

$query  = "SELECT * FROM StudentRecords WHERE Email= '".$myusername."'";	
$result = mysql_query($query);

<td><input type="text" name="PickupAddressPostCode"</td>
$query = "SELECT address_code FROM address WHERE userID= '".$myuserID."'";
$result = mysql_query($query);

<td><input type="text" name="PickupAddressPostCode" value="<?php echo $result['address_code']; ?>" /></td>

Matti Ressler
Suomedia

thank u :D

Mark as solved ;)

Its meant to select the postcode from the address table where the email matchs the login name which is myusername. and then display postcode in the textbox. it connects to database but in the textbox what the postcode is meant to appear in it says...
<br /><b>Notice</b>: Undefined variable: result in <b>/home/public_html/book.php</b> on line <b>79</b><br />

<? 
$query = "SELECT PostCode FROM address WHERE
Email= '".$myusername."'";
$result = mysql_query($query);
?>

line 79 is here 
<td><input type="text" name="PickPostCode" value="<?php echo 
$result['PostCode ']; ?>" /></td>

You need to connect to mySQL, select the database, make the query, fetch the result with mysql_fetch_array() and close the connection.


Matti Ressler
Suomedia

ive got the connection the database connection and everything working expect that 1 notice

$query = "SELECT address_code FROM address WHERE userID= '".$myuserID."'";
$result = mysql_query($query);

<td><input type="text" name="PickupAddressPostCode" value="<?php echo $result['address_code']; ?>" /></td>

Matti Ressler
Suomedia

That should actually be

$query = "SELECT address_code FROM address WHERE userID= '".$myuserID."'";
$result = mysql_query($query);
$row = mysql_fech_array($result); //or while($row = mysql_fetch_array($result)) if your query returns more than 1 row
<td><input type="text" name="PickupAddressPostCode" value="<?php echo $row['address_code']; ?>" /></td>

Cheers,
Naveen

Still not working

Same error ? Try mysql_error() with die statement. Also print out your query and tell us what it says !

That should actually be

$query = "SELECT address_code FROM address WHERE userID= '".$myuserID."'";
$result = mysql_query($query);
$row = mysql_fech_array($result); //or while($row = mysql_fetch_array($result)) if your query returns more than 1 row
<td><input type="text" name="PickupAddressPostCode" value="<?php echo $row['address_code']; ?>" /></td>

Cheers,
Naveen

That should actually be:

$query = "SELECT address_code FROM address WHERE userID= '".$myuserID."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result); //or while($row = mysql_fetch_array($result)) if your query returns more than 1 row
<td><input type="text" name="PickupAddressPostCode" value="<?php echo $row['address_code']; ?>" /></td>

Don't you hate it when the phone rings and the edit window times out ;)


Matti Ressler
Suomedia

Same error ? Try mysql_error() with die statement. Also print out your query and tell us what it says !

Its saying theres a error here

<input type="text" name="PickupAddressPostCode" value="<?php echo $row['PickupAddressPostCode']; ?>"

<br /><b>Notice</b>: Undefined variable: row in on line <b>78</b><br />

Ive got this code connecting to database in the login check form because when the user signs in i want the postcode 2appear automatically

$query = "SELECT PickupAddressPostCode FROM StudentRecords WHERE Email= '".$myusername."'";
$result = mysql_query($query, $connection);
while($row = mysql_fetch_array($result))

// Close connection ! (please !)
mysql_close($connection);

try something like this

$result1=mysql_query("");
for ($i = 0; $i < 1; ++$i)
{
$line = mysql_fetch_row($result1);
echo $line[0];
}

Hello ive sorted the errors out but now its saying that myusername is undefined its somthing to do with the select statement, because when im selecting im only selecting student table and its fields but myusername should already be defined has its used to login and also displays the name at the top of the page..

'".$myusername."'";

When you start the script, make $myusername null. Then assign a value to it and then print it.
ie., $myusername="";

hello ive tried it but nothing is now getting displayed in textbox, but no errors now. i put..

<?

$myusername="Null"; 

// Standard SQL
$query = "SELECT PickupAddressPostCode FROM Student WHERE Email= '".$myusername."'";

i dont understand what you mean assign a value to it and then print?

Post your complete latest code.

Post your complete latest code.

session for user first page

<? 
session_start();
if(!session_is_registered("myusername")){
header("location:StudentLogin.php");
}
?>


<?

$myusername=""; 

// Standard SQL
$query = "SELECT PickupAddressPostCode FROM StudentRecords WHERE Email= '".$_SESSION['myusername']."'";

echo $sql;


// Connect to DB server
$connection = mysql_connect("Host", "", "");
if (!$connection)
	die("Cannot connect to DB");

// Select database
mysql_select_db("", $connection)
	or die("Cannot find DB");

$result = mysql_query($query, $connection);


// Loop through data and display
while($row = mysql_fetch_array($result))
echo "<tr><td style=\"color:Black\">".$a_row['PickupAddressPostCode']."</td>". 
                    "<tr><td style=\"color:Black\">".$a_row['Email']."</td></tr>"; 


// Close connection ! (please !)
mysql_close($connection);

?>
<input type="text" name="PickupAddressPostCode" value="<?php echo $row['PickupAddressPostCode']; ?>" />

Yes i want postcode to appear in textbox as soon as the user logs in the email is the same as username but username comes from members and email comes from students table. 2diffrent tables check the code but now its saying

Notice: Undefined variable: sql in /home/book2.php on line 16

Notice: Undefined variable: a_row in /home/book2.php on line 33

Notice: Undefined variable: a_row in /home/book.php on line 34

mysql_select_db("", $connection)

You haven't specified the Dbname. Turn off the notices OR (which is a very good option) initialize your variables before using it to get rid of notices.

database is connected just taken the name out due to posting the code, but does the coding look correct, either way nothing is displaying in textbox

Hmm.. Seems good.. But, the only problem I can think off is, either $_SESSION is empty or the query returns records with null values.
Oh, hey btw, use { } for your while loop.

Attach your files in a zip using the attachment option when posting your next message (the paper clip).


Matti Ressler
Suomedia

As per the rules, Suomedia, it's good to keep things on the site. Solving problems through PMs, email and sending attachments makes things cumbersome and difficult to search through if someone else is sharing the problem.

As per the rules, Suomedia, it's good to keep things on the site. Solving problems through PMs, email and sending attachments makes things cumbersome and difficult to search through if someone else is sharing the problem.

It is on site. This forum is designed to allow attachments to posts so that the threads are not cluttered with mile long posts of code (more than one file in this case).

Please leave moderating to the moderators :icon_frown:


Matti Ressler
Suomedia

Anyway, aside from that

Notice: Undefined variable: sql in /home/book2.php on line 16

Notice: Undefined variable: a_row in /home/book2.php on line 33

Notice: Undefined variable: a_row in /home/book.php on line 34

The first error is happening because echo $sql; should be echo $query .
The second and third are happening because $a_row should be $row

Hello its all working now but the postcode dont appear in the textbox it appears at the top of the page, even though ive used

<input type="text" name="PickupAddressPostCode" value="<?php echo $row['PickupAddressPostCode']; ?>" />

Give this a shot

<input type='text' name='PickupAddressPostCode' value='<?=$row['PickupAddressCode'];' />

Give this a shot

<input type='text' name='PickupAddressPostCode' value='<?=$row['PickupAddressCode'];' />

Umm.. doesn't make any difference since <?php echo $row is same as <?=$row; ?> .. Why not have your input box in the loop itself ? ie.,

while($row = mysql_fetch_array($result)){
echo "<input type='text' name='PickupAddressPostcode' value='".$row['PickupAddressCode']."'>";
}

still aint working coming up causing an error on the next textbox.

Can you post your latest code which showed PickupAddressPostcode on top ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.