php-general Digest 12 Dec 2004 11:01:50 -0000 Issue 3165
Topics (messages 204074 through 204092):
FTP_PUT 0kb problem
204074 by: jpb
204076 by: Marek Kilimajer
php variables in a backtick command
204075 by: Jonathan Duncan
204077 by: Jonathan Duncan
204079 by: Sebastian
204084 by: Rory Browne
204087 by: Jonathan Duncan
204088 by: Jonathan Duncan
Re: Data Access Object (DAO) with PHP
204078 by: Manuel Lemos
Re: PHP via DIAL-UP?
204080 by: Rory Browne
Forms Question: Options
204081 by: Steve Marquez
204082 by: Matthew Weier O'Phinney
Re: Joining same table twice
204083 by: Marek Kilimajer
Re: MySQL Connection problem
204085 by: Peter Lauri
dynamic include() in while loop
204086 by: Sebastian
Re: Sorry forgot to include the code for my last message - Mike Francis
204089 by: David Robley
Header location open into a new window?
204090 by: Justin Wilkins
Re: Question: Repopulating form parameters
204091 by: Stuart Felenstein
204092 by: Jason Wong
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 ---
I am using the FTP_PUT command in conjunction with a form:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="imagefile">
<input type="submit" value="Submit">
upload.php:
Everything seems to work except the put statement.
$upload = ftp_put($conn_id, $destination_file, $_POST[imagefile],
FTP_BINARY);
I am connecting to the server and it is replacing the old image file with a
0 kb file.
Permissions are RWX across the board. Any ideas?
Thanks - Jeff
--- End Message ---
--- Begin Message ---
jpb wrote:
I am using the FTP_PUT command in conjunction with a form:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="imagefile">
<input type="submit" value="Submit">
upload.php:
Everything seems to work except the put statement.
$upload = ftp_put($conn_id, $destination_file, $_POST[imagefile],
FTP_BINARY);
I am connecting to the server and it is replacing the old image file with a
0 kb file.
Permissions are RWX across the board. Any ideas?
Read http://www.php.net/manual/en/features.file-upload.php
information about uploaded file(s) is in $_FILES array and
$_FILES['imagefile'] is an array
--- End Message ---
--- Begin Message ---
I am trying to run a shell command with backticks. However, I get a parse
error. Is it because I have an array variable in there?
$result = `adduser -l=$dist_id -p=$user['password'] --f="$user['name_first']
$user['name_last']"`;
Do I need to assign the value to a regular variable before I put it in
there? Like this?
$pword=$user['password']
$fname =$user['name_first']
$lname =$user['name_last']
$result = `adduser -l=$dist_id -p=$pword --f="$fname $lname"`;
Thanks,
Jonathan
--- End Message ---
--- Begin Message ---
So I tried it that way and it worked, that is annoying though, having to add
extra lines to the code and assign the contents of one variable to another.
Any way around this?
Jonathan
"Jonathan Duncan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I am trying to run a shell command with backticks. However, I get a parse
>error. Is it because I have an array variable in there?
>
> $result =
> `adduser -l=$dist_id -p=$user['password'] --f="$user['name_first']
> $user['name_last']"`;
>
> Do I need to assign the value to a regular variable before I put it in
> there? Like this?
>
> $pword=$user['password']
> $fname =$user['name_first']
> $lname =$user['name_last']
> $result = `adduser -l=$dist_id -p=$pword --f="$fname $lname"`;
>
> Thanks,
> Jonathan
--- End Message ---
--- Begin Message ---
well $user['password'] has no double quotes around it.
----- Original Message -----
From: "Jonathan Duncan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, December 11, 2004 8:09 PM
Subject: [PHP] php variables in a backtick command
> I am trying to run a shell command with backticks. However, I get a parse
> error. Is it because I have an array variable in there?
>
> $result =
`adduser -l=$dist_id -p=$user['password'] --f="$user['name_first']
> $user['name_last']"`;
>
> Do I need to assign the value to a regular variable before I put it in
> there? Like this?
>
> $pword=$user['password']
> $fname =$user['name_first']
> $lname =$user['name_last']
> $result = `adduser -l=$dist_id -p=$pword --f="$fname $lname"`;
>
> Thanks,
> Jonathan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
--- End Message ---
--- Begin Message ---
I'm not sure about variable expansion with backticks(I don't use
backticks, if necessary I use shell_exec() instead). I'm just after
installing a fresh SuSE 9.1, and php is giving me a segfault at the
minute, with that particular code, but if you were using double quotes
you could:
$command = "adduser -l=$dist_id -p={$user['password']}
--f=\"{$user['name_first']} {$user['name_last']}\"";
bearing in mind that the variables have been {}'ed, and your double
quote around $user['name_first'] and ['name_last']) has been escaped
to \"
you can use shell_exec($command), which is identical to the backtick operation.
Having that said, you should consider using alternative program
execution instead, instead of using the shell. What do you need the
shell for? You might(albeit unlikely) also come across a situation
where the shell is something like /bin/false, or /bin/falselogin, or
/bin/scponly, or basicly something that doesn't particularly work that
well as a shell.
Rory
On Sat, 11 Dec 2004 18:09:17 -0700, Jonathan Duncan <[EMAIL PROTECTED]> wrote:
> I am trying to run a shell command with backticks. However, I get a parse
> error. Is it because I have an array variable in there?
>
> $result = `adduser -l=$dist_id -p=$user['password'] --f="$user['name_first']
> $user['name_last']"`;
>
> Do I need to assign the value to a regular variable before I put it in
> there? Like this?
>
> $pword=$user['password']
> $fname =$user['name_first']
> $lname =$user['name_last']
> $result = `adduser -l=$dist_id -p=$pword --f="$fname $lname"`;
>
> Thanks,
> Jonathan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Ah, that is a good idea, putting the command in a variable and then
executing the variable. I have doen that before but did not think of it
now. Too many things going on. Thanks!
Jonathan
"Rory Browne" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm not sure about variable expansion with backticks(I don't use
> backticks, if necessary I use shell_exec() instead). I'm just after
> installing a fresh SuSE 9.1, and php is giving me a segfault at the
> minute, with that particular code, but if you were using double quotes
> you could:
>
> $command = "adduser -l=$dist_id -p={$user['password']}
> --f=\"{$user['name_first']} {$user['name_last']}\"";
>
> bearing in mind that the variables have been {}'ed, and your double
> quote around $user['name_first'] and ['name_last']) has been escaped
> to \"
>
> you can use shell_exec($command), which is identical to the backtick
> operation.
>
> Having that said, you should consider using alternative program
> execution instead, instead of using the shell. What do you need the
> shell for? You might(albeit unlikely) also come across a situation
> where the shell is something like /bin/false, or /bin/falselogin, or
> /bin/scponly, or basicly something that doesn't particularly work that
> well as a shell.
>
> Rory
>
> On Sat, 11 Dec 2004 18:09:17 -0700, Jonathan Duncan <[EMAIL PROTECTED]>
> wrote:
>> I am trying to run a shell command with backticks. However, I get a
>> parse
>> error. Is it because I have an array variable in there?
>>
>> $result =
>> `adduser -l=$dist_id -p=$user['password'] --f="$user['name_first']
>> $user['name_last']"`;
>>
>> Do I need to assign the value to a regular variable before I put it in
>> there? Like this?
>>
>> $pword=$user['password']
>> $fname =$user['name_first']
>> $lname =$user['name_last']
>> $result = `adduser -l=$dist_id -p=$pword --f="$fname $lname"`;
>>
>> Thanks,
>> Jonathan
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
--- End Message ---
--- Begin Message ---
The quotes are only for the shell command which does not use quotes around
password. Thanks for the feedback.
Jonathan
"Sebastian" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> well $user['password'] has no double quotes around it.
>
> ----- Original Message -----
> From: "Jonathan Duncan" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Saturday, December 11, 2004 8:09 PM
> Subject: [PHP] php variables in a backtick command
>
>
>> I am trying to run a shell command with backticks. However, I get a
>> parse
>> error. Is it because I have an array variable in there?
>>
>> $result =
> `adduser -l=$dist_id -p=$user['password'] --f="$user['name_first']
>> $user['name_last']"`;
>>
>> Do I need to assign the value to a regular variable before I put it in
>> there? Like this?
>>
>> $pword=$user['password']
>> $fname =$user['name_first']
>> $lname =$user['name_last']
>> $result = `adduser -l=$dist_id -p=$pword --f="$fname $lname"`;
>>
>> Thanks,
>> Jonathan
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
--- End Message ---
--- Begin Message ---
Hello,
Adwin Wijaya wrote:
Is there any mature DAO class for PHP (free) ?
You may want to check Metastorage. It is not really a DAO class but
rather a DAO class generator. It tends to generate code that is much
more efficient than DAO base classes as the generated code only includes
the features that you need for each DAO class in your data model, and
any static details are compiled as optimized code instead of parameters
that will consume CPU and memory to compute.
For instance, you do not need to build your queries at run time. These
are just compiled into the generated code, even those that need to take
dynamic parameters defined at run time. It is like calling stored
procedures.
The way Metastorage works is letting the developer describe your data
model of classes in a simple XML format with variables, relationships,
validation rules and the type of functions that you need to manipulate
your data objects.
Once you have defined your data model, the compiler (which is actually a
bunch of PHP classes) builds everything that you need in a few seconds.
The generated code is very compact and independent as it does not need
any part of the compiler to run in your applications.
http://www.meta-language.net/metastorage.html
Here are also some screenshots of the compiler Web interface GUI, Web
forms to interface with sample project generated classes, and UML
diagram of generated classes:
http://www.meta-language.net/screenshots.html
--
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/
Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
--- End Message ---
--- Begin Message ---
Assuming I understand you correctly, you want to connect to your
office computer, which is running apache, from home.
The fact that you are using win98 isn't particularly relevent,
provided you can connect to the internet with it.
Are you talking about connecting to your office computer through the
internet, or establishing a DialUp Link directly between your home,
and office? If it is the former, then all you need to do, is put your
office's IP into the address bar instead of http://localhost.
Your office enviornment is more relevent than anything else on this matter.
In short we'll need more info.
On Fri, 10 Dec 2004 17:34:56 -0800 (PST), Police Trainee
<[EMAIL PROTECTED]> wrote:
> Hello. I have a computer at my office running Apache
> that I use to run PHP scripts with using
> http://localhost.
>
> Is there anyway I can set up my computer to allow me
> to dial-in from home and use the webserver and my php
> applications?
>
> It is a win 98 system with tcp/ip.
>
> __________________________________
> Do you Yahoo!?
> Read only the mail you want - Yahoo! Mail SpamGuard.
> http://promotions.yahoo.com/new_mail
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Hi everyone!
Can someone help me with this question?
I created a photo upload utility with individual galleries that images can
be uploaded into. In the MySQL database, there are multiple names of
galleries, some are the same. I want to have a select menu to show just the
unique names of the galleries.
I have used:
Select DISTINCT gallery_names from images_upload;
I have about 15 records, ten are "GALLERY1" and 5 are "GALLERY2." When I use
the DISTINCT, two are output. It works perfectly in the MySQL terminal.
However, when I use the same in PHP as a web page, it only outputs one, the
one with only 5 records.
Here is the code:
<?php
// log into our local server using the MySQL root user.
$dbh = mysql_connect( "hostname", "username", "password" );
// select the database.
mysql_select_db( "db" ) or die ( mysql_error() . "\n" );
//and read it back for printing purposes.
$get_table_data = "SELECT DISTINCT gallery_name FROM images_upload ORDER
BY gallery_name DESC";
$response = mysql_query( $get_table_data, $dbh );
//now print it out for the user.
if ( $one_line_of_data = mysql_fetch_array( $response ) ) {
extract ( $one_line_of_data );
}
?>
<-- Snip -->
<?php
while ( $data = mysql_fetch_array( $response, MYSQL_ASSOC)) {
print "<select name=\"gallery_name\">";
foreach ( $data as $option_value ) {
print "<option
value=\"$option_value\">$option_value</option>";
} print "</select>";
}
?>
<-- Snip -->
--- End Message ---
--- Begin Message ---
* Steve Marquez <[EMAIL PROTECTED]>:
> I created a photo upload utility with individual galleries that images can
> be uploaded into. In the MySQL database, there are multiple names of
> galleries, some are the same. I want to have a select menu to show just the
> unique names of the galleries.
>
> I have used:
>
> Select DISTINCT gallery_names from images_upload;
>
> I have about 15 records, ten are "GALLERY1" and 5 are "GALLERY2." When I use
> the DISTINCT, two are output. It works perfectly in the MySQL terminal.
>
> However, when I use the same in PHP as a web page, it only outputs one, the
> one with only 5 records.
>
> Here is the code:
>
> <?php
>
> // log into our local server using the MySQL root user.
> $dbh = mysql_connect( "hostname", "username", "password" );
>
> // select the database.
> mysql_select_db( "db" ) or die ( mysql_error() . "\n" );
>
> //and read it back for printing purposes.
> $get_table_data = "SELECT DISTINCT gallery_name FROM images_upload ORDER
> BY gallery_name DESC";
>
> $response = mysql_query( $get_table_data, $dbh );
>
> //now print it out for the user.
> if ( $one_line_of_data = mysql_fetch_array( $response ) ) {
It's only printing out one record because you're only fetching from the
results set once. Change that to :
while ($one_line_of_data = mysql_fetch_array($response)) {
and you should be set.
--
Matthew Weier O'Phinney | mailto:[EMAIL PROTECTED]
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
--- End Message ---
--- Begin Message ---
Sebastian wrote:
i apologize if its against the rules to post mysql questions here, though im
using php to query the db
so...
i have a table with three integers.
[table post]
postuserid | replyuserid | parentid
----------------------------------
i do a left join on table user to get the username that postuserid belongs
to, but i also need to get the username on the same table 'user' of
replyuserid as well if parentid isn't null. can this be done with a single
query?
this is what i have:
mysql_query("
SELECT post.postuserid, post.replyuserid, post.parentid, user.username AS
uname FROM post
LEFT JOIN user ON(user.userid = post.postuserid) ORDER BY id");
that gets me the username of postuserid, but what about replyuserid, how i
get that username?
thanks for any help.
If you are using the same table more than once you can alias it and use
the alias in your select, where, order by etc. clauses. If more columns
have the same name, you can alias them too to get distinct array keys
from mysql_fetch_assoc()
Useless example:
select t1.id t1_id, t2.id t2_id from table t1 left join table t2 on
t1.id = t2.id ..
--- End Message ---
--- Begin Message ---
It would be nice if you submit code that generates the error.
/Peter
"Mike Francis" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
Hi,
I have Apache 2, PHP 5 and MySQL 4.1 installed on an XP pro box.
I have created a new database 'ijdb' with a single table 'joke' and have
entered data into two of the three fields in the table.
I can access the database / tables / data from a command prompt.
However, when I try to connect through WAMP I either receive a 'Unable to
connect to the
database server at this time.' error message - which is my default error
message, or, I receive a blank window in IE / Mozilla / Opera etc and no
error messages.
I have tried removing the @ from the file and this has no effect -
interesting?!
The error logs do not reveal anything that indicates a missing table /
field.
I wonder if anyone has any ideas ?
Cheers,
Mike
--- End Message ---
--- Begin Message ---
this is a brain buster, at least for me.
i have a while loop (results from mysql) which display news articles. i want
to include() a file if there hasn't been a news article posted "today"
meaning after midnight 12am to 12pm midnight... but if there are articles
the articles would be echo'd before the include and the rest of the articles
below the include..
eg,
Article (today)
Article (today)
include();
More articles (not today)
.. but if there are no Articles posted "today" it would show up as:
include();
Article
Article
i want to know if this is possible, if so, can anyone give me an example?
the articles are dated in unix timestamp.
cheers
--- End Message ---
--- Begin Message ---
On Sun, 12 Dec 2004 07:03, Mike Francis wrote:
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Our List of Jokes</title>
> <meta http-equiv="content-type"
> content="text/html; charset=iso-8859-1" />
> </head>
> <body>
> <?php
> // Connect to the database server
> $dbcnx = @mysql_connect('localhost', 'root', 'MyPassword');
> if (!$dbcnx) {
> echo '<p>Unable to connect to the ' .
> 'database server at this time.</p>' );
Note that using the @ in front of the connect suppresses any error messsages
that may be returned from the connect; I would get rid of that. Then add
here:
echo mysql_error();
> exit();
> }
> // Select the jokes database
> if ([EMAIL PROTECTED]('ijdb')) {
And use mysql_error() here too.
> exit('<p>Unable to locate the joke ' .
> 'database at this time.</p>');
> }
> ?>
mysql_error() will return a useful error message.
--
David Robley
Backups? We doan *NEED* no steenking baX%^~,VbKx NO CARRIER
--- End Message ---
--- Begin Message ---
Is there a way in the current code below to make my $go_to_address go to a
webpage in a new link -- instead of embedded in an iframe?
In others words, can Header(Location: open in a new window?
<?
if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {
die ("You can't access this file directly..."); }
if(!IsSet($mainfile)) { include ("mainfile.php"); }
/* get current user online whether they are registered user or just visitor
*/
/* we need global variables belong to PHP-Nuke */ global $user, $anonymous;
$users = $user;
/* init our variables */
$userid = 1;
$username = $anonymous;
/* check if registered user online */
if (is_user($users))
{
if (!is_array($users))
{
$user_cookie = explode(':', addslashes(base64_decode($users)));
$userid = $user_cookie[0];
$username = $user_cookie[1];
unset($user_cookie);
}
else
{
$userid = $users[0];
$username = $users[1];
}
$userid = (preg_match('/^[0-9]+$/', $userid)) ? intval($userid) : 1;
$username = (preg_match('/^[a-z0-9_-]+$/i', $username)) ? $username :
$anonymous;
}
/* construct a link (for registered user) */ if ($userid > 1) {
$content =
'https://swww.google.com/servlet/com.google.framework.servlets.BGSeamlessLog
in?STYLESHEETURL=google&PREFID='.rawurlencode($username).'';
}
else
{
$content2 = 'modules.php?name=form_joinpp'; }
/* clean unnecessary variables, to keep memory usage as low as possible */
unset($userid); unset($username);
/* all done. we provide $content variable to block handler */
$index=0;
$theme="4July";
//////TEST
$url_for_anonymous = $content2;
/////TEST
if (is_user($user)) {
$go_to_address1=$content;
$go_to_address=rawurldecode($go_to_address1);
include("header.php");
OpenTable3();
echo "<center><h4><a href=\"index.php\">Click Here to Return to the Main
Menu</a></h4></center>"; echo "<iframe SRC=\"".$go_to_address."\"
width=\"100%\" height=\"1200\"
framespacing=0 frameborder=no border=0 scrolling=auto></iframe>"; echo
"<br><center></center><br>"; } else { header("Location:".$content2.""); }
CloseTable3();
include("footer.php");
die;
?>
--- End Message ---
--- Begin Message ---
--- Jason Wong <[EMAIL PROTECTED]> wrote:
> > I'm pretty sure I need to loop through the $_Get
> of
> > the array. Not sure , and haven't found anything
> > that shows this.
>
> Yes, you need to reference $_GET to see whether an
> option was selected and
> change the echo above accordingly.
>
Still stuck on this one. I know I'm doing something
wrong and wouldn't mind some correction:
Code now:
if (count($Ind) > 0 AND is_array($Ind)) {
$Ind = "'".implode("','", $Ind)."'";
<select name="Ind[]" size="8" multiple="multiple"
id="Ind[]" >
<?php
$selected = $_GET['Ind'];
while($row = mysql_fetch_array($inds, MYSQL_BOTH)) {
if ($selected==$row['CareerIDs']) echo ' selected';
echo '<option
value="'.$row['CareerIDs'].'">'.$row['CareerCategories'].'</option>';
}
?>
Stuart
--- End Message ---
--- Begin Message ---
On Sunday 12 December 2004 18:15, Stuart Felenstein wrote:
> Still stuck on this one. I know I'm doing something
> wrong and wouldn't mind some correction:
Did you mockup some test HTML in a wysisyg editor as suggested?
> Code now:
>
> if (count($Ind) > 0 AND is_array($Ind)) {
> $Ind = "'".implode("','", $Ind)."'";
>
> <select name="Ind[]" size="8" multiple="multiple"
> id="Ind[]" >
> <?php
> $selected = $_GET['Ind'];
> while($row = mysql_fetch_array($inds, MYSQL_BOTH)) {
> if ($selected==$row['CareerIDs']) echo ' selected';
> echo '<option
> value="'.$row['CareerIDs'].'">'.$row['CareerCategories'].'</option>';
>
> }
> ?>
Did you compare the mockup HTML with that produced by your code above?
--
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
------------------------------------------
/*
Polymer physicists are into chains.
Ö
*/
--- End Message ---