php-general Digest 10 Jun 2006 09:22:28 -0000 Issue 4177

Topics (messages 237711 through 237732):

Re: Skip first 4 array values
        237711 by: Richard Lynch

Re: substring with numric values
        237712 by: Richard Lynch

Re: mail() function dying half way through.
        237713 by: Richard Lynch

Re: transfer file
        237714 by: Richard Lynch

Re: remove last comma in string
        237715 by: Richard Lynch
        237717 by: Paul Novitski
        237719 by: Richard Lynch

Re: order of elements in $_POST super global
        237716 by: Richard Lynch
        237718 by: Richard Lynch
        237720 by: Richard Lynch

Re: server sending notifications to clients
        237721 by: Richard Lynch

Re: running php method in the background
        237722 by: Richard Lynch

Using php4 to manage Apache 1.3 access database
        237723 by: Doug Carter

Re: Session puzzle... / why no new session?
        237724 by: chris smith

Re: Tables vs. databases
        237725 by: chris smith
        237729 by: Lester Caine

How to re-order an array
        237726 by: jekillen

How to tell if a socket is connected
        237727 by: Michael W.

Mail sending program (beginner)
        237728 by: aci india
        237730 by: Rabin Vincent
        237731 by: benifactor

1,600,000 ÃÒª×èÍÍÕàÁÅì ¤Ñ´ÊÃÃàÃÕ§ÅӴѺÍÑ¡ÉÃÊдǡÊÓËÃѺ¢ÂÒ¸ØáԨ¢Í§·èÒ¹ 
¾ÃéÍÁ·Ñé§á¶Áâ»Ãá¡ÃÁ·Ñ¹ÊÁѨҡµèÒ§»ÃÐà·ÈÍÕ¡ËÅÒÂÍÂèÒ§ ÃÒ¤Ò¶Ù¡ÁÒ¡ËÒäÁèä´éÍÕ¡áÅéÇ 
¨Ó˹èÒ¨ӹǹ¨Ó¡Ñ´
        237732 by: 1,600,000 ÃÒª×èÍÍÕàÁÅì 
¤Ñ´ÊÃÃàÃÕ§ÅӴѺÍÑ¡ÉÃÊдǡÊÓËÃѺ¢ÂÒ¸ØáԨ¢Í§·èÒ¹ 
¾ÃéÍÁ·Ñé§á¶Áâ»Ãá¡ÃÁ·Ñ¹ÊÁѨҡµèÒ§»ÃÐà·ÈÍÕ¡ËÅÒÂÍÂèÒ§ ÃÒ¤Ò¶Ù¡ÁÒ¡ËÒäÁèä´éÍÕ¡áÅéÇ 
¨Ó˹èÒ¨ӹǹ¨Ó¡Ñ´

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

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


----------------------------------------------------------------------
--- Begin Message ---
> Jonas Rosling wrote:
>
>>Is there any way you can skip for example the first 4 array
>> values/posisions
>>in an array no matter how many values it contains?

http://php.net/array_slice


-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---

$int = (int) $value;

On Fri, June 9, 2006 2:51 am, Jonas Rosling wrote:
> Is there any easy way to "trim" or pick out the none decimal values in
> a
> numric value? Like:
>
> 1,333 = 1
> 5,667 = 5
> 12,145 = 12
> 15,997 = 15
>
> Thanks // Jonas
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, June 9, 2006 12:59 am, Dave M G wrote:
> I have a database of about 120 users. Each weak I send out a
> newsletter.
> So far as I know, it's been working fine for the last couple of years.
>
> Then recently some users emailed me to let me know that they haven't
> been receiving all the messages. I added extra output to my script to
> echo out the name of each member that got an email sent to them, and I
> can now see that only about 50 of them are getting the email.
>
> The only think that has changed that I can think of is that I've
> upgraded to MySQL 5.0. However, given the type of problem I'm having,
> I
> don't think it's a MySQL problem, it appears much more likely to be a
> problem with my PHP code.
>
> This is the script that sends out the message (edited slightly to take
> out irrelevant bits of newsletter content):
>
> - - - -
> $count = 0;
> while ( $member = mysql_fetch_row($result) )
> {
> set_time_limit(0);
> $subject = "Newsletter subject line";
> $mailcontent = "This message was sent to " . $member[0] . " at
> {$member[1]}
> Blah, blah, blah - newsletter content goes here.";
> mail($member[1], $subject, $mailcontent, $fromaddress);

mail() returns a value to indicate if it failed/succeeded in queueing
up the email.

Check it.

Also, every call to mail() fires up a sendmail process.

This is expensive.

maybe sleep(1) in between calls

or consider switching to SMTP

or sending ONE email with a Bcc...  Though that has a slightly higher
probability of being labeled as spam.

> $count++;
> echo "<p>Newsletter sent to " .  $member[0] . " at " . $member[1] .
> "</p>";
> }
> echo "<p>A total of " .$count ." emails were sent out.</p>\n";
> - - - -
>
> The script actually dies before it gets to the last echo which echoes
> the value of $count. It outputs about 50 lines of "Newsletter sent to
> usersname at [EMAIL PROTECTED]" and then the cursor is stuck in hourglass
> mode and the browser is continually waiting a response. It stays like
> that indefinitely, and the only way it stops is if I go to another
> page
> or shut down the browser.
>
> I have heard that the mail() function does have limitations on how
> many
> emails it sends out. But I thought it took hundreds, somewhere between
> 500 and a thousand, of individual emails before it would die. And I
> also
> thought the set_time_limit(0) function would alleviate the problem of
> timing out.
>
> Where have I gone wrong with this?
>
> Any advice would be greatly appreciated. Thank you for taking the time
> to read this.
>
> --
> Dave M G
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Thu, June 8, 2006 10:16 pm, kristianto adi widiatmoko wrote:
> can php do transfer file betwen 2 server without using ftp function
> socket that use ftp port

If you want to re-write all the FTP stuff in PHP, with
http://php.net/fsockopen and fgets and fputs, sure, you could do
that...

Kinda silly to re-invent the wheel, but you could.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
You're missing an = for the city.

substr() should have worked.

rtrim() won't work, as ',' is not whitespace.

On Thu, June 8, 2006 7:58 pm, weetat wrote:
> Hi all,
>
>   I am using php 4.3.2 and mysql , linux.
>
>   I have a sql statement below :
>
>      UPDATE tbl_chassis_temp SET  country = 'Singapore',  city
> 'SINGAPORE',  building = 'Tampines Central 6',  other = 'Level 03-40',
>
>
> I need to remove the last comma from sql text above.
> I have tried using substr and rtrim , without any success ?
> Anyone have any suggestion ?
>
> THanks
> - weetat
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---

weetat wrote:
 I have a sql statement below :
UPDATE tbl_chassis_temp SET country = 'Singapore', city 'SINGAPORE', building = 'Tampines Central 6', other = 'Level 03-40',
I need to remove the last comma from sql text above.
I have tried using substr and rtrim , without any success ?


At 06:10 PM 6/8/2006, Chris wrote:
How about:

$query = substr(trim($query), 0, -1);

This feels like a hack to me -- it acts blindly, assuming that just the comma and no extra spaces are at the end of the string. Better I think to intelligently remove just those characters one wishes to remove.


At 03:00 PM 6/9/2006, Richard Lynch wrote:

rtrim() won't work, as ',' is not whitespace.

Richard, you're wrong -- read the manual. All three functions trim(), ltrim(), and rtrim() allow you to append an optional list of characters to be trimmed:

http://php.net/trim
http://php.net/ltrim
http://php.net/rtrim

Regards,
Paul
--- End Message ---
--- Begin Message ---
On Fri, June 9, 2006 5:17 pm, Paul Novitski wrote:
>>rtrim() won't work, as ',' is not whitespace.
>
> Richard, you're wrong -- read the manual.  All three functions
> trim(), ltrim(), and rtrim() allow you to append an optional list of
> characters to be trimmed:
>
> http://php.net/trim
> http://php.net/ltrim
> http://php.net/rtrim

Yeah, those wacky PHP Devs keep adding features faster than I can
learn and remember 'em :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Thu, June 8, 2006 9:59 am, Ben Liu wrote:
> I'm using a form (method="POST") to collect 30 boolean values from the
> end user using a series of checkboxes in the form. The form is
> arranged in a table so that the 30 check boxes are not a long list but
> rather three columns (with related items columnized). The problem is
> when I iterate through the $_POST results:
>
> The order in which I wish to present the checkboxes to the end user is
> different than the order I want to have in the $_POST super global and
> subsequently when I dump that information out to a text file.

You CANNOT rely on the browser to send POST data in any particular
order, by the HTTP spec.

While it's true that ALL known browsers send them in the order they
appear in the HTML, they don't have to.

And, of course, if they ever change that, a zillion scripts will break...

Still, better safe than sorry.

> What would be the best way to solve this?

Since you want them in a particular order, use the KEY of the array to
order them:

<input type="checkbox" name="array[0]" /> I'm first.
<input type="checkbox" name="array[1]" /> I'm second.
<input type="checkbox" name="array[2]" /> I'm third.


> 1) Is there a way to present the checkboxes in a certain order, yet
> have the data transmitted into the $_POST super global in a different
> order?

Presentation order is all HTML.

> 2) Does it make more sense to process the $_POST super global array
> and reorder the items within the array?
>
> 3) Some other method?
>
> Thanks for any advice.
>
> - Ben
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, June 9, 2006 7:34 am, Ben Liu wrote:
> The basic problem is that the way a $_POST variable gets processed is
> in the order it is in on the original form.

This is an undocumented behaviour, almost for sure.

Your script shouldn't rely on it, even if a skillion other scripts do.
:-)

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
name="bool[0][careers]"

might do what you want...

it's really quite difficult to say without a concrete example...

On Thu, June 8, 2006 10:20 am, Ben Liu wrote:
> I probably should add some more details to my question:
>
> The names of the form checkboxes could be changed from ie:
> bool_careers, bool_speaking, bool_internship, etc. to a single array
> bool_questions[], for instance. The problem with that is that I am
> using the form checkbox names later to process related data.
> Specifically, I am building a user-input based query. So if the form
> checkbox names are the same as the names of the variables in the
> database, it makes for easy creating of the query, since the names
> become associative keys in the $_POST array. I iterate through the
> $_POST array, checking each for true/false state. If the checkbox is
> checked, I add the associative key name to the query. Eliminating the
> checkbox names in favor of a numerical key only would make this more
> complicated.
>
> - Ben
>
> On 6/8/06, Barry <[EMAIL PROTECTED]> wrote:
>
>> 1. Use Keys in your form like a[1],a[2]
>> 2. order the array by usort (alphabetically or whatever u prefer)
>>
>> that way => 2: yes it is.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Thu, June 8, 2006 9:24 am, kartikay malhotra wrote:
> Is there a way for the server to notify the client about an event,
> provided
> the client was online in the past X minutes?
>
> To elaborate:
>
> A client comes online. A script PHP executes (serves the client), and
> terminates. Now if a new event occurs, how can the server notify the
> client
> about that event?

Keep a table of "notifications" and what time they happened, and if
the user has seen them -- perhaps even allowing the user to choose
which ones to dismiss, perhaps even only having a little icon about
notifications if there are any...

When the users hits a page, check the notifications table for things
they ought to know about.

The exact rules of how/when to do what is up to you and your users,
but give it a lot of thought before you go annoying the [bleep] out of
users with a damn popup for each notification stacked up or
something... :-)

This takes a lot more thought about WHAT to do from a
process/user-interface side than HOW to code it in PHP.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Thu, June 8, 2006 9:10 am, Nic Appleby wrote:
> I have a php web script which communicates with a server using
> sockets.
> There is a method in which the client listens for messages from the
> server, and this blocks the client.
> I need a way to 'fork' a process or to get this method to run in the
> background so that i can process user input while not interrupting the
> protocol.
>
> I have searched all over the web with no luck, can anyone point me in
> the right direction?

http://php.net/fsockopen and friends discuss the non-blocking aspect.
http://php.net/fork covers fork.

You can't use fork (or any pcntl) in a web-server environment, only CLI

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
I'm trying to make a web page to maintain my Apache authorization
file with instead of dbmmanage.

Since I have to have php loaded for other reasons I started
there.  Problem seems to be that the OpenBSD package and port
systems only seem to gdbm for php-4 and gdbm is not
supported by Apache 1.3 (gdbm does seem to be supported for
Apache 2 but that is not an option for me). Sort of a catch 22.

Is this correct or am I more likely
malforming the gdbm database or something else?

Context is:
 OpenBSD 3.9 with default chrooted Apache 1.3
 db-4.2.52p8
 gdbm-1.8.3p0
 php4-core-4.4.1p0
 php4-dba-4.4.1p0

Ruby 1.8 supports DB files but I don't really want to move all
the Ruby stuff to /var/www/ (required for the chrooted Apache
install).

Any suggestions?

Thanks,
--
Doug Carter

--- End Message ---
--- Begin Message ---
On 6/10/06, Ryan A <[EMAIL PROTECTED]> wrote:
Hi,

I am working on a very simple script, basically adding
features to an older script, I'll write down the main
parts:


<?php
ini_set('session.name', 'COSTREAM_SESSION');
session_start();

## authenticate user code comes here

## log the user
my_log("login",$user,$_REQUEST['COSTREAM_SESSION']);

?>

and for logout.php I have:
-----
ini_set('session.name', 'COSTREAM_SESSION');
session_start();
unset($_SESSION['user']);
session_destroy();
-- redirect user comes here
-----

but when I check the DB the session id is always the
same hash, I should be getting new hashes everytime I
login right? I am running the logout script before
logging in again...why is it always giving me the same
hash?

If you're logging straight back in after logging out, maybe not - the
browser might remember the old session. If you log out, close the
browser then go to the login page you should get a new id. If you want
to guarantee a new id, use http://php.net/session_regenerate_id

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
On 6/10/06, Antonio Bassinger <[EMAIL PROTECTED]> wrote:
Hi gang,

Situation:

I've a HTTP server. I intend to run a file upload service. There could be up
to 10000 subscribers. Each saving files up to 10 MB.

I made a proof-of-concept service using PHP & MySQL, where there is a single
database, but many tables - a unique table for each subscriber. But I
realize that I may land in trouble with such a huge database. Would it be
better to have a separate database for each subscriber?

On top of the replies you already have you should read these pages:

http://arjen-lentz.livejournal.com/66547.html
http://bobfield.blogspot.com/2006/03/million-tables.html

Though you're not talking about those sort of numbers, you need to be
aware of those limitations (there were more posts on planetmysql.org
about this but I can't find the original page).

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Antonio Bassinger wrote:

I've a HTTP server. I intend to run a file upload service. There could be up
to 10000 subscribers. Each saving files up to 10 MB.

I made a proof-of-concept service using PHP & MySQL, where there is a single
database, but many tables - a unique table for each subscriber. But I
realize that I may land in trouble with such a huge database. Would it be
better to have a separate database for each subscriber?

Which approach is better, many tables in 1 database, or many databases with
1 or max 2 tables?

Kindly suggest with pros and cons of each.

Take a look at bitweaver
www.bitweaver.org
Fully operational user management and file upload with management that allows it to be fully scalable.
It will give you some practical examples at least ;)

--
Lester Caine - G8HFL
-----------------------------
L.S.Caine Electronic Services - http://home.lsces.co.uk
Model Engineers Digital Workshop - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/
Treasurer - Firebird Foundation Inc. - http://www.firebirdsql.org/index.php

--- End Message ---
--- Begin Message ---
Hello;
i'm scratching my head with a difficulty.
The situation is this.
A script begins with one indexed array (not associative) and one other indexed array
with the same values in a different order, the final order.
I want to create an interim array and progressively re order the array until it matches slot for slot one of the original arrays. At this point the script is considered completed. One important factor is that I'm looking to write this in javascript and the interim
array will be altered by the actions of a web page user.
Why am I asking the php list? Because I have a better chance of getting an answer here. I'm not looking for help with javascript, specifically, just how one would go about this task. Answer with php code and some theory if you wish and I will try to translate
it into javascript.
Some javascript functions I might use aren't supported in all the browsers that will
potentially run the script.
I might resort to using Ajax and let php keep track for me. But, then again not all
browsers will do the Ajax either (as I understand it).
Thanks in advance
JK

--- End Message ---
--- Begin Message ---
Hello,
  Can any of you tell me how to tell whether a socket (from fsockopen()) is
connected or not? Specifically, whether the remote server has closed the
connection? Stream_get_meta_data() does not do it; in my tests, its output
does not change even when the server closes the stream.

Thank you,
Michael W.

--- End Message ---
--- Begin Message ---
Dear group,

Description:

Following is the code which I tried for learning propuses. It is a mail
sending program

which checks weather the user enters a correct mail id If he enters the
correct mail ID then

user name and e-mail will get stored in the mysql data base table. After
getting stored

then mail will sent to the user as a accknoledg process. For the propus of
mail subject

and mail body, I have created two external files.

The problem:

Filling the rows and col in the data base is no problem at all. The value
getting stored.

But after clicking the button for accknoledg the browser takes lot of time
in execution. I doubt

with either the file handling functions or infinit loop. Or Am I missing
somthing basic? Pls mention if you faced a similear situation with file
handling and infinit loop. Thanks.



NOTE: Sorry for the very long code

============================== the code=====================================

The html file:

^^^^^^^^^^^^

<HTML>

<body>

<form method="post" name="my_frm" action="mail.php">

<TABLE align ="center">

<tr>

<td>

Name:

</td>

<td>

<input id="text" name="user_name">

</td>

</tr>

<tr>

<td>

E-mail:

</td>

<td>

<input id="text" name="user_email">

</td>

</tr>

</TABLE>

<table align = "center">

<tr>

<td>

<input type="submit" name="click_btn" value="yes,I want my 'CMS' NewsLetter
NOW!" align=middle onClick="validt()">

</td>

</tr>

</table>

<table align="center">

<tr>

<td>

<a href="test.html"><font size=2>Or click here to see how you can learn
everything

<br>

you need to know about CMS without signing up for our free newsletter
</font>

</a>

</td>

</tr>

</table>

<script language="javascript">

function validt()

{

var str= document.my_frm.user_email.value;

var name = document.my_frm.user_name.value;

if(str.indexOf("@") <0 || str.indexOf(".") < 0)

{

my_error()

}

else

alert("thanks for entering valid e-mail");

}

function my_error()

{

alert("pls enter a correct e-mail ID");

document.my_frm.user_email.value = " ";

}

</script>

</form>







</body>

</HTML>

the mail.php file:

^^^^^^^^^^^^^^^

<?php

/*mail body file*/

function cnd($fname)

{

$fil = fopen($fname,"r");

if(!$fil)

die("fopen error");

while(!feof($fil))

$buffer = fgets($fil);

while($buffer != NULL)

{

if($buffer == "\n.") /*a line should not start with .*/

$buffer = str_replace("\n.","\n..", $buffer);

if($buffer == "\n" && $buffer > 70) /*should be less than 70*/

$buffer = '\n';

}

fclose($fil);

return $buffer;

}

/*mail sub file*/

function sub($fname)

{

$fil = fopen($fname,"r");

if(!$fil)

die("fopen err in sub file");

while(!feof($fil))

$buff = fgets($fil);

while($buff != NULL)

{

if($buff > 15)

{

?>

<script language="javascript">

alert("the subject line should not be less than 15, pls check the sub.txtfile");

</script>

<?php

}

}

fclose($fil);

return $buff;

}

function fetch_names()

{

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$result = mysql_query("select name from users",$var) or die("unable to fetch
rows");

$rows = mysql_fetch_array($result);

while($rows)

{

for($i=0; $i<= $rows ; $i++)

for($j=0;$j <= i-1 ; $j++)

$names[$i] = $rows[$j];

}

return $names;

}

function fetch_emails()

{

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$result = mysql_query("select email from users",$var) or die("unable to
fetch rows");

$rows = mysql_fetch_array($result);

while($rows)

{

for($i=0; $i<= $rows ; $i++)

for($j=0;$j <= i-1 ; $j++)

$email[$i] = $rows[$j];

}

return $email;

}

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$name = $_POST['user_name'];

$mail = $_POST['user_email'];

$db_q = mysql_query("insert into users values('$name','$mail')");

if(!$db_q)

die("mysql error");

$condt = cnd("cond.txt");

$sub = sub ("sub.txt");

$name = fetch_names();

$email = fetch_emails();

$mail_stat = mail($email,$sub,$condt,"from:[EMAIL PROTECTED]");

if($mail_stat == NULL)

echo "mail sent failed";

else

echo "mail sent sucess. Pls check for mail for further acction";

?>
==================code ends========================

sorry english is not my native language.

--- End Message ---
--- Begin Message ---
On 6/10/06, aci india <[EMAIL PROTECTED]> wrote:
NOTE: Sorry for the very long code

Please paste long code snippets in a website like
pastebin.com. Also, the code is hard to read because
of the complete lack of indentation.

I suggest you atleast attempt to debug your code before
posting it here. Sprinkle echo or var_dump statements
throughout your code and try to find out where the problem
is. Make liberal use of the documentation at php.net/manual.

I have placed some comments inline, and pointed
out your infinite loop.

the mail.php file:

^^^^^^^^^^^^^^^

<?php

/*mail body file*/

function cnd($fname)

{

$fil = fopen($fname,"r");

if(!$fil)

die("fopen error");

while(!feof($fil))

$buffer = fgets($fil);

while($buffer != NULL)

{

if($buffer == "\n.") /*a line should not start with .*/

What is this? You are checking if the whole string is
equal to "\n.", which I think will never happen.

You probably want $buffer{0} == '.'/

$buffer = str_replace("\n.","\n..", $buffer);

As above.

if($buffer == "\n" && $buffer > 70) /*should be less than 70*/

What is this supposed to be? You are checking if
the line is empty, and then checking if it is greater
than 70? And you probably mean strlen in the second
part of the if.

$buffer = '\n';

}

fclose($fil);

return $buffer;

}

/*mail sub file*/

function sub($fname)

{

$fil = fopen($fname,"r");

if(!$fil)

die("fopen err in sub file");

while(!feof($fil))

$buff = fgets($fil);

while($buff != NULL)

{

if($buff > 15)

strlen here too. Strings don't magically give out their
length.

{

?>

<script language="javascript">

alert("the subject line should not be less than 15, pls check the sub.txtfile");

</script>
<?php

}

}

fclose($fil);

return $buff;

}

function fetch_names()

{

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$result = mysql_query("select name from users",$var) or die("unable to fetch
rows");

$rows = mysql_fetch_array($result);

while($rows)

{

Here's your infinite loop. Review the docs on how to
iterate through returned rows. php.net/mysql_query.


for($i=0; $i<= $rows ; $i++)

for($j=0;$j <= i-1 ; $j++)

$names[$i] = $rows[$j];

}

return $names;

}

function fetch_emails()

{

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$result = mysql_query("select email from users",$var) or die("unable to
fetch rows");

$rows = mysql_fetch_array($result);

while($rows)

{

One more infinite loop.


for($i=0; $i<= $rows ; $i++)

for($j=0;$j <= i-1 ; $j++)

$email[$i] = $rows[$j];

}

return $email;

}

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$name = $_POST['user_name'];

$mail = $_POST['user_email'];

$db_q = mysql_query("insert into users values('$name','$mail')");

This is open to SQL injection attacts. See
php.net/mysql_real_escape_string and phpsec.org

if(!$db_q)

die("mysql error");

$condt = cnd("cond.txt");

$sub = sub ("sub.txt");

$name = fetch_names();

$email = fetch_emails();

$mail_stat = mail($email,$sub,$condt,"from:[EMAIL PROTECTED]");

if($mail_stat == NULL)

mail doesn't return NULL. php.net/mail.

echo "mail sent failed";

else

echo "mail sent sucess. Pls check for mail for further acction";

?>
==================code ends

Rabin

--- End Message ---
--- Begin Message ---
i don't really understand what your trying to do here but if im correct
there is a much easier way...

if you are trying to make a newletter sign up this is simple. there is no
reason to send the email to the database simply have the enter thier email
address, use regex to check it, if it passes that test, send it and a uniqe
conformation number to a database, and use mail() to send them the
conformation information with the link to the confirm page.  they then click
on the link to confirm.php or whatever and it will check the database for
that email or number... if they are both there and the both match it will
erase it from the confirm database and send the info to the newsletter
database. i will give you an example...

//start index.php or news_signup.php or something of the sort...
<?php
//first we define the function for the email check...

 function is_valid ($email) {

  if
(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)[EMAIL 
PROTECTED](\.[a-z0-9-]+)*(\.[a-z]{2,3})
$", $email)) {

  return true;

  }
 }
//check to see if the signup form button was pressed and perform tests on
the form data..

 if ($HTTP_POST_VARS[ADD_USER]) {
  if (!$HTTP_POST_VARS[email]) {
   $e = "error! you must enter your email address!";
  }
  else {
  if (!is_valid($HTTP_POST_VARS[email]) {
   $e = "error! your email address is invalid!";
  }
  else {
   //all the tests passed at this point, so we make that conf # i talked
about...
   $conf = uniqid("nuser");
   //now we eneter all the information in to a database called add that has
three feilds.. auto_increment id. email. confid.
   mysql_query("insert into add (id, email, confid) VALUES (null, '$email',
'$conf')");
   //now we send the email
   $to      = "$email";
   $subject = 'Your Newsletter subscription...';
   $message = "Hello $email, your registration is almost complete! all you
have to do now is confirm your registration. to do this simply click on this
link: <a
href=\"http://yoursite.com/newsletter/confirm.php?confid=$conf\";>Complete
Registration Now</a> or, copy and paste this into your web browser:
www.yoursite.com/newsletter/confirm.php?confid=$conf <br><br><b>Please Note:
your resgistration will expire in exactly 24 hours from when you clicked the
register button, so please confirm your registration now!</b>";
   $message = wordwrap($message);
   $headers = 'From: [EMAIL PROTECTED]' . "\r\n";
   $headers  .= 'MIME-Version: 1.0' . "\r\n";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   mail($to, $subject, $message, $headers);
   $e = "congratulations you have signed up! You should recieve an email
shortly to confirm.";

  }
  }
  }
  else {
  //now we actually display the form
?>

<form method="post" action="whateveryoucallit.php">
email:<br>
<input type="text" name="email" value="<?php echo("$email"); ?>"
length="35"><br>
<input type="submit" name="ADD_USER" value="SIGN UP!">
</form>

<?php
//now we wnd the orginal php block
}

//now we dipslay the error message if there was any...

if ($e) {
echo("$e");
}

?>

this is the whole first page. simple. not too many languages. now the
confirm page.


//start confirm.php or whatever.

<?php
//first we make sure they got to this page by email, making sure the
variable $conf is set
if (!$conf) {

 $e = ("Sorry, you must have an id in order to complete the registration...
please click on or copy and paste the link from your email into your web
browser.. thank you - staff");
}
//now we make sure that the confid is in the database
else {
$cc1 = mysql_query("SELECT * from add where confid = '$conf'") or
die(mysql_error());
$ccc1 = mysql_fetch_array($cc1);
if (!$ccc1) {
$e = ("Sorry, The id you have enterd does not match any of our records...you
may have already confirmed your email - staff");
}
//grab the data where the ids match and enter the in to the new database
else {
$query = mysql_query("select * from conf where confid = '$conf'");
while ($d = mysql_fetch_array($query)) {
$email = "$d[email]";
mysql_query("insert into users (id, email) VALUES (NULL, '$email')") or
die(mysql_error());
//delete from the conf database
mysql_query("delete from conf where conf = '$confid'") or
die(mysql_error());
$s = ("Congratulations <b>$email</b>, you have successfully signedup... you
will now get our monthly emails...");
}
}
}
}
if ($e) {
echo("<b><center>$e</b></center>");
}
if ($s) {
echo("<b><center>$s</b></center><br><b><center>$s1</b></center><br><center><
b>You will now be redirected to login...</b></center>");
}
?>

this is not perfect, but should give you an idea of what your doing and a
different way (possibly better) of doing this.

----- Original Message ----- 
From: "aci india" <[EMAIL PROTECTED]>
To: <php-general@lists.php.net>
Sent: Friday, June 09, 2006 10:24 PM
Subject: [PHP] Mail sending program (beginner)


> Dear group,
>
> Description:
>
> Following is the code which I tried for learning propuses. It is a mail
> sending program
>
> which checks weather the user enters a correct mail id If he enters the
> correct mail ID then
>
> user name and e-mail will get stored in the mysql data base table. After
> getting stored
>
> then mail will sent to the user as a accknoledg process. For the propus of
> mail subject
>
> and mail body, I have created two external files.
>
> The problem:
>
> Filling the rows and col in the data base is no problem at all. The value
> getting stored.
>
> But after clicking the button for accknoledg the browser takes lot of time
> in execution. I doubt
>
> with either the file handling functions or infinit loop. Or Am I missing
> somthing basic? Pls mention if you faced a similear situation with file
> handling and infinit loop. Thanks.
>
>
>
> NOTE: Sorry for the very long code
>
> ============================== the
code=====================================
>
> The html file:
>
> ^^^^^^^^^^^^
>
> <HTML>
>
> <body>
>
> <form method="post" name="my_frm" action="mail.php">
>
> <TABLE align ="center">
>
> <tr>
>
> <td>
>
> Name:
>
> </td>
>
> <td>
>
> <input id="text" name="user_name">
>
> </td>
>
> </tr>
>
> <tr>
>
> <td>
>
> E-mail:
>
> </td>
>
> <td>
>
> <input id="text" name="user_email">
>
> </td>
>
> </tr>
>
> </TABLE>
>
> <table align = "center">
>
> <tr>
>
> <td>
>
> <input type="submit" name="click_btn" value="yes,I want my 'CMS'
NewsLetter
> NOW!" align=middle onClick="validt()">
>
> </td>
>
> </tr>
>
> </table>
>
> <table align="center">
>
> <tr>
>
> <td>
>
> <a href="test.html"><font size=2>Or click here to see how you can learn
> everything
>
> <br>
>
> you need to know about CMS without signing up for our free newsletter
> </font>
>
> </a>
>
> </td>
>
> </tr>
>
> </table>
>
> <script language="javascript">
>
> function validt()
>
> {
>
> var str= document.my_frm.user_email.value;
>
> var name = document.my_frm.user_name.value;
>
> if(str.indexOf("@") <0 || str.indexOf(".") < 0)
>
> {
>
> my_error()
>
> }
>
> else
>
> alert("thanks for entering valid e-mail");
>
> }
>
> function my_error()
>
> {
>
> alert("pls enter a correct e-mail ID");
>
> document.my_frm.user_email.value = " ";
>
> }
>
> </script>
>
> </form>
>
>
>
>
>
>
>
> </body>
>
> </HTML>
>
> the mail.php file:
>
> ^^^^^^^^^^^^^^^
>
> <?php
>
> /*mail body file*/
>
> function cnd($fname)
>
> {
>
> $fil = fopen($fname,"r");
>
> if(!$fil)
>
> die("fopen error");
>
> while(!feof($fil))
>
> $buffer = fgets($fil);
>
> while($buffer != NULL)
>
> {
>
> if($buffer == "\n.") /*a line should not start with .*/
>
> $buffer = str_replace("\n.","\n..", $buffer);
>
> if($buffer == "\n" && $buffer > 70) /*should be less than 70*/
>
> $buffer = '\n';
>
> }
>
> fclose($fil);
>
> return $buffer;
>
> }
>
> /*mail sub file*/
>
> function sub($fname)
>
> {
>
> $fil = fopen($fname,"r");
>
> if(!$fil)
>
> die("fopen err in sub file");
>
> while(!feof($fil))
>
> $buff = fgets($fil);
>
> while($buff != NULL)
>
> {
>
> if($buff > 15)
>
> {
>
> ?>
>
> <script language="javascript">
>
> alert("the subject line should not be less than 15, pls check the
sub.txtfile");
>
> </script>
>
> <?php
>
> }
>
> }
>
> fclose($fil);
>
> return $buff;
>
> }
>
> function fetch_names()
>
> {
>
> $var = mysql_connect("localhost","root","");
>
> if(!$var)
>
> die("could not connect".mysql_error());
>
> $db = mysql_select_db("sathya_clon",$var);
>
> if(!$db)
>
> die("could not find the data base".mysql_error());
>
> $result = mysql_query("select name from users",$var) or die("unable to
fetch
> rows");
>
> $rows = mysql_fetch_array($result);
>
> while($rows)
>
> {
>
> for($i=0; $i<= $rows ; $i++)
>
> for($j=0;$j <= i-1 ; $j++)
>
> $names[$i] = $rows[$j];
>
> }
>
> return $names;
>
> }
>
> function fetch_emails()
>
> {
>
> $var = mysql_connect("localhost","root","");
>
> if(!$var)
>
> die("could not connect".mysql_error());
>
> $db = mysql_select_db("sathya_clon",$var);
>
> if(!$db)
>
> die("could not find the data base".mysql_error());
>
> $result = mysql_query("select email from users",$var) or die("unable to
> fetch rows");
>
> $rows = mysql_fetch_array($result);
>
> while($rows)
>
> {
>
> for($i=0; $i<= $rows ; $i++)
>
> for($j=0;$j <= i-1 ; $j++)
>
> $email[$i] = $rows[$j];
>
> }
>
> return $email;
>
> }
>
> $var = mysql_connect("localhost","root","");
>
> if(!$var)
>
> die("could not connect".mysql_error());
>
> $db = mysql_select_db("sathya_clon",$var);
>
> if(!$db)
>
> die("could not find the data base".mysql_error());
>
> $name = $_POST['user_name'];
>
> $mail = $_POST['user_email'];
>
> $db_q = mysql_query("insert into users values('$name','$mail')");
>
> if(!$db_q)
>
> die("mysql error");
>
> $condt = cnd("cond.txt");
>
> $sub = sub ("sub.txt");
>
> $name = fetch_names();
>
> $email = fetch_emails();
>
> $mail_stat = mail($email,$sub,$condt,"from:[EMAIL PROTECTED]");
>
> if($mail_stat == NULL)
>
> echo "mail sent failed";
>
> else
>
> echo "mail sent sucess. Pls check for mail for further acction";
>
> ?>
> ==================code ends========================
>
> sorry english is not my native language.
>

--- End Message ---
--- Begin Message ---
1,600,000 ÃÒª×èÍÍÕàÁÅì ¤Ñ´ÊÃÃàÃÕ§ÅӴѺÍÑ¡ÉÃÊдǡÊÓËÃѺ¢ÂÒ¸ØáԨ¢Í§·èÒ¹ 
¾ÃéÍÁ·Ñé§á¶Áâ»Ãá¡ÃÁ·Ñ¹ÊÁѨҡµèÒ§»ÃÐà·ÈÍÕ¡ËÅÒÂÍÂèÒ§ ÃÒ¤Ò¶Ù¡ÁÒ¡ËÒäÁèä´éÍÕ¡áÅéÇ 
¨Ó˹èÒ¨ӹǹ¨Ó¡Ñ´
µÔ´¨ÃÇ´ãËé¸ØáԨ¢Í§·èÒ¹´éÇ¡ÒûÃЪÒÊÑÁ¾Ñ¹¸ì¸ØáԨ·Ò§ÍÕàÁÅì 
â´Âµé¹·Ø¹·ÕèµèÓáÅмŵͺÃѺ·Õè´Õ·ÕèÊØ´
´éÇÂÍÕàÁÅì 1.6 ÅéÒ¹àÁÅì 
á¶Áâ»Ãá¡ÃÁ
- Êè§àÁÅì¤Ø³ÀÒ¾ÊÙ§¨Ò¡µèÒ§»ÃÐà·È µÑÇàµçÁãªé§Ò¹ä´éµÅÍ´ 
- â»Ãá¡ÃÁ´Ù´àÁÅì¤Ø³ÀÒ¾ÊÙ§¨Ò¡µèÒ§»ÃÐà·È µÑÇàµçÁãªé§Ò¹ä´éµÅÍ´ 
- µÑÇ¡ÃͧÍÕàÁÅì ¤Ø³ÀÒ¾ÊÙ§¨Ò¡µèÒ§»ÃÐà·È µÑÇàµçÁãªé§Ò¹ä´éµÅÍ´ 

ÇÔ¸Õ¡ÒèѴÊè§ÊÔ¹¤éÒ Êè§ EMS ·èÒ¹¨Ðä´éÃѺÊÔ¹¤éÒÀÒÂã¹ 1-2 Çѹ
ËÃ×Í ´ÒǹìâËÅ´ÀÒÂã¹ 1-2 ª.Á. ãªéä´éàÅÂ

ÃÒ¤Ò 790 ºÒ·
ʹã¨â·Ã 06-7815050
ÍÕàÁÅì  [EMAIL PROTECTED]

--- End Message ---

Reply via email to