Page 2 of 2

Posted: Mon Apr 21, 2003 7:17 pm
by volka
sorry, I meant it the other way round. Only keep the static part.
The next step is to format the html-code. really take care of it, there are some ..hmm... mistakes in your current output, e.g. there must not be more than one <body>-element in a an HTML-document.
  • no offense but this is how your php-script looks like now

    Code: Select all

    <?php
    echo "<script type="text/javascript">";
    mysql_connect("myhost", "user", "pass") or die("db failed");
    ?>	
    function doNothing()
    { return true; }
    </script><body><p>
    <?php
    $result = mysql_query("SELECT * FROM tbln");
    echo '<form action="test.php" method="POST">';
    while($row = mysql_fetch_array($result))
    	echo "<input type=text name=".$result[name]." value=".$result[val].">";
    ?>	
    <input type="button" value="click me" onClick="javascript:doNothing();" >	</form>
    </html>
  • removing everything that is not output-related (for now)

    Code: Select all

    <?php
    echo "<script type="text/javascript">";
    ?>   
    function doNothing()
    { return true; }
    </script><body><p>
    <?php
    echo '<form action="test.php" method="POST">';
    while($row = mysql_fetch_array($result))
       echo "<input type=text name=".$result[name]." value=".$result[val].">";
    ?>   
    <input type="button" value="click me" onClick="javascript:doNothing();" >   </form>
    </html>
  • moving all static echos

    Code: Select all

    <script type="text/javascript">
    function doNothing()
    { return true; }
    </script><body><p>
    <form action="test.php" method="POST">
    <?php
    while($row = mysql_fetch_array($result))
    	echo "<input type=text name=".$result[name]." value=".$result[val].">";
    ?>	
    <input type="button" value="click me" onClick="javascript:doNothing();" >	</form>
    </html>
  • replacing all remaining php-blocks by an html-comment, describing the result (output)

    Code: Select all

    &lt;script type="text/javascript"&gt;
    function doNothing()
    &#123; return true; &#125;
    &lt;/script&gt;&lt;body&gt;&lt;p&gt;
    &lt;form action="test.php" method="POST"&gt;
    &lt;!-- a while-loop adding an _input text_ element for each record fetched from database --&gt;
    &lt;input type="button" value="click me" onClick="javascript:doNothing();" &gt;	&lt;/form&gt;
    &lt;/html&gt;
  • re-formatting (step 1).
    for each opening tag I use one more tab, after each closing tag I use one tab less.

    Code: Select all

    &lt;script type="text/javascript"&gt;
    	function doNothing()
    	&#123; return true; &#125;
    &lt;/script&gt;
    &lt;body&gt;
    	&lt;p&gt;
    		&lt;form action="test.php" method="POST"&gt;
    			&lt;!-- a while-loop adding an _input text_ element for each record fetched from database --&gt;
    			&lt;input type="button" value="click me" onClick="javascript:doNothing();" &gt;
    				&lt;/form&gt;
    			&lt;/html&gt;
  • that doesn't look right, does it?

    Code: Select all

    &lt;html&gt;&lt;!-- there was a closing html-tag, but it was never opened --&gt;
    	&lt;script type="text/javascript"&gt;
    		function doNothing()
    		&#123; return true; &#125;
    	&lt;/script&gt;
    	&lt;body&gt;
    		&lt;p&gt;
    			&lt;form action="test.php" method="POST"&gt;
    				&lt;!-- a while-loop adding an _input text_ element for each record fetched from database --&gt;
    				&lt;input type="button" value="click me" onClick="javascript:doNothing();" /&gt;&lt;!-- immediate close --&gt;
    			&lt;/form&gt;
    		&lt;/p&gt;&lt;!-- p-element had not closing tag --&gt;
    	&lt;/body&gt;&lt;!-- body-element had not closing tag --&gt;
    &lt;/html&gt;
  • there are still some elements missing; common browser do not require all of them, but...

    Code: Select all

    &lt;html&gt;
       &lt;head&gt;
          &lt;title&gt;test&lt;/title&gt;
          &lt;script type="text/javascript"&gt;
             function doNothing()
             &#123;
                return true;
             &#125;
          &lt;/script&gt;
       &lt;/head&gt;
       &lt;body&gt;
          &lt;p&gt;
             &lt;!-- use html comments to describe php-blocks you have to remove here --&gt;
             &lt;!-- something like: --&gt;
             &lt;form action="test.php" method="POST"&gt;
                &lt;!-- a while-loop adding an _input text_ element for each record fetched from database --&gt;
                &lt;input type="button" value="click me" onClick="javascript:doNothing();" /&gt;
             &lt;/form&gt;
          &lt;/p&gt;
       &lt;/body&gt;
    &lt;/html&gt;
I'm under the impression that you do not understand the script and your knowledge on the basics ...err... needs a little refreshment ;)
So this is about stripping the php-code down to the wires, reassemble it and then finally re-code it in perl. This might take quite a while (esp. because I don't know how often I'm online in the next few days)
And yes, this is going to be (a bit) pedantic :twisted:
It's the best I can offer.

Posted: Tue Apr 22, 2003 3:53 am
by Nik
ii know some basic perl and php, but i dont knwo exactly why are you re-writing the html to php.... u want just pure php and then convert to perl??

anyways, what must i do know??

Posted: Tue Apr 22, 2003 4:01 am
by Nik
Well, cant we just code the whole file to perl, or to perl with some javascript inside it?? why do we have to use html??? I donw know, u know best but i beleive that is a very good idea to have all the file contents in just one language PERL. What do you think?

Posted: Tue Apr 22, 2003 7:57 am
by Nik
Well i have tries and make the code look like this:

Code: Select all

#!perl
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use DBI;
use DBD::mysql;

print header(), start_html( &#123;title => "Didaxes Patros Paisiou", background => "images/anemos.jpg"&#125; );

$db = DBI->connect("DBI:mysql:nik_db", &#123;RaiseError => 1&#125;) or
$db = DBI->connect("DBI:mysql:nik_db", "nik", "macgyver", &#123;RaiseError => 1&#125;);

$xronos = localtime;  $i=0;
#$host = gethostbyaddr($ENV&#123;'REMOTE_ADDR'&#125;, 2);

#foreach (@tainies)  &#123; print "<option> $_ </option>" &#125;;

print table( &#123;-border => 5, background => "images/blue.jpg"&#125;,
      Tr( th( &#1111; h3("Pos se lene file"),         textfield(&#123; -name => 'onoma'&#125;)  ] ) ),
      Tr( th( &#1111; h3("Poio einai to sxolio sou"), textfield(&#123; -name => 'sxolio'&#125;) ] ) ),
      Tr( th( &#1111; h3("Poio einai to e-mail sou"), textfield(&#123; -name => 'email'&#125;)  ] ) ) );
      br(), br();

open(IN, "diary.txt");
while (<IN>) &#123;
   push (@diary, $_);
&#125;

$quote=$diary&#1111;int(rand(@diary))];

print table( &#123;-border => 5, background => "images/blue.jpg"&#125;,
	  Tr( th( h4( $quote ) ) ) );
	  
print h2( $xronos );

$sql = "UPDATE counter SET visitor = visitor + 1";
$db->do( $sql );

$st = $db->prepare( "SELECT visitor FROM counter" );
$st->execute();

@visitor = $st->fetchrow_array();
print h2( $visitor&#1111;0] );

a( &#123;-href => "personal"&#125;, "img src=images/cross.gif" );
#mail ("nik0s\@mycosmos.gr", "Åðßóêåøç ÁôæÝíôáò $host => $visitor&#1111;0]", "", "From: 007\@spy.gr");
Why the background wont work?
how can i center text using perl?

how can i embed my javascript inside my perl file?? will it interpret it?

Once again i need your help!