Fetch_Array with String field

I use mysql_fetch_array and get the correct row. In the simple code below:

$result = mysql_query( “SELECT * from Members where Tail_Num=‘N1074Y’” );
while ($a_row = mysql_fetch_array( $result ) ) {
$Name = $a_row[‘Name’];

The field contains “Firstname Lastname”. But when I look at the value of $Name, it is only “Firstname”.
If I print $a_row[‘Name’], then I get “Firstname Lastname”.
It appears that spaces in a text string truncate the assignment. How do I work around this?

This should not be a case. Probably you’re outputting this value to html element and not using quotes/double quotes? For example, if you do this:
[php]<?php
echo “”;
?>[/php]
Everything after first space in the value of $Name will not be displayed in html.

So how would I assign the SQL field to a variable and capture the entire string?

Use quotes or double quotes. Also htmlspecialchars() function to encode special characters like < > etc.
Example:
[php]<?php
echo ‘’;
?>[/php]

The first echo statement works perfectly and prints the entire string.

But when the array is part of the HTML value = statement, only the chars up to the space print.

while ($a_row = mysql_fetch_array( $result ) ) {

echo $a_row[‘Name’];

echo ‘<input name = “name” size=30 value =’;
echo htmlspecialchars($a_row[‘Name’]);
echo ‘">’;

I promise this is my last request for help…

This is your code:

echo ‘<input name = “name” size=30 value =’;
echo htmlspecialchars($a_row[‘Name’]);
echo ‘">’;

See, at the end of the first line you have =’; this is correct php code, but still incorrect HTML (you are missing opening double quote). Correct code is:

echo ‘’;

Sponsor our Newsletter | Privacy Policy | Terms of Service