problem with forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
katun
Forum Newbie
Posts: 5
Joined: Sun Aug 22, 2004 12:20 pm

problem with forms

Post by katun »

I have a small form and this put some text into a plain file.
After that, if I want to change a line in this file, I have a PHP script to read the text, get the line I need to change and put this line in a text field on my form.

And now is the problem: on this procedure I lose a part of my text line, my PHP script put in text field just the first word from text line.

Help me, please.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your code.
katun
Forum Newbie
Posts: 5
Joined: Sun Aug 22, 2004 12:20 pm

Post by katun »

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php
//File Name to read Here
    $filename = "used_cars.dat";
//Checks to see if the file exist
    if (file_exists("$filename")) {
//Assigns all the content from the file to the var $info
    $inline = file($filename);

    list ($nrcrt, $tip, $capacitate, $an, $km, $carburant, $culoare, $dotari, $pret, $img) = split('[|]', $inline[$y]);
	$tip = str_replace ( "_", " ", $tip );
	$capacitate = str_replace ( "_", " ", $capacitate );
	$an = str_replace ( "_", " ", $an );
	$km = str_replace ( "_", " ", $km );
	$carburant = str_replace ( "_", " ", $carburant );
	$culoare = str_replace ( "_", " ", $culoare );
	$dotari = str_replace ( "_", " ", $dotari );
	$pret = str_replace ( "_", " ", $pret );

echo "<html><title>Modifica Auto</title><body>";
echo "<FORM name='this' method='post' action='input_mod.php'>";

echo "<BR><table cellpadding="2" cellspacing="0" border="1" bordercolor="#CCCCCC" align="center"><TR> 
      <TD bgcolor="#003399"><font face="Arial, Helvetica, sans-serif" color='#ffffff' size='2'><b>Detalii Automobil</b></font></TD>
    </TR>
    <TR> 
      <TD align="center"> 
        <TABLE border="0" cellspacing="1" cellpadding="1" align="center">";
echo "<TR><TD>&nbsp;</TD></TR>
     <TR><TD align='center'>";
echo "<TABLE border='0' cellspacing='1' cellpadding='1' align='center' width='100%'><TR>
            <TD><font face='Arial, Helvetica, sans-serif' size='-2'></font></TD>
            <TD width='30%'><font face='Arial, Helvetica, sans-serif' size='-2'><b>Tip/Model:</b></font></TD>
            <TD width='30%'><font face='Arial, Helvetica, sans-serif' size='-2'></font></TD>
            <TD width='30%'><font face='Arial, Helvetica, sans-serif' size='-2'><b>Imagine:</b></font></TD>
          </TR>
          <TR>
            <TD><font face='Arial, Helvetica, sans-serif' size='-2'></font></TD>
            <TD width='30%'> <font face='Arial, Helvetica, sans-serif' size='-2'>
              <input type='text' name='tip' size='20' value=$tip>
              </font></TD><TD colspan="2"><font face='Arial, Helvetica, sans-serif' size='2'>
              <input type='file' name='filename' size='29' id='filename' value=$img>
              </font></TD>
          </TR>
          <TR>
            <TD  align='left'><font face='Arial, Helvetica, sans-serif' size='-2'></font></TD>
            <TD  align='left' width='30%'><b><font face='Arial, Helvetica, sans-serif' size='-2'>Capacitate
              motor (CP):</font></b></TD>
            <TD  align='left' width='30%'><b><font face='Arial, Helvetica, sans-serif' size='-2'>An
              fabricatie:</font></b></TD>
            <TD align='left' width='30%'><b><font face='Arial, Helvetica, sans-serif' size='-2'>Rulaj
              (km):</font></b></TD>
          </TR>
          <TR>
            <TD>&nbsp;</TD>
            <TD width='30%'><font face='Arial, Helvetica, sans-serif' size='-2'>
              <input type='text' name='capacitate' value=$capacitate size='12'>
              </font></TD>
            <TD width='30%'><font face='Arial, Helvetica, sans-serif' size='-2'>
              <input type='text' name='an' value=$an size='10'>
              </font></TD>";

echo       "<TD width='30%'><font face='Arial, Helvetica, sans-serif' size='-2'>
              <input type='text' name='km' value=$km size='12'>
              </font></TD>
          </TR>";
          
echo     "<TR>
            <TD>&nbsp;</TD>
            <TD width='30%'><b><font face='Arial, Helvetica, sans-serif' size='-2'>Carburant:</font></b></TD>
            <TD width='30%'><font face='Arial, Helvetica, sans-serif' size='-2'><b>Culoare:</b>
              </font></TD>
            <TD width='30%'><b><font face='Arial, Helvetica, sans-serif' size='-2'>Pret
              (&euro;):</font></b></TD>
          </TR>
          <TR>
            <TD>&nbsp;</TD>
            <TD width='30%'>
              <select name='carburant' id='carburant'>";
if ($carburant=" "){			  
echo           "<option value=' ' selected> </option>";}
else{
echo           "<option value=' '> </option>";}
if ($carburant="Benzina"){
echo           "<option value='Benzina' selected>Benzina</option>";}
else{
echo           "<option value='Benzina'>Benzina</option>";}

if ($carburant="Motorina"){
echo           "<option value='Motorina' selected>Motorina</option>";}
else{
echo           "<option value='Motorina'>Motorina</option>";}
echo         "</select>
            </TD>
            <TD width='30%'>
              <input type='text' maxlength='20' size='15' name='culoare' value=$culoare>
            </TD>
            <TD width='30%'><input type='text' name='pret' value=$pret size='10' maxlength='6'></TD></TR>
          <TR>
            <TD>&nbsp;</TD>
            <TD colspan="3"><span class="style2"><font face="Arial, Helvetica, sans-serif" size='-2'>Dotari:</font></span></TD>
          </TR>
          <TR>
            <TD>&nbsp;</TD>
            <TD colspan="3"><textarea name="dotari" cols="50" rows="5" id="dotari" value=$dotari></textarea></TD>
          </TR>
          <TR>
            <TD>&nbsp;</TD>
            <TD colspan="3">&nbsp;</TD>
            </TR>			
			</TABLE></table>";

echo "</TD></TR></TABLE>";
echo "<TABLE width=50% border='0' cellspacing='0' cellpadding='0' align='center'>
    <TR>
      <TD align='center'><br>
        <input type='hidden' name='nrcrt' value=$nrcrt>
        <input type='hidden' name='y' value=$y>
		<INPUT type='submit' name='yes' value=Modifica>
        </td>
        <td><br>
        <INPUT type='submit' name='Renuntare' value=Renunta>        
      </TD>
    </TR>
  </TABLE>";
echo "</FORM>";
</body></html>";
}
 ?>

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm going to hazard a guess that $dotari is the content, or maybe $pret.. at any rate, value attributes need to be in quotes. Textarea's values are a little different though. They are supposed to be stored inside the container, not in a value attribute..

Code: Select all

&lt;textarea name="dotari" cols="50" rows="5" id="dotari"&gt;$dotari&lt;/textarea&gt;
if $dotari contains HTML, then you need to escape it for the code to show up in the textarea: [php_man]htmlentities[/php_man]()
katun
Forum Newbie
Posts: 5
Joined: Sun Aug 22, 2004 12:20 pm

Post by katun »

I try this but the resut is identical!
:(
Maybe you have an other suggestion.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

As feyd said:
value attributes need to be in quotes
Where you have things like:
value=$capacitate
value=$pret
etc..etc..you need to quote them, eg
value="$capacitate"
value="$pret"
but because of your funky way of using quotes you'll need to do:
value=\"$capacitate\"
value=\"$pret\"

Be sure to change all the other place where you do value=$somevar too.
Post Reply