Page 1 of 1

why the echo command not returning the full string...

Posted: Sun Oct 16, 2011 7:40 pm
by grabber_grabbs
i have this input command to get a search value
Search Here :<input type="text" name="varsearch" id="varsearch" size="40" value = <?php echo "{$varsearch}"; ?> >

Here as the return value i have the php echo command to return the value of the previous search...

I initially thought that all was working fine, because i was only searching with one word.... but just noticed that if i search like
2% Milk, i have only the string 2% that appear in the search field once the search done....

In my Php code (further down the code), if i do echo $varsearch, i do get all the characters...(2% Milk)

In my input command, i did try <?php echo "$varsearch"; ?> (with no brackets, but no luck either.... it returns one word only.)


Again 1000 thanks to all of you supporting this site and helping newbies like me. :D

Re: why the echo command not returning the full string...

Posted: Sun Oct 16, 2011 8:00 pm
by Celauran

Code: Select all

<input type="text" name="varsearch" id="varsearch" size="40" value="<?php echo $varsearch; ?>" />

Re: why the echo command not returning the full string...

Posted: Mon Oct 17, 2011 8:45 am
by grabber_grabbs
yeah... tried that, but no luck.... still returning the first word only.....
what puzzle me is in in the code below this <form> where i transfer the value of varibles $_POST['varsearch'],
if i do
varsearch = $_POST['varsearch'];
echo $varsearch;

i get the full string !!!!

Re: why the echo command not returning the full string...

Posted: Mon Oct 17, 2011 8:53 am
by grabber_grabbs
i was in the same situation in the past where i had my input hidden command, it was transfering only the first word... you suggested putting brackets
echo " <input type=hidden name=NAME value=\"{$desc}\" />";

and it solved the problem,

Re: why the echo command not returning the full string...

Posted: Mon Oct 17, 2011 9:00 am
by Celauran
grabber_grabbs wrote:yeah... tried that, but no luck.... still returning the first word only.....
That doesn't make any sense. There must be something else at play here. Please post the relevant code beyond just that single line.

Re: why the echo command not returning the full string...

Posted: Mon Oct 17, 2011 9:21 am
by grabber_grabbs
at the top of my page i have this :
<form id="form1" name="form1" method="post" action="">
Recherche :<input type="text" name="varsearch" id="varsearch" size="40" value = <?php echo $varsearch; ?> >
</form>

somewhere below i have this to search the whole sql database until end of file, all is working fine here for this

while ($db_field = mysql_fetch_assoc($result)) {
$prodno = $db_field['PRODNO'];
$desc = $db_field['DESCSHORT'];
$dept = $db_field['DEPT'];
$desclong = $db_field['DESCLONG'];
$prix = $db_field['PRIX'];
$instock = $db_field['STOCK'];
$picture = $prodno;
$picture .= ".jpg";
$varsearch = $_POST['varsearch'];
echo $varsearch;

Echo " <P><FORM NAME=order onSubmit=\"AddToCart(this); return false\"> ";
Echo "<br> Quantity: <input type=text size=2 maxlength=3 name=QUANTITY onChange='this.value=CKquantity(this.value)' value=\"1\"> ";
Echo " <input type=hidden name=\"PRICE\" value=$prix> ";
echo " <input type=hidden name=NAME value=\"$desc\" >";
Echo " <input type=hidden name=\"ID_NUM\" value=\"$prodno\"> ";
echo "<input type=\"hidden\" name=\"SHIPPING\" value=\"0.00\">";
echo "<input type=\"hidden\" name=\"WEIGHT\" value=\"0\"><br />";
echo "<FONT FACE=\"ARIAL,HELVETICA\" SIZE=5>";
echo " <B>Prix $prix</B>";
echo " </FONT>";
echo " <FONT FACE=\"ARIAL,HELVETICA\" SIZE=2>";
Echo " <input type=\"image\" src=\"./images/cart.gif\" border=0 value=\"Add to Cart\" align=top> ";
echo "<br><a href=\"managecart.html\"><small>Votre panier</small></a></form>";
echo "</td>";
}

Re: why the echo command not returning the full string...

Posted: Mon Oct 17, 2011 10:05 am
by Celauran
grabber_grabbs wrote:at the top of my page i have this :
<form id="form1" name="form1" method="post" action="">
Recherche :<input type="text" name="varsearch" id="varsearch" size="40" value = <?php echo $varsearch; ?> >
</form>
Et voilà le problème! You don't have quotes around your value.

Code: Select all

<form id="form1" name="form1" method="post" action="">
Recherche :<input type="text" name="varsearch" id="varsearch"  size="40" value="<?php echo $varsearch; ?>" />
</form>
Your echo $varsearch farther down the page is working fine because $_POST['varsearch'] contains whatever you typed into the text box. It's when you try to place it back in the text box that you're having problems, and that's due to the missing quotes.

Re: why the echo command not returning the full string...

Posted: Mon Oct 17, 2011 11:09 am
by grabber_grabbs
tried this in the first thing.... no success either.
right now this is what i got,

Recherche :<input type="text" name="varsearch" id="varsearch" size="40" value = <?php echo "$varsearch"; ?> >

if you try this
http://www.caraquetvacances.com/cart/index.html
then you click at the bottom on produit laitiers
do a search from there....

you will notice where the $varsearch is echoed... right above the pictures. You will see the $varsearch echoed 3 times because i have 3 products in my database. (echoed only if in the produits laitiers department)

please dont look at the pictures of each items... they are not related at all to the product... just testing here.

Re: why the echo command not returning the full string...

Posted: Mon Oct 17, 2011 11:59 am
by Celauran
What you've got:

Code: Select all

Recherche :<input type="text" name="varsearch" id="varsearch" size="40" value = <?php echo "$varsearch"; ?> >
What I'm suggesting:

Code: Select all

Recherche :<input type="text" name="varsearch" id="varsearch" size="40" value="<?php echo $varsearch; ?>" />
See how they're not the same?

Re: why the echo command not returning the full string...

Posted: Mon Oct 17, 2011 1:02 pm
by grabber_grabbs
see i am just learning php and man, your contribution to this forums is fantastic.

what is your degree ? are you a webmaster, working developping website, anyway, you have allways resolved the problem i had up to now and i want to thank you for this.

Eventually i will need your paypal account for me to send you a little something for the help you provide.

thanks again.

Yep as you guess, the "" had to be placed outside the <?php and the closing tag ?>

thanks.