php-general Digest 8 Jan 2005 22:10:53 -0000 Issue 3216
Topics (messages 205862 through 205887):
Using the OR operator in an IF statement
205862 by: Tim Burgan
205864 by: Greg Beaver
205865 by: Jason Wong
Re: Which script runs first?
205863 by: Rens Admiraal
205879 by: Rory Browne
205882 by: Curt Zirzow
Not about PHP, more about this list...
205866 by: gustav.varupiraten.se
Re: Pagination Optimization
205867 by: Bruno B B Magalh�es
205872 by: M. Sokolewicz
205878 by: Curt Zirzow
PHP Help
205868 by: TonyC
205871 by: tr
Re: Persistent PHP web application?
205869 by: Josh Whiting
205874 by: Lance Lovette
205877 by: Xuefer Tinys
205883 by: Rasmus Lerdorf
PHP any Mysql connection- new b
205870 by: babu
205873 by: M. Sokolewicz
Writing mulitple output lines to single line
205875 by: Robert M. Pufky
205880 by: Jason Wong
Re: Multiple POP accounts on Webmail Front
205876 by: JHollis
Re: PHP 5 confusion
205881 by: Curt Zirzow
Problem with MySQL
205884 by: Andrew Maxwell
205885 by: JHollis
"*** glibc detected *** double free or corruption:" error
205886 by: Alex Greg
Re: On large application organization [long and possibly boring]
205887 by: Josh Whiting
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:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hello,
Can someone please correct me on my efforts below.
If I have a condition where I want to test if a variable is not equal to
"student", "staff", or "admin".. what's the simplest was to achieve that?
Here's what I tried.. that didn't work:
<?php
if ( ($_POST['usertype'] != "student") || ($_POST['usertype'] !=
"staff") || ($_POST['usertype'] != "admin") )
{
// ...
}
?>
And also:
<?php
if ( ($_POST['usertype'] != "student" || "staff" || "admin" )
{
// ...
}
?>
I must be using the OR operator the wrong way. Can someone please
correct me on this.
Thanks very much for your time.
Regards
Tim Burgan
--- End Message ---
--- Begin Message ---
Tim Burgan wrote:
Hello,
Can someone please correct me on my efforts below.
If I have a condition where I want to test if a variable is not equal to
"student", "staff", or "admin".. what's the simplest was to achieve that?
Here's what I tried.. that didn't work:
<?php
if ( ($_POST['usertype'] != "student") || ($_POST['usertype'] !=
"staff") || ($_POST['usertype'] != "admin") )
{
// ...
}
?>
use && instead of ||
In english, you'd say "if the usertype is not student and not staff and
not admin, then we're OK." or "if the usertype is neither student, nor
staff, nor admin"
neither/nor is implemented using !=/&&
Greg
--- End Message ---
--- Begin Message ---
On Saturday 08 January 2005 19:02, Tim Burgan wrote:
> Can someone please correct me on my efforts below.
> If I have a condition where I want to test if a variable is not equal to
> "student", "staff", or "admin".. what's the simplest was to achieve that?
>
> Here's what I tried.. that didn't work:
>
> <?php
> if ( ($_POST['usertype'] != "student") || ($_POST['usertype'] !=
> "staff") || ($_POST['usertype'] != "admin") )
> {
> // ...
> }
> ?>
You need to use 'AND' (or '&&').
Or you can use in_array():
$usertype = array('student', 'staff', 'admin');
if (in_array($_POST['usertype'], $usertype)) {
// valid usertype;
} else {
// invalid usertype
}
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts
--- End Message ---
--- Begin Message ---
The way frames are loaded is actually dependent of many things I think
(size and browser e.g.), so, most secure is to use javascript, or, let
PHP check if the var is set, and if not, reload...
you can do this like this:
javascript:
left.php:
<body onload="parent.frames['targetframename'].location='page'"> // can
be a little different, but I think it is correct...
PHP method:
in main.php:
if (!isset ($_SESSION["var"])) header ("location:
{$_SERVER["PHP_SELF"]}"); // or something like this what will do the same...
[EMAIL PROTECTED] wrote:
Hi there!
I have two frames, one with left.php in the left frame and one with
main.php in the right frame.
I refresh the contents of main.hp at the end of left.php. (With help of
Javascript actually, maybe could be done with HEADER(...))
My Question:
Is it ALWAYS so that left.php must be executed before the right frame is
loaded? I wonder this because a session-variable are set in left.php that
main.php is dependent of. So this session-variable must be set before
main.php is loaded.
/G
@varupiraten.se
--- End Message ---
--- Begin Message ---
I don't know much about frames(I hate the things), but the only thing
I'd count on would be that the main frame will be loaded first. would
it be possible to load your session variables in this?
Another possibility would be to have the left frame do the loading of
variables, and have the frame on the right as "loading". Then when the
left frame has loaded the variables, you can use javascript( using
document.frames IIRC) to load the right page. This way you can be sure
that the left page is loaded before the right page, since it is the
left page that actually does do the loading of the right page. Your
page is kinda screwed though if a visitor turns off javascript, like I
do when I have the displeasure of having to use IE on Windows.
Apologies Rens if you recieved this twice. I forgot to CC it the first time.
On Sat, 08 Jan 2005 13:17:54 +0100, Rens Admiraal
<[EMAIL PROTECTED]> wrote:
> The way frames are loaded is actually dependent of many things I think
> (size and browser e.g.), so, most secure is to use javascript, or, let
> PHP check if the var is set, and if not, reload...
>
> you can do this like this:
>
> javascript:
> left.php:
> <body onload="parent.frames['targetframename'].location='page'"> // can
> be a little different, but I think it is correct...
>
> PHP method:
> in main.php:
> if (!isset ($_SESSION["var"])) header ("location:
> {$_SERVER["PHP_SELF"]}"); // or something like this what will do the same...
>
> [EMAIL PROTECTED] wrote:
>
> >Hi there!
> >
> >I have two frames, one with left.php in the left frame and one with
> >main.php in the right frame.
> >
> >I refresh the contents of main.hp at the end of left.php. (With help of
> >Javascript actually, maybe could be done with HEADER(...))
> >
> >My Question:
> >Is it ALWAYS so that left.php must be executed before the right frame is
> >loaded? I wonder this because a session-variable are set in left.php that
> >main.php is dependent of. So this session-variable must be set before
> >main.php is loaded.
> >
> >
> >/G
> >@varupiraten.se
> >
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
* Thus wrote [EMAIL PROTECTED]:
> Hi there!
>
> I have two frames, one with left.php in the left frame and one with
> main.php in the right frame.
>
> I refresh the contents of main.hp at the end of left.php. (With help of
> Javascript actually, maybe could be done with HEADER(...))
>
> My Question:
> Is it ALWAYS so that left.php must be executed before the right frame is
> loaded? I wonder this because a session-variable are set in left.php that
> main.php is dependent of. So this session-variable must be set before
> main.php is loaded.
Setup your session-variables in the script that defines the
frameset.
Curt
--
Quoth the Raven, "Nevermore."
--- End Message ---
--- Begin Message ---
Hi there!
I'm wondering. Why don't I see my own posts in the list? I have to guess
that the mail has arrived correctly to the list. I only see them when
someone has posted and replied on my questions...
/G
@varupiraten.se
--- End Message ---
--- Begin Message ---
Thanks for your help, in fact helped a lot... Now my function only
performs 2 queries, here it is:
=======================================
function fetch_paginated($query='',$page=1,$itens=20)
{
$this->query($query);
$total_rows = $this->num_rows();
if($total_rows > $itens)
{
$this->total_pages = ceil($total_rows/$itens);
$this->pages_before = ceil($page - 1);
$this->pages_after = ceil($this->total_pages - $page);
$this->query($query.' LIMIT
'.(($page*$itens)-$itens).','.$itens);
while($this->fetch_array())
{
$results[] = $this->row;
}
}
elseif($total_rows > 0)
{
while($this->fetch_array())
{
$results[] = $this->row;
}
$this->total_pages = '1';
$this->pages_before = '0';
$this->pages_after = '0';
}
else
{
return null;
}
return $results;
}
=======================================
Regards,
Bruno B B Magalh�es
On Jan 7, 2005, at 10:09 PM, M. Sokolewicz wrote:
first of all, you're running 4 queries here. 4 queries is a lot!
Especially when you don't need more than 2 ;)
the problem here is that your queries are pretty "unknown" to this
function. Although it does a nice result for that unknowing, there's a
few minor things that make it faster.
First of all, would be using less queries.
What I usually do is issue a query like this:
"SELECT count(some_unique_col) WHERE
(that_where_clause_youre_using_in_the_select_query)"
then, we do some math.
$pages_before = $page-1;
$rows_before = $pages_before*$itens;
$rows_after = $total_number_of_rows-($page*$itens);
$pages_after = ceil($rows_after/20);
Then do the actual selecting of the rows using the limit.
The thing that makes it slow in your example is the fact that 4 times
you're selecting ALL data from the relevant rows, and buffer it. You
buffer it, but don't use any of it, except for the number of rows.
Mysql does a far quicker job at this than PHP would, so use mysql. :)
Then, you're using 3 queries to determine the rows around the page;
even though, with a bit of simple math, you can calculate it. And
trust me on this, simple math is faster ;)
anyway, hope that helped.
--- End Message ---
--- Begin Message ---
and now a few small comments to your code ;)
Bruno B B Magalh�es wrote:
Thanks for your help, in fact helped a lot... Now my function only
performs 2 queries, here it is:
=======================================
function fetch_paginated($query='',$page=1,$itens=20)
{
$this->query($query);
$total_rows = $this->num_rows();
if($total_rows > $itens)
{
$this->total_pages = ceil($total_rows/$itens);
$this->pages_before = ceil($page - 1); // No need to ceil this!
// $page is an integer, meaning a full numer (like 1, 10, 125, -15,
etc.) ceiling the result is not useful, since the result is an integer
aswell.
$this->pages_after = ceil($this->total_pages - $page); // same thing here
// no need to ceil it.
$this->query($query.' LIMIT
'.(($page*$itens)-$itens).','.$itens);
while($this->fetch_array())
{
$results[] = $this->row;
}
}
elseif($total_rows > 0)
{
while($this->fetch_array())
{
$results[] = $this->row;
}
$this->total_pages = '1';
$this->pages_before = '0';
$this->pages_after = '0';
// here, I suggest not making those values STRINGS, but instead leaving
them be integers. So instead do:
/*
$this->total_pages = 1;
$this->pages_before = 0;
$this->pages_after = 0;
*/
}
else
{
return null;
}
return $results;
}
=======================================
Regards,
Bruno B B Magalh�es
On Jan 7, 2005, at 10:09 PM, M. Sokolewicz wrote:
first of all, you're running 4 queries here. 4 queries is a lot!
Especially when you don't need more than 2 ;)
the problem here is that your queries are pretty "unknown" to this
function. Although it does a nice result for that unknowing, there's a
few minor things that make it faster.
First of all, would be using less queries.
What I usually do is issue a query like this:
"SELECT count(some_unique_col) WHERE
(that_where_clause_youre_using_in_the_select_query)"
then, we do some math.
$pages_before = $page-1;
$rows_before = $pages_before*$itens;
$rows_after = $total_number_of_rows-($page*$itens);
$pages_after = ceil($rows_after/20);
Then do the actual selecting of the rows using the limit.
The thing that makes it slow in your example is the fact that 4 times
you're selecting ALL data from the relevant rows, and buffer it. You
buffer it, but don't use any of it, except for the number of rows.
Mysql does a far quicker job at this than PHP would, so use mysql. :)
Then, you're using 3 queries to determine the rows around the page;
even though, with a bit of simple math, you can calculate it. And
trust me on this, simple math is faster ;)
anyway, hope that helped.
--- End Message ---
--- Begin Message ---
* Thus wrote Bruno B B Magalhes:
> Thanks for your help, in fact helped a lot... Now my function only
> performs 2 queries, here it is:
>
> =======================================
> function fetch_paginated($query='',$page=1,$itens=20)
> {
> $this->query($query);
This here is going to be your big bottle neck. You're requiring
your database to fetch all the results. You're goal with
pagination is to know basically how many rows there are from the
result with minimal effort there are two ways i know that can
accomplish this rather efficiently:
1. use the SQL_CALC_FOUND_ROWS option (i'm assuming this is
mysql from your LIMIT statement).
This way you can always use the LIMIT based on the page and
items you want, and still know how many items would have
been in the results. This will result with simply one query
to the database.
2. Modify your select statement to issue a count(*) of the
query, to accomplish this automatically you can do something
like:
/* find the coulumns to replace with count(*) */
$match = '/(select)\s+(.*?)\s+(from\s+.*)/i';
/* row to start on; calculating what page they are
* on to the actual row number */
$start = (($page-1) * $items);
/* replace fieldnames with count(*) */
$replace = '$1 count(*) as qty $3';
/* now replace the sqlqty and make the limit query */
$sql_qty = preg_replace($match, $replace, $query);
$sql_qty = preg_replace('/(order|group) by.*/', '', $sql_qty);
$sql_limit = $query . " limit $start, $items";
And now you have $sql_qty that returns the number of total
rows are available and $sql_limit which give you the actual
results.
The first usage, is probably the fastest approach (i havn't done
any benchmarks), but it does limit to you with *only* mysql >= 4.0 and
and is not a common thing in other dbms (iirc).
The second option seems like a lot of work but, i can guarantee you
that it will be much faster than selecting all rows in a resultset
and figururing out what to do, expecially on the later pages.
Here is some code that uses method 2, keep in mind that the does
several things, like generating the navigation (which makes it more
complex). I should probably seperate the pagination method a bit
more.
http://zirzow.dyndns.org/html/php/code/paginate.php
And an example usage of it:
http://www.bigstockphoto.com/search.php
HTH,
Curt
--
Quoth the Raven, "Nevermore."
--- End Message ---
--- Begin Message ---
I have used Dreamweaver 4.0 for editing my html files and love its
'design view; so I know exactly what the file looks like before I upload
to the server. We currently now are incorporating a shopping cart into
our site and the files are in 'php' format. When I open a 'php' file in
Dreamweaver in 'design mode' it looks nothing like the page does on the
web. How do I view it so it looks the way an 'html' file does in 'design
mode'. Or, another program that can do what I need is fine too. Thanks.
Deb Curiale
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.9 - Release Date: 1/6/2005
--- End Message ---
--- Begin Message ---
TonyC wrote / nap�sal (a):
I have used Dreamweaver 4.0 for editing my html files and love its
'design view; so I know exactly what the file looks like before I
upload to the server. We currently now are incorporating a shopping
cart into our site and the files are in 'php' format. When I open a
'php' file in Dreamweaver in 'design mode' it looks nothing like the
page does on the web. How do I view it so it looks the way an 'html'
file does in 'design mode'. Or, another program that can do what I
need is fine too. Thanks.
Deb Curiale
Probably cause php is interpreted by the php interpreter
and try not to think of it like about html.
Try to look in the browser through the webserver like
http://localhost/dir/some.php
trobi
--- End Message ---
--- Begin Message ---
On Thu, Jan 06, 2005 at 08:41:57PM -0500, Jason Barnett wrote:
> >Does "not up to date" mean the code isn't working with current releases
> >of php 4 or 5? I'd be interested in giving it a try.
>
> I believe this is the case. AFAIK the APC library doesn't support PHP5
> or at least it didn't when I looked at it. If you want to pitch in
> support for APC you should just download it (or PEAR INSTALL it from the
> command line to try it :) )
I don't think Rasmus was talking about APC. AFAIK he mentioned some
extension code that used the Apache SAPI to run a PHP script to acheive
what we're talking about (persistent global vars/functions/objects etc).
(quoting Rasmus):
> The apache-hooks SAPI can do this, although when I initially wrote it
> nobody seemed interested. George fixed it/rewrote it to work much better,
> but nobody was interested in his version either, so the current
> implementation isn't up to date anymore. The problem was likely that
> people really didn't understand how to use it and it is a rather unsafe
> thing to let PHP scripts fiddle with all the various Apache request hooks.
> You can really toast your server that way. A simple generic data loading
> extension is something people will be able to understand and they are
> unlikely to destroy their server with it.
Rasmus, can you say more about what this is and it's current state of
functionality (or lack thereof)?
(back to quoting Jason):
> >I'm picturing an extension that would simply not allow an uncautious or
> >unknowing scripter to ruin the server, but would only allow him to store
> >all his app defs and data model startup stuff in a one-shot performance
> >booster. It could even do it in a separate (CLI?) interpreter and copy
> >the data over (but only once!) to the Apache-embedded interpreter using
> >a shared memory resource... hmmm.
>
> So your process is something like (correct me if I misunderstand):
> <php_script>
[snip...]
> The above suggestion is quite messy and probably not thread-safe, but
> it's a start. ;)
Well, bravo for venturing a possible implementation, but I'm not versed
in Apache or PHP internals to propose or evaluate one in that kind of
detail :(. I don't know what is possible or how PHP internally stores
variables, functions, objects, etc that would make them able to persist
or be shuffled around.
/jw
--- End Message ---
--- Begin Message ---
I wrote a PHP extension a while ago that implements "executor" persistence
for scalar variables and constants. I never looked much into persisting
objects, arrays or resources but it would be a useful addition to the
extension if someone wants to contribute. I haven't updated the Web site
with the latest version that compiles under 4.3.x, but if you're interested
I can send you the files that changed in the meantime. It has been immensely
useful for my projects.
http://pwee.sourceforge.net
Lance
-----Original Message-----
From: Josh Whiting [mailto:[EMAIL PROTECTED]
Sent: Monday, January 03, 2005 11:28 AM
To: [email protected]
Subject: [PHP] Persistent PHP web application?
Dear list,
My web application (an online classifieds server) requires a set of
fairly large global arrays which contain vital information that most all
the page scripts rely upon for information such as the category list,
which fields belong to each category, and so on. Additionally, there are
a large number of function definitions (more than 13,000 lines of code
in all just for these global definitions).
These global arrays and functions never change between requests.
However, the PHP engine destroys and recreates them every time. After
having spent some serious time doing benchmarking (using Apache Bench),
I have found that this code takes at least 7ms to parse per request on
my dual Xeon 2.4ghz server (Zend Accelerator in use*). This seriously
cuts into my server's peak capacity, reducing it by more than half.
My question is: is there a way to define a global set of variables and
functions ONCE per Apache process, allowing each incoming hit to run a
handler function that runs within a persistent namespace? OR, is it
possible to create some form of shared variable and function namespace
that each script can tap?
AFAIK, mod_python, mod_perl, Java, etc. all allow you to create a
persistent, long-running application with hooks/handlers for individual
Apache requests. I'm surprised I haven't found a similar solution for
PHP.
In fact, according to my work in the past few days, if an application
has a large set of global functions and variable definitions, mod_python
FAR exceeds the performance of mod_php, even though Python code runs
significantly slower than PHP code (because in mod_python you can put
all these definitions in a module that is loaded only once per Apache
process).
The most promising prospect I've come across is FastCGI, which for Perl
and other languages, allows you to run a while loop that sits and
receives incoming requests (e.g. "while(FCGI::accept() >= 0) {..}").
However, the PHP/FastCGI modality seems to basically compare to mod_php:
every request still creates and destroys the entire application
(although the PHP interpreter itself does persist).
Essentially I want to go beyond a persistent PHP *interpreter* (mod_php,
PHP/FastCGI) and create a persistent PHP *application*... any
suggestions?
Thanks in advance for any help!
Regards,
J. Whiting
* - Please note that I am using the Zend Accelerator (on Redhat
Enterprise with Apache 1.3) to cache the intermediate compiled PHP code.
My benchmarks (7ms+) are after the dramatic speedup provided by the
accelerator. I wouldn't even bother benchmarking this without the
compiler cache, but it is clear that a compiler cache does not prevent
PHP from still having to run the (ableit precompiled) array and function
definition code itself.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
even apc/eAcc have to copy from shm to php-memory(alloc by emalloc),
because $array might be modified anytime
i'd guess this is almost same as serialize/unserialize
i doubt if there's anyway to have 1 memcpy $array<-from/to->shm, php
will release 1 element of $array when the element is unset(refcount=0)
maybe apc set element refcount+1, so it won't free by php, but apc
free the whole block itself? or rely on zend memory manager to free?
apc opcode seems doing this way, but i don't know it much.
sth off topic:
the constant-array definition imho, should be optimized to which like
static variable but each time get a new copy
$a = array(...big..)
to:
static $__a = array(....big...)
$a = $__a;
it seems static var isn't store as opcode, i'm not quite sure
well, end of off topic :)
On Thu, 06 Jan 2005 10:58:07 -0800, Rasmus Lerdorf <[EMAIL PROTECTED]> wrote:
> Adrian Madrid wrote:
> > I think I understand where you're coming from. I've had a similar
> > problem and the best solution I've found is eAccelerator (previously
> > known as Turck MMCache). What EA does is keep the bytecodes PHP compiles
> > inshared memory so next time you need that script PHP doesn't need to
> > recompile, EA returns the bytecode from SHM. Now, since PHP scripts are
> > compiled and saved in SHM all I need to do is /save/ the data that does
> > not change often but requires a lot of queries as code (an array inside
> > a script) and include it whenever I need the data. No recompiling, no
> > need to touch the DB again, pure speed. I hope all this helps you. I
> > personally don't need extra processes and stuff like that but if you
> > really want all that you can take a look at phpbeans.
>
> What you are talking about is opcode caching. While it certainly speeds
> things up, it can be done much faster. When you cache a file that
> contains a large PHP array definition, all you are caching are the
> instructions to create that array. On every request these instructions
> need to be loaded from shared memory and executed in order to recreate
> the array. This can be quite slow. What we are discussing here are
> ways to avoid recreating the array on every request which is quite
> different.
>
> -Rasmus
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Xuefer Tinys wrote:
even apc/eAcc have to copy from shm to php-memory(alloc by emalloc),
because $array might be modified anytime
i'd guess this is almost same as serialize/unserialize
You greatly underestimate how slow unserialize is.
-Rasmus
--- End Message ---
--- Begin Message ---
Hi all,
I am using php 3.0 and mysql and win xp.
i want to add users to database through php page.
adduser.php
<html>
<FORM METHOD="post" ACTION="add.php">
Real Name: <INPUT TYPE=text MAXLENGTH=70 NAME="real_name" SIZE=20><Br>
Username: <INPUT TYPE=text MAXLENGTH=70 NAME="username" SIZE=20><Br>
Password: <Input Type=text Maxlength=70 Name="userpass" Size=10><Br>
<INPUT TYPE=submit VALUE="Add"> <INPUT type=reset VALUE="Reset Form"></form>
</tr></td></table></tr></td></table>
</body>
</html>
when i enter the fileds and submit ,the action is not performed, instead
add.php file is opened.
add.php
<?
$ID = uniqid("userID");
$db = mysql_connect("localhost","root","halfdinner");
mysql_select_db (userpass);
$result = mysql_query ("INSERT INTO users (id, real_name, username, password )
VALUES ('$ID', '$real_name', '$username', '$userpass') ");
if(!$result)
{
echo "<b>User not added:</b> ", mysql_error();
exit;
}
if($result)
{
mysql_close($db);
print "User <b>$username</b> added sucessfully!";
}
else
{
print ("Wrong Password");
}
?>
is the problem due to mysql and php connection.i am using windows xp with
apache2.
i followed the steps said by someone in the previous thread.that is adding
libmysql.dll to system32 and so on. I cannot find php_mysql.dll in php.ini.
can some one help
Thanks
babu
---------------------------------
ALL-NEW Yahoo! Messenger - all new features - even more fun!
--- End Message ---
--- Begin Message ---
php 3.0???!
man, you seriously need to think about upgrading :| PHP 3 is seriously
outdated
- tul
Babu wrote:
Hi all,
I am using php 3.0 and mysql and win xp.
i want to add users to database through php page.
adduser.php
<html>
<FORM METHOD="post" ACTION="add.php">
Real Name: <INPUT TYPE=text MAXLENGTH=70 NAME="real_name" SIZE=20><Br>
Username: <INPUT TYPE=text MAXLENGTH=70 NAME="username" SIZE=20><Br>
Password: <Input Type=text Maxlength=70 Name="userpass" Size=10><Br>
<INPUT TYPE=submit VALUE="Add"> <INPUT type=reset VALUE="Reset Form"></form>
</tr></td></table></tr></td></table>
</body>
</html>
when i enter the fileds and submit ,the action is not performed, instead
add.php file is opened.
add.php
<?
$ID = uniqid("userID");
$db = mysql_connect("localhost","root","halfdinner");
mysql_select_db (userpass);
$result = mysql_query ("INSERT INTO users (id, real_name, username, password )
VALUES ('$ID', '$real_name', '$username', '$userpass') ");
if(!$result)
{
echo "<b>User not added:</b> ", mysql_error();
exit;
}
if($result)
{
mysql_close($db);
print "User <b>$username</b> added sucessfully!";
}
else
{
print ("Wrong Password");
}
?>
is the problem due to mysql and php connection.i am using windows xp with
apache2.
i followed the steps said by someone in the previous thread.that is adding libmysql.dll to system32 and so on. I cannot find php_mysql.dll in php.ini.
can some one help
Thanks
babu
---------------------------------
ALL-NEW Yahoo! Messenger - all new features - even more fun!
--- End Message ---
--- Begin Message ---
Hello all,
I have tried looking through the previous messages, but I have yet to
find anything that involves my specific problem. Maybe I am not
searching for the correct terminology.
I current have a php script that processes many files (6000+). When
it is processing a file, it prints out what is going on with each file
to a seperate line. What I want to do is OVERWRITE the output line for
each file, and keep output to a single line. (Please see below for
example) - I know it is possible to do this in bash, pearl and other
scripting languages, but I have yet to figure out if it is possible in
php. I have tried printing backspace characters (\b), the ascii
equivalent, etc, but nothing seems to be working. If anyone has any
solutions / suggestions, it would be most welcome.
Example:
Current screen (after 3 iterations):
running cleanup...
processing 1 of 6453: adding extensions / removing case.
processing 2 of 6453: adding extensions / removing case.
processing 3 of 6453: invalid extension - deleteing.
Wanted screen (after 3 iterations):
running cleanup...
processing 3 of 6453: invalid extension - deleteing.
(The content of the lines is unimportant, its the number of lines
showing that is)
Thanks in advance!
- bob.
--- End Message ---
--- Begin Message ---
On Sunday 09 January 2005 01:01, Robert M. Pufky wrote:
> I current have a php script that processes many files (6000+). When
> it is processing a file, it prints out what is going on with each file
> to a seperate line. What I want to do is OVERWRITE the output line for
> each file, and keep output to a single line. (Please see below for
> example) - I know it is possible to do this in bash, pearl and other
> scripting languages, but I have yet to figure out if it is possible in
> php. I have tried printing backspace characters (\b), the ascii
> equivalent, etc, but nothing seems to be working. If anyone has any
> solutions / suggestions, it would be most welcome.
rewind()
> Example:
>
> Current screen (after 3 iterations):
> running cleanup...
> processing 1 of 6453: adding extensions / removing case.
> processing 2 of 6453: adding extensions / removing case.
> processing 3 of 6453: invalid extension - deleteing.
>
> Wanted screen (after 3 iterations):
> running cleanup...
> processing 3 of 6453: invalid extension - deleteing.
>
> (The content of the lines is unimportant, its the number of lines
> showing that is)
Note that you'll have to keep track of line lengths so remnants from a
previous iteration are properly overwritten.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts
--- End Message ---
--- Begin Message ---
James Nunnerley wrote:
Hi All,
Bit of a side question, but it's still php related.
Does anyone know of a Webmail client, preferably open-source, that is able
to support single login, to allow users to collect and use multiple POP3 or
IMAP accounts?
I'm currently using Ilohamail, and have used Squirrel in the past, but
neither, I don't, think support multiple POP3 accounts on one login.
Any ideas?
Cheers
James
Check this out!
http://openwebmail.org/
--- End Message ---
--- Begin Message ---
* Thus wrote Don:
> Hi,
>
> Reading the PHP 5 documentation at: HYPERLINK
> "http://www.php.net/manual/en/language.oop5.basic.php"http://www.php.net/man
> ual/en/language.oop5.basic.php, I am confused.
After looking at the example output, it is not correct, the real
output should be:
object(SimpleClass)#1 (1) {
["var"]=>
string(30) "$assigned will have this value"
}
object(SimpleClass)#1 (1) {
["var"]=>
string(30) "$assigned will have this value"
}
object(SimpleClass)#1 (1) {
["var"]=>
string(30) "$assigned will have this value"
}
> In the example given, what is the difference between:
> $assigned = $instance;
> $reference =& $instance;
>
> I would expect all of the var_dump to display NULL
The manual needs some changes, the example 19-3 is assuming that
both 19-1 and 19-2 exist in the code, which should result with what
I have above.
>
> The doc says "When assigning an already created instance of an object to a
> new variable, the new variable will access the same instance as the object
> that was assigned." so the above assignments seem the same to me and setting
> $instance to NULL should also set $assigned to NULL.
>
> If this is not the case and not using the '&' specifies a 'copy'
> (contradicting the documentation) then what's the purpose of object cloning?
>
> I tried the code below and find that it gives the exact same output
> regardless if I am using the '&' or not so it seems to assign be reference
> either way.
The way objects are assigned in php5 are a bit different than in
php4, basically in php4 if you do something like:
$var1 = new Object();
$var2 = $var1;
It is treated like a clone, where now there are two objects.
php5 on the other hand, its a little more complex. When an object
is create in php5 and assigned to a variable, there are two things
that happen:
$var1 = new Object();
1. an object is created
2. a variable, referencing that object, is created.
When you assign a variable (that references the object) to another
variable, we now have two variables referencing the object:
$var2 = $var1;
So if I issue:
unset($var1);
the same object that was originally crated still exists in $var2,
until i destroy $var2, then that object gets destroyed as well.
Now, with the = & assignment:
$var2 = &$var1;
What happens here is that both $var1 and &var2 become in a way
identical. If I issue:
unset($var1);
Then both $var1 and $var2 become unset, thus the original object
no longer is being referenced by anything.
I hope that didn't complicate things, but helped clarified what you
were looking at.
Curt
--
Quoth the Raven, "Nevermore."
--- End Message ---
--- Begin Message ---
Hello,
Im fairly new to PHP and I am running an Apache web server on my
computer, set up as localhost, and i recently installed MySQL 4.1 . I
am having trouble making a DB and a table in the DB. when i try to
create it from a command prompt it tells me this:
C:\mysql\bin>mysqld-opt
C:\mysql\bin>mysqladmin create userDB
mysqladmin: connect to server at 'localhost; failed
error: 'Can't connect to MySQL server on 'localhost' (10061)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'
and when I try to connect using Telnet it gives me this error
Microsoft Telnet> open localhost 3306
Connecting to localhost...Could not open connection to the host, on
port 3306: Connection failed
And when i run services.msc it shows that mysql is running, so i dont
know what the problem is. Anyone have any ideas?
~Andrew
--- End Message ---
--- Begin Message ---
Try running mysqld without the -opt. Check out this site
www.apachefriends.org it has a great all in one package that can be
installed on Windows and Linux. If you install it on Windows it has the
option to setup mysql and apache to run as services. This XAMPP package
is a no brainer!!
Hope this helps.
Andrew Maxwell wrote:
Hello,
Im fairly new to PHP and I am running an Apache web server on my
computer, set up as localhost, and i recently installed MySQL 4.1 . I
am having trouble making a DB and a table in the DB. when i try to
create it from a command prompt it tells me this:
C:\mysql\bin>mysqld-opt
C:\mysql\bin>mysqladmin create userDB
mysqladmin: connect to server at 'localhost; failed
error: 'Can't connect to MySQL server on 'localhost' (10061)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'
and when I try to connect using Telnet it gives me this error
Microsoft Telnet> open localhost 3306
Connecting to localhost...Could not open connection to the host, on
port 3306: Connection failed
And when i run services.msc it shows that mysql is running, so i dont
know what the problem is. Anyone have any ideas?
~Andrew
--- End Message ---
--- Begin Message ---
Hi,
Recently I migrated the front-end of our bulletin board (running
phpBB, patched against the recently highlight vulnerability) to a pair
of servers running Fedora Core 3. I compiled Apache 1.3.33 and PHP
4.3.10 from source. The MySQL database is running on a separate machine.
This morning, the servers slowed down to the point that they were
almost completely unresponsive. After a while I managed to SSH into
the machines and saw that the httpd processes had grown to 35MB each
and were using up all the swap and RAM on the machines (they have 1GB
RAM, 1GB swap). I then set MaxClients to 30 and restarted Apache, but
the slowdown happened again:
top - 18:18:51 up 32 days, 4:51, 1 user, load average: 15.22, 41.62, 39.75
Tasks: 90 total, 1 running, 89 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2% us, 0.0% sy, 0.0% ni, 99.7% id, 0.2% wa, 0.0% hi, 0.0% si
Mem: 1033484k total, 898000k used, 135484k free, 1268k buffers
Swap: 1052248k total, 896880k used, 155368k free, 10896k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19305 nobody 16 0 41892 35m 5732 S 0.0 3.5 0:38.49 /www/bin/httpd
19219 nobody 18 0 41940 29m 5732 S 0.0 3.0 0:20.87 /www/bin/httpd
19290 nobody 18 0 41940 29m 5732 S 0.0 3.0 0:42.64 /www/bin/httpd
19217 nobody 18 0 48780 29m 5736 S 0.0 2.9 0:51.25 /www/bin/httpd
19252 nobody 16 0 41916 29m 5732 S 0.0 2.9 0:45.81 /www/bin/httpd
19298 nobody 18 0 41940 29m 5732 S 0.0 2.9 0:16.61 /www/bin/httpd
19296 nobody 18 0 44052 25m 5732 S 0.0 2.6 0:42.79 /www/bin/httpd
19294 nobody 18 0 41796 25m 5732 S 0.0 2.5 0:11.85 /www/bin/httpd
19215 nobody 17 0 41892 25m 5732 S 0.0 2.5 0:22.84 /www/bin/httpd
19218 nobody 17 0 41940 25m 5732 S 0.0 2.5 0:17.84 /www/bin/httpd
19221 nobody 16 0 41900 24m 5732 S 0.0 2.5 0:45.56 /www/bin/httpd
19299 nobody 17 0 41796 24m 5732 S 0.0 2.5 0:11.63 /www/bin/httpd
19302 nobody 17 0 41796 24m 5732 S 0.0 2.5 0:13.46 /www/bin/httpd
19220 nobody 16 0 42300 24m 5732 S 0.0 2.4 0:24.97 /www/bin/httpd
19292 nobody 16 0 41796 21m 5732 S 0.0 2.1 0:37.17 /www/bin/httpd
19303 nobody 16 0 43736 19m 5732 S 0.0 1.9 0:45.86 /www/bin/httpd
19300 nobody 18 0 42184 16m 5732 S 0.0 1.6 0:31.80 /www/bin/httpd
19222 nobody 18 0 42264 14m 5732 S 0.0 1.4 0:16.17 /www/bin/httpd
19291 nobody 16 0 41904 13m 5732 S 0.0 1.4 0:12.57 /www/bin/httpd
19293 nobody 16 0 41796 12m 5732 S 0.0 1.3 0:33.04 /www/bin/httpd
19295 nobody 18 0 44040 11m 5732 S 0.0 1.1 0:35.78 /www/bin/httpd
19224 nobody 17 0 42292 8600 5732 S 0.0 0.8 0:15.22 /www/bin/httpd
19304 nobody 16 0 43804 7908 5732 S 0.0 0.8 0:37.06 /www/bin/httpd
19301 nobody 16 0 43736 7316 5732 S 0.0 0.7 0:40.19 /www/bin/httpd
19537 nobody 18 0 21112 7020 5732 S 0.0 0.7 0:05.79 /www/bin/httpd
19250 nobody 16 0 42272 5712 5732 S 0.0 0.6 0:15.20 /www/bin/httpd
19223 nobody 16 0 41940 5248 5732 S 0.0 0.5 0:45.97 /www/bin/httpd
19216 nobody 16 0 41892 4828 5732 S 0.0 0.5 0:42.77 /www/bin/httpd
19287 nobody 18 0 41892 4312 5732 S 0.0 0.4 0:38.22 /www/bin/httpd
19288 nobody 18 0 41892 4096 5732 S 0.0 0.4 0:08.98 /www/bin/httpd
I then checked the error log and found this:
*** glibc detected *** double free or corruption: 0x097ec7e8 ***
*** glibc detected *** double free or corruption: 0x097ec7e8 ***
*** glibc detected *** double free or corruption: 0x097e6d58 ***
*** glibc detected *** double free or corruption: 0x096ec7b8 ***
*** glibc detected *** double free or corruption: 0x09723188 ***
*** glibc detected *** double free or corruption: 0x097ed3b8 ***
*** glibc detected *** double free or corruption: 0x097e8870 ***
*** glibc detected *** double free or corruption: 0x097ffe88 ***
*** glibc detected *** double free or corruption: 0x096ee320 ***
*** glibc detected *** double free or corruption: 0x08f147e8 ***
*** glibc detected *** double free or corruption: 0x08f147f8 ***
*** glibc detected *** double free or corruption: 0x08f147f8 ***
and the same on the other server:
*** glibc detected *** double free or corruption: 0x09957ac0 ***
*** glibc detected *** double free or corruption: 0x09a50710 ***
*** glibc detected *** double free or corruption: 0x09a622e0 ***
*** glibc detected *** double free or corruption: 0x09978768 ***
*** glibc detected *** double free or corruption: 0x099df900 ***
*** glibc detected *** double free or corruption: 0x0993ca08 ***
*** glibc detected *** double free or corruption: 0x0992b6d8 ***
*** glibc detected *** double free or corruption: 0x0992b6d8 ***
*** glibc detected *** double free or corruption: 0x0992b5f8 ***
This bulletin board application has been running fine for a month or
so on a pair of Fedora Core 1 servers running PHP 4.3.9 (which I've
recently upgraded to 4.3.10), and they didn't have the above problem.
Any advice would be much appreciated.
Regards,
-- Alex
--- End Message ---
--- Begin Message ---
> Josh, I am interested in what you mean by "but there may be a better
> overall approach."
(which was in reference to my original question which was: why are you
using a big switch?)
The reason I say that is because, though I'm no expert on application
design, in my own code I've found that whenever I'm tempted to use a big
switch, it's probably a better idea for me to make a class hierarchy. I
just have a hard time imagining a case where a big switch accurately
represents the problem to be solved, since in real life solving problems
is more complicated than a flat set of totally isolated operations.
For example, a while ago I wrote some form validation code for a
classifieds application that used a 50+ case switch to validate incoming
form data, one case for each possible kind of field (make & model,
price, location, color, etc). There was a large amount of overlapping
functionality for similar field types and it was also hard for me to
understand exactly what the start and end goal was for all the cases.
If some common thing needed to be changed, most or all the cases had to
be updated and kept consistent, and by the 45th case my brain is going
to miss something.
Now I'm not suggesting this is what you're doing - this is just bad
design on my part. Currently I'm in the process of implementing a class
hierarchy of fields, where for example the "make_and_model" class
inherits from the "drop_down" parent class, which inherits from the
"basic_field" class, each one extended or overriding it's parents
validate() method. If I need to update the way drop downs validate, I
make a change in the drop_down class and it propagates naturally to all
the instances and subclasses. A much better method than my earlier
switch!
So, because I feel like I've learned a bit personally about avoiding big
switches I was curious about your approach, which I say again could be
perfectly elegant :)
/jw
--- End Message ---