[PHP] alle variabelen vallen weg met fwrite

Pagina: 1
Acties:

  • Snow_King
  • Registratie: April 2001
  • Laatst online: 22:09

Snow_King

Konijn is stoer!

Topicstarter
Hallo,

Ik zit met een moeilijk probleem en ga het zo goed mogelijk proberen uit te leggen.

Ik ben een script aan het maken, waar mensen een offerte kunnen aanvragen.

Nu is er geen MySQL op de server dus moet het ingevulde worden opgeslagen in een txt bestand.

Nu vullen mensen alles in en dan krijgen ze een bevestingings pagina waar ze kunnen zien wat ze hebben ingetypt, keuren ze dat goed dan wordt alles weggescreven in een txt bestand.

Maar het gekke is alle variabelen (wat is ingevuld door de bezoeker) valt weg...

zo scrhijf ik het weg
PHP:
1
<?    $file = date("d-m-Y:s");    $file .= ".html";    $fp = fopen($file, "w");    fwrite($fp, "$body,");    fclose($fp);?>

ik heb al van alles geprobeerd! in de variabele body staat een complete html pagina, hier een klein stukje uit $body
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$body = "
<html>
<head>
<link href='../style.css' type='text/css' rel='stylesheet'>
</head>
<body bgcolor='#FFFFFF' text='#000066' leftmargin='20'>
<center>
<table border='0' width='100%'>
  <tr>
    <td width='540' bgcolor='#000066'>
    <h4 align='center'>Offerte Autoverzekeringen</h4>
    </td>
  </tr>
</table>
<p>&nbsp;</p>
<strong><font color='#000066' face='Arial' size='2'>Voor 
    welke autoverzekering wilt u een offerte hebben ? </strong>$Typeverzekering</font>
<br><br>
     <table border='0' width='100%'>
      <tr>
        <td width='25%'><font color='#000066' face='Arial' size='2'>Ingangsdatum</font></td>
        <td width='25%'><font color='#000066' face='Arial' size='2'>$Ingangsdatum</font></td>
        <td width='25%'><font color='#000066' face='Arial' size='2'>Bouwjaar + mnd</font></td>
        <td width='25%'><font color='#000066' face='Arial' size='2'>$Bouwjaar</font></td>
      </tr>

dus even kort, bijv de variable $Bouwjaar wordt niet in de html pagina gestopt terwijl ie wel geset is!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

en als je 'm gewoon print, die $body, dan krijg je wel de gewenste output? Zo niet, probeer direct voor de fopen () eventjes $Bouwjaar te echo-en.

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • Nielsz
  • Registratie: Maart 2001
  • Niet online
Haal bij die fwrite eens die "'s weg?

En dit is een heel mooi voorbeeld waar XML goed voor gebruikt zou kunnen worden ;)

  • ^Mo^
  • Registratie: Januari 2001
  • Laatst online: 04-11-2025
code:
1
<td width='25%'><font color='#000066' face='Arial' size='2'>$Bouwjaar</font></td>

Dit is gewoon plain html, maak er eens dit van bijvoorbeeld:
code:
1
<td width='25%'><font color='#000066' face='Arial' size='2'><? printf( $Bouwjaar); ?></font></td>

"There are 10 kinds of people in the world, those who understand binary and those who don't" | Werkbak specs


  • Snow_King
  • Registratie: April 2001
  • Laatst online: 22:09

Snow_King

Konijn is stoer!

Topicstarter
Op dinsdag 11 juni 2002 17:46 schreef _Mo_ het volgende:
code:
1
<td width='25%'><font color='#000066' face='Arial' size='2'>$Bouwjaar</font></td>

Dit is gewoon plain html, maak er eens dit van bijvoorbeeld:
code:
1
<td width='25%'><font color='#000066' face='Arial' size='2'><? printf( $Bouwjaar); ?></font></td>
als ik het gehele script post begrijp je het..
PHP:
1
<?if(isset($ContactGewenst)) {                    // Checked of ContactGewenst is aangevinkt of niet    $ContactGewenst = "Ja";                    // Zo ja, maak er dan 'Ja' van} else {    $ContactGewenst = "Nee";                // Zo nee, maak er dan 'Nee' van}$body = "<html><head><link href='../style.css' type='text/css' rel='stylesheet'></head><body bgcolor='#FFFFFF' text='#000066' leftmargin='20'><center><table border='0' width='100%'>  <tr>    <td width='540' bgcolor='#000066'>      <h4 align='center'>Offerte Autoverzekeringen</h4>    </td>  </tr></table><p>&amp;nbsp;</p><strong><font color='#000066' face='Arial' size='2'>Voor     welke autoverzekering wilt u een offerte hebben ? </strong>$Typeverzekering</font><br><br>     <table border='0' width='100%'>        <tr>          <td width='25%'><font color='#000066' face='Arial' size='2'>Ingangsdatum</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Ingangsdatum</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>Bouwjaar + mnd</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Bouwjaar</font></td>        </tr>        <tr>          <td width='25%'><font color='#000066' face='Arial' size='2'>Nationaliteit</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Nationaliteit</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>Beveiliging</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Beveiliging</font></td>        </tr>        <tr>          <td width='25%'><font color='#000066' face='Arial' size='2'>Geslacht</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Geslacht</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>Brandstof</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Brandstof</font>        </tr>        <tr>          <td width='25%'><font color='#000066' face='Arial' size='2'>Jaren rijbewijs</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$jaren_rijbewijs jaar</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>Gewicht</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Gewicht kg</font></td>        </tr>        <tr>          <td width='25%'><font color='#000066' face='Arial' size='2'>Jaren verzekerd</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$jaren_verzekerd jaar</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>Nieuwwaarde</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>€ $Nieuwwaarde</font></td>        </tr>        <tr>          <td width='25%'><font color='#000066' face='Arial' size='2'>Jaren schadevij</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$jaren_schadevrij jaar</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>Dagwaarde</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>€ $Dagwaarde</font></td>        </tr>        <tr>          <td width='25%'><font color='#000066' face='Arial' size='2'>Schadeverleden</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Schadeverleden</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>Kilometers</font></td>          <td width='25%'><font color='#000066' face='Arial' size='2'>$Kilometers km</font></td>        </tr>        <tr>          <td height='29'><font color='#000066' face='Arial' size='2'>Gebruik</font></td>          <td height='29'><font color='#000066' face='Arial' size='2'>$Gebruik</font></td>          <td height='29'><font color='#000066' face='Arial' size='2'>2e Gezinsauto</font></td>          <td height='29'><font color='#000066' face='Arial' size='2'>$gezinsauto</font></td>        </tr>      </table>  <p><strong><font color='#000066' face='Arial' size='2'>Hoe kunnen we contact met u opnemen?</font></strong></p>      <table width='100%'>        <tr>          <td width='50%'><font color='#000066' face='Arial' size='2'>Naam</font></td>          <td width='50%'><font color='#000066' face='Arial' size='2'>$Naam</font></td>        </tr>        <tr>          <td width='50%'><font face='Arial' color='#000066' size='2'>Adres</font></td>          <td width='50%'><font color='#000066' face='Arial' size='2'>$Adres</font></td>        </tr>        <tr>          <td width='50%'><font size='2' face='Arial' color='#000066'>Woonplaats</font></td>          <td width='50%'><font color='#000066' face='Arial' size='2'>$Woonplaats</font></td>        </tr>        <tr>          <td width='50%'><font color='#000066' face='Arial' size='2'>E-mail</font></td>          <td width='50%'><font color='#000066' face='Arial' size='2'><a href='mailto:$Email'>$Email</a></font></td>        </tr>        <tr>          <td width='50%'><font color='#000066' face='Arial' size='2'>Telefoon</font></td>          <td width='50%'><font color='#000066' face='Arial' size='2'>$Telefoon</font></td>        </tr>        <tr>          <td width='50%'><font color='#000066' face='Arial' size='2'>Fax</font></td>          <td width='50%'><font color='#000066' face='Arial' size='2'>$Fax</font></td>        </tr>        <tr>          <td width='50%'><font color='#000066' face='Arial' size='2'>Neem hierover zo snel mogelijk contact met mij op:</font></td>          <td width='50%'><font color='#000066' face='Arial' size='2'>$ContactGewenst</font></td>        </tr>      </table>";if(!isset($stuurop)) {    echo($body);    echo("        <p align='center'><font color='#000066' face='Arial' size='2'><b>Zijn de gegevens correct ?</b></font><br>        <form action='$PHP_SELF' method='post'>            <input type='hidden' name='stuurop' value='1'>            <input type='submit' value='Ja'>            <input type='button' onclick='javascript:history.back(-1)' value='Nee'>        </form></p>        </center>    </body></html>    ");} else {    $body .= "</body>\n</html>";    $file = date("d-m-Y:s");    $file .= ".html";    $fp = fopen($file, "w");    fwrite($fp, "$body,");    fclose($fp);    echo($body);    include("verstuurd.htm");                    // Laat de laatste pagina zien}?>

Als ik die echo plaats voor de fopen dan is de body nog steeds leeg!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

doe je dan
code:
1
echo $body;

of
code:
1
echo "$body";

Zou me niets verbazen als het binnen quotes niet geparsed wordt, nl.

En als je $Bouwjaar gewoon output, doet die het wel?

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • Snow_King
  • Registratie: April 2001
  • Laatst online: 22:09

Snow_King

Konijn is stoer!

Topicstarter
Op dinsdag 11 juni 2002 18:12 schreef drm het volgende:
doe je dan
code:
1
echo $body;

of
code:
1
echo "$body";

Zou me niets verbazen als het binnen quotes niet geparsed wordt, nl.

En als je $Bouwjaar gewoon output, doet die het wel?
Nee das het vreemde, als je kijkt op http://www.kantoordenhollander.nl/formulieren/autoverzekering.html

dan zie je het script in werking..

ik echo via echo($body);

  • Skinny
  • Registratie: Januari 2000
  • Laatst online: 25-07 18:17

Skinny

DIRECT!

Maak van dit stukkie
PHP:
1
<?<form action='$PHP_SELF' method='post'><input type='hidden' name='stuurop' value='1'><input type='submit' value='Ja'>            <input type='button' onclick='javascript:history.back(-1)' value='Nee'>        </form>?>

eens
PHP:
1
<?<form action='$PHP_SELF' method='post'><input type='hidden' name='body' value='$body'><input type='hidden' name='stuurop' value='1'><input type='submit' value='Ja'>            <input type='button' onclick='javascript:history.back(-1)' value='Nee'>        </form>?>

Het is niet echt mooi om die hele BODY in een FORM mee te sturen, maar waar het om gaat is dat je dus bij het klikken op JA (van versturen) opnieuw die pagina laadt en dan ZONDER de variabelen van het formulier op de 1e (invul) pagina. Je moet of de $body, of alle aparte variabelen ook over het tweede <FORM> heen tillen..

Beetje snel uitgelegd, maar ik moet ff eten.

SIZE does matter.
"You're go at throttle up!"


  • Snow_King
  • Registratie: April 2001
  • Laatst online: 22:09

Snow_King

Konijn is stoer!

Topicstarter
Op dinsdag 11 juni 2002 18:30 schreef Skinny het volgende:
Maak van dit stukkie
PHP:
1
<?<form action='$PHP_SELF' method='post'><input type='hidden' name='stuurop' value='1'><input type='submit' value='Ja'>            <input type='button' onclick='javascript:history.back(-1)' value='Nee'>        </form>?>

eens
PHP:
1
<?<form action='$PHP_SELF' method='post'><input type='hidden' name='body' value='$body'><input type='hidden' name='stuurop' value='1'><input type='submit' value='Ja'>            <input type='button' onclick='javascript:history.back(-1)' value='Nee'>        </form>?>

Het is niet echt mooi om die hele BODY in een FORM mee te sturen, maar waar het om gaat is dat je dus bij het klikken op JA (van versturen) opnieuw die pagina laadt en dan ZONDER de variabelen van het formulier op de 1e (invul) pagina. Je moet of de $body, of alle aparte variabelen ook over het tweede <FORM> heen tillen..

Beetje snel uitgelegd, maar ik moet ff eten.
het klopt wat je zei, dat was het! tnx!
Pagina: 1