php-general Digest 14 Oct 2010 13:25:35 -0000 Issue 6987

Topics (messages 308687 through 308694):

floored by floor()
        308687 by: Mattias Thorslund
        308689 by: Thijs Lensselink
        308690 by: gaojian

Re: poll of 'public framework or roll your own'
        308688 by: Tommy Pham

searching for application like Google Doc
        308691 by: ФêÏ
        308694 by: Bob McConnell

Stuck in implementing PHP with HTML
        308692 by: vivek
        308693 by: Tommy Pham

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hi List,

I'm having a problem with the behavior of the floor() function:

echo floor(327.03 * 100)."\n"; //prints "32702" and not "32703"!!

Sanity check:
var_dump(327.03 * 100); //prints "float(32703)" as expected

Any ideas why this happens, and how to work around it?

Thanks,

Mattias


--- End Message ---
--- Begin Message ---
 On 10/14/2010 07:48 AM, Mattias Thorslund wrote:
Hi List,

I'm having a problem with the behavior of the floor() function:

echo floor(327.03 * 100)."\n"; //prints "32702" and not "32703"!!

Sanity check:
var_dump(327.03 * 100); //prints "float(32703)" as expected

Any ideas why this happens, and how to work around it?

Thanks,

Mattias



Read the floating point precision part

http://nl2.php.net/float

Use round() before you use floor() to get the expected result.


--- End Message ---
--- Begin Message ---
在 2010-10-13三的 22:48 -0700,Mattias Thorslund写道:
> Hi List,
> 
> I'm having a problem with the behavior of the floor() function:
> 
> echo floor(327.03 * 100)."\n"; //prints "32702" and not "32703"!!
> 
> Sanity check:
> var_dump(327.03 * 100); //prints "float(32703)" as expected
> 
> Any ideas why this happens, and how to work around it?
> 
> Thanks,
> 
> Mattias
> 
> 

i think u should read the manual about int and float:

http://www.php.net/manual/en/language.types.integer.php

http://www.php.net/manual/en/language.types.float.php#warn.float-precision


jim



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Steve Staples [mailto:sstap...@mnsi.net]
> Sent: Wednesday, October 13, 2010 5:29 AM
> To: php-general
> Subject: RE: [PHP] poll of 'public framework or roll your own'
> 
> I must have missed this poll.... but let me chime in (you've prolly already
> stopped reading now... :P )
> 
> 
> to make a long story short, i use a custom variant that started life as
> cakephp.  well, not even anywhere close.   I started to comprehend how
> cakephp started/configured itself, and then wrote my own, and reduced a
> lot of the "extra" stuff it did that I didn't need.
> 
> So, what I use is my own custom "switchboard/index" file, that does my
> magic, and then utilizes:
> smarty templates
> pchart (for graphs)
> fpdf (for pdf generation)
> pear mdb2
> pear mailer (or sometimes phpmailer)
> jquery
> 
> that is about all I use for every site i develop now.  I am still fine tuning 
> my
> classes/functions so that everything is more manageable and stream lined.
> my custom "switchboard/index" uses mod-rewrites, and does prolly a lot
> more than it needs to do, but i find it works quite nicely.
> 
> -Steve

Hi,

I was just a bit curious since the project I recently started is huge and 
highly modular with the modules communicating to each other.  I was looking 
into some MVC frameworks - Zend.com, phpro.org, PureMVC.org -  to help speed up 
the project and its future expandability.   After perusing some of the codes, 
Zend seems a bit bloated for me even though it already has a lot of good 
features built-in and doesn't seem to support modules and the 
inter-communcation.  Phpro is very straight forward and very light while it 
doesn't seem to be able to support a highly sophisticated application with a 
lot of modules and the communication between them.  PureMVC concept is awesome 
but there isn't an official release to support multiple modules (or cores) and 
their inter-communication.  So I ported the standard to multicore but still 
need to see how the modules inter-communication work.  I guess I'll have to dig 
up some more on the net for examples of the multicore.  I haven't yet looked at 
the other frameworks, such as CakePHP, symfony, etc.  Another plus to PureMVC 
is that it is language agnostic design, which I can later easily port my 
application to another language should the need arise.

Thanks,
Tommy


--- End Message ---
--- Begin Message ---
Is there any application like Google Doc(here I mean the spreadsheet).

thanks

--- End Message ---
--- Begin Message ---
From: ?? 

> Is there any application like Google Doc(here I mean the spreadsheet).

What is your conception of "like"?

Have you looked at OpenOffice?

Bob McConnell

--- End Message ---
--- Begin Message ---
Hi All,

Hi i am a newbie in PHP environment.

First of all my sincere regards to all behind developing this fabulous
language & of-course to every one who are sharing their knowledge & views
making others comfortable with the same.
Coming to the point i am trying to create a contact form applying server
side validation for my site using PHP. Here the problem had arises.
I have designed a from & applied validation referring the tutorials
available on web but unfortunately it is not working.
I am applying the validation & trying to show the error in the same field if
there
Here i am sending you the code snippet what i am trying to do. Your help is
highly appreciable. kindly help me out.

*form.php:-*
<body>
    <?php
        $required =
array("name"=>"Name","number"=>"Number","email"=>"Email","detail"=>"Comment");
        foreach($required as $field => $label){
            if(!$_POST[$field]){
                $warnings[$field] = "Required";
            }
            if($_POST["email"] && !eregi
("^[_a-z0-9-]+(\.[_a-z0-9-]+)*...@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$_POST["email"]))
            $warnings["email"] = "Invalid Email Format";

            if($_POST["number"] && !eregi ("^[0-9]{10}$",$_POST["number"]))
            $warnings["number"] = "Invalid number Format";

            if(count($warnings)>0){
    ?>
    <!-- start form-->
<div class="post">
                <h2 class="title-credit">Contact Form:-</h2>
                <div class="entry" style="padding-left:30px;">
                    <form name="feedback" method="post" action="submit.php">
                        <p><div style="padding:3px;">Name <span
style="margin-left:20px"><input name="name" type="text" id="name" size="40"
<?php if($$warnings["name"]) echo 'style=\"shaded\"';?> value="<?php echo
$_POST["name"];?>"><?php echo $warnings["name"];?>></span></div>
                        <div style="padding:3px;">Number <span
style="margin-left:10px"><input name="number" type="text" id="number"
size="40" <?php if($$warnings["number"]) echo 'style=\"shaded\"';?>
value="<?php echo $_POST["number"];?>"><?php echo
$warnings["number"];?></span></div>
                        <div style="padding:3px;">Email <span
style="margin-left:22px"><input name="email" type="text" id="email"
size="40" <?php if($$warnings["email"]) echo 'style=\"shaded\"';?>
value="<?php echo $_POST["email"];?>"><?php echo
$warnings["email"];?></span></div>
                        <div style="padding:3px;">Comment <span
style="margin-left:0px"><textarea name="detail" cols="50" rows="4"
id="detail" <?php if($$warnings["detail"]) echo 'style=\"shaded\"';?>
value="<?php echo $_POST["detail"];?>"></textarea><?php echo
$warnings["detail"];?></span></div>
                        <div style="padding:3px; padding-left:150px;"><input
type="submit" name="Submit" value="Submit">
                        <input type="reset" name="Reset"
value="Reset"></div></p>
                    </form>
                    <?php
                    }
                    else{
                        echo "Thanks for valuable comments";
                    }
                    ?>
</body>

*submit.php*
<?
$con=mysql_connect("localhost","test","test1234") or die
(mysql_errno().":<b> ".mysql_error()."</b>");
mysql_select_db("dbname",$con) or die (mysql_errno().":<b>
".mysql_error()."</b>");

$insert_query = 'insert into GUESTBOOK (NAME,NUMBER,EMAIL,DETAIL) values(
                    "' . $_POST['name'] . '",
                    "' . $_POST['number'] . '",
                    "' . $_POST['email'] . '",
                    "' . $_POST['detail'] . '"
                    )';
mysql_query($insert_query) or die ('Error updating database');
mysql_close($con);
?>
header('Location: http://www.sweetsamaira.com/guest.php');

Kindly help me out. Thanks in advance.


-- 
Kind Regards,
Vivek Jadiya

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: vivek [mailto:er.jadiyavi...@gmail.com]
> Sent: Thursday, October 14, 2010 2:26 AM
> To: php-gene...@lists.php.net
> Subject: [PHP] Stuck in implementing PHP with HTML
> 
> Hi All,
> 
> Hi i am a newbie in PHP environment.
> 
> First of all my sincere regards to all behind developing this fabulous
> language & of-course to every one who are sharing their knowledge & views
> making others comfortable with the same.
> Coming to the point i am trying to create a contact form applying server
side
> validation for my site using PHP. Here the problem had arises.
> I have designed a from & applied validation referring the tutorials
available
> on web but unfortunately it is not working.
> I am applying the validation & trying to show the error in the same field
if
> there Here i am sending you the code snippet what i am trying to do. Your
> help is highly appreciable. kindly help me out.
> 
> *form.php:-*
> <body>
>     <?php
>         $required =
> array("name"=>"Name","number"=>"Number","email"=>"Email","detail"=>
> "Comment");
>         foreach($required as $field => $label){
>             if(!$_POST[$field]){
>                 $warnings[$field] = "Required";
>             }
>             if($_POST["email"] && !eregi
> ("^[_a-z0-9-]+(\.[_a-z0-9-]+)*...@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-
> z]{2,3})$",$_POST["email"]))
>             $warnings["email"] = "Invalid Email Format";
> 
>             if($_POST["number"] && !eregi
("^[0-9]{10}$",$_POST["number"]))
>             $warnings["number"] = "Invalid number Format";
> 
>             if(count($warnings)>0){
>     ?>
>     <!-- start form-->
> <div class="post">
>                 <h2 class="title-credit">Contact Form:-</h2>
>                 <div class="entry" style="padding-left:30px;">
>                     <form name="feedback" method="post"
action="submit.php">

Here is your problem... The form is submitting to submit.php while your
validation is done in form.php.  What you should do is have the form submit
TO form.php.  If validation passes, redirect via header() [1].  You might
have to use session [2] to have the value accessible in submit.php for
security reasons.

>                         <p><div style="padding:3px;">Name <span
style="margin-
> left:20px"><input name="name" type="text" id="name" size="40"
> <?php if($$warnings["name"]) echo 'style=\"shaded\"';?> value="<?php
> echo $_POST["name"];?>"><?php echo
> $warnings["name"];?>></span></div>
>                         <div style="padding:3px;">Number <span
style="margin-
> left:10px"><input name="number" type="text" id="number"
> size="40" <?php if($$warnings["number"]) echo 'style=\"shaded\"';?>
> value="<?php echo $_POST["number"];?>"><?php echo
> $warnings["number"];?></span></div>
>                         <div style="padding:3px;">Email <span
style="margin-
> left:22px"><input name="email" type="text" id="email"
> size="40" <?php if($$warnings["email"]) echo 'style=\"shaded\"';?>
> value="<?php echo $_POST["email"];?>"><?php echo
> $warnings["email"];?></span></div>
>                         <div style="padding:3px;">Comment <span
style="margin-
> left:0px"><textarea name="detail" cols="50" rows="4"
> id="detail" <?php if($$warnings["detail"]) echo 'style=\"shaded\"';?>
> value="<?php echo $_POST["detail"];?>"></textarea><?php echo
> $warnings["detail"];?></span></div>
>                         <div style="padding:3px;
padding-left:150px;"><input
> type="submit" name="Submit" value="Submit">
>                         <input type="reset" name="Reset"
> value="Reset"></div></p>
>                     </form>
>                     <?php
>                     }
>                     else{
>                         echo "Thanks for valuable comments";
>                     }
>                     ?>
> </body>
> 
> *submit.php*
> <?
> $con=mysql_connect("localhost","test","test1234") or die
> (mysql_errno().":<b> ".mysql_error()."</b>");
> mysql_select_db("dbname",$con) or die (mysql_errno().":<b>
> ".mysql_error()."</b>");
> 
> $insert_query = 'insert into GUESTBOOK (NAME,NUMBER,EMAIL,DETAIL)
> values(
>                     "' . $_POST['name'] . '",
>                     "' . $_POST['number'] . '",
>                     "' . $_POST['email'] . '",
>                     "' . $_POST['detail'] . '"
>                     )';

In submit.php, the values should be retrieved from $_SESSION.  Also, this is
very bad to SQL injection.  Look into escaping the input [3].  I suggest you
to use mysqli extension, if you can, over mysql extension.  There many
benefits to it.

> mysql_query($insert_query) or die ('Error updating database');
> mysql_close($con); ?>
> header('Location: http://www.sweetsamaira.com/guest.php');
> 
> Kindly help me out. Thanks in advance.
> 
> 
> --
> Kind Regards,
> Vivek Jadiya

Regards,
Tommy

[1] http://php.net/manual/en/function.header.php
[2] http://www.php.net/manual/en/book.session.php
[3] http://us2.php.net/manual/en/function.mysql-real-escape-string.php



--- End Message ---

Reply via email to