Re: [PHP-DB] SQL Insert problem

2004-08-05 Thread John W. Holmes
From: Vincent Jordan [EMAIL PROTECTED]

   $sql = INSERT INTO rmarequest (firstname, lastname, address,
   address2,
   city, state, zip, phone, email, serial, product, reason,
   rmanumber)VALUES
   ('$firstname', '$lastname', '$address', '$city', '$state',
   '$zip', '$phone',
   '$email', '$serial', '$product', '$reason', '$rmanumber') or die
   (mysql_error());

Uhhh. where's mysql_query()???

$sql = INSERT ...;

$result = mysql_query($sql) or die(mysql_error());

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: LAMP

2004-08-03 Thread John W. Holmes
From: Lester Caine [EMAIL PROTECTED]
  I'd really like to find a Linux distro that is a LAMP system right out
  of the box.
  (Linux, Apache, MySQL, PHP)
  Are there any out there?

 Thankfully not ;)
 I want LAFP but LAPP seems still to be more popular on Linux.

 WHY does everybody run lemming like after MySQL. It STILL has to catch
 up with the better FREE database engines ;)

Right... I find a great need for triggers and stored procedures in my
guestbooks and shoutboxes.

Come on people, the right tool for the right job. MySQL is supported on more
hosts and fills the needs of most web developers. This is like arguing over
which editor to use!

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Wait Statement... ?

2004-07-20 Thread John W. Holmes
..: GamCo :.. wrote:
ok, i added the sleep() function in my page. what i'm basically doing is :-
i have a .php page where people log-in from. from there i send the form to
another .php page that actually checks the login and registers a session
with the username and password as session variables. then on the page that
actually does the validation, i have something that says : validating
login... sleep 1 funtion. then, i have another line that says validation
successfull... sleep 1 function and then i have another line that says
redirecting... with sleep 1 function and then header redirects to the actual
logged-in.php file. the redirect and validation works perfectly as well as
the sleep functions, but it now doesn't display the validating login... blah
blah blah stuff which is done in normal html code...
You are very confused. Read the manual page on header(). You can't have 
any output before you try to redirect with a header().

If you're trying to implement some sort of brute force protection by 
using sleep(), you're using it in the wrong method, anyhow. Your login 
processing script should sleep for a second or two whether the login is 
correct or not and it should be the first thing that it does (i.e. 
before any output or redirection). If you only sleep() on failures and 
redirect on good logins, brute force methods can pick up on that and 
adjust their methods to get around the wait time.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] howto get PK id after INSERT??

2004-07-20 Thread John W. Holmes
Vincent Jordan wrote:
I think I got it correct got the most part. I am having a problem with
the urlencode function I believe.
 
On page CustomerAddNew1.php ( page than handles form data ) im using:
 
$last_id = mysql_query(SELECT LAST_INSERT_ID() from customerinfo);
$last_id is now a Result Resource, not the value you're after. You must 
use mysql_result() or any of the mysql_fetch_*() functions to retrieve 
the value...

$lastid = mysql_result($last_id,0);
$last_id = urlencode ($last_id);
No need to urlencode an integer.
header(Location: UserMain.php?custid='$last_id');
You don't put quotes around values in the URL.
and on the UserMain.php page I am using this to return the data:
 
$cid = $last_id;
You called it custid in the URL, not last_id. All you need here is 
$cid = $cust_id although that's a waste of code. What you really want is

$cid = (int)$_GET['cust_id'];
so that now you know $cid is an integer and you're not opening yourself 
wide open to SQL injection attacks later.

ini_set('display_errors', 1);
error_reporting(E_ALL ~ E_NOTICE);
$connect = mysql_connect() or die (unable to connect to database .
mysql_error() . ); $select = mysql_select_db() or die (unable to
connect to database . mysql_error() . SPDATA); $result =
mysql_query(select * from customerinfo where custid='$cid') or die
The custid column is an integer, right? Why are you passing it a 
string by putting quotes around $cid?

(mysql_error(Unable to query database)); while ($row =
mysql_fetch_array($result)) { $firstname = $row['firstname']; $lastname
= $row['lastname']; snip
This whole process of $var = $row['var'], $var2 = $row['var2'] is a 
waste of resources. Why do you need to rename the variable? You already 
have $row['firstname'] as a variable, just use it. If you don't 
understand how to use an array when printing a string, then check the 
manual.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Wait Statement... ?

2004-07-20 Thread John W. Holmes
Daevid Vincent wrote:
Similarly, I could adjust my brute force attack to sleep() a pre-determined
amount of time too ;-)
Uhmmm.. how effective is a brute force attack where you can only try one 
combination per second? It's going to take you a while to get through 
that dictionary.

The whole 'sleep()' idea just seems silly. I agree with Jason. Just validate
and be done. A better way to stop attacks is to have a tally of failed
logins if you really are that worried someone is going to brute-force you.
Then after 3 fails, just don't let that IP connect or add other intelligent
handling. Maybe add them to a 'ban list' after x amount of failed tries. You
can get the $_SERVER['REMOTE_ADDR'] or use the session id or whatever.
You can still do this on top of the sleep() method. A one second wait is 
n't going to affect you when you log in to an application.

The problem with reacting after three failed logins is that it can then 
be easy to lock other people out of their account. You just have to 
figure out their username, which usually isn't that hard. Since IP 
addresses can be spoofed or shared among users of certain ISPs, relying 
on them isn't adequate, either.

I'm not saying using sleep is the solution to security problems, but 
it can be one layer of your defense.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Wait Statement... ?

2004-07-20 Thread John W. Holmes
Tim Van Wassenhove wrote:
In article [EMAIL PROTECTED], John W. Holmes wrote:
Daevid Vincent wrote:
Similarly, I could adjust my brute force attack to sleep() a pre-determined
amount of time too ;-)
Uhmmm.. how effective is a brute force attack where you can only try one 
combination per second? It's going to take you a while to get through 
that dictionary.

You're mistaken here. Every kiddie knows he has to fork 50 concurrent
threads that try to authenticate... 
That's still only 50 guesses a second compared to thousands when your 
server gives an immediate good or bad response. Like I said, this is 
just another layer you can add in addition to what you have below. It 
doesn't hurt anything if implemented correctly and it only serves to 
hassle those abusing the system. Defense in depth. :)

I'd suggest to have 2 queues for failed authentication attempts.
One containing (ip - timestamp) pairs,
the other containing (username - timestamp) pairs.
Every time someone tries to authenticate, you count the number of
failures in both queues. The larger the number, the longer the sleep
will take. (removing old entries once in a while might speed up things)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mysqli/Statement isn't valid anymore in x.php line #

2004-07-19 Thread John W. Holmes
Gilmore, Corey (DPC) wrote:
Is anyone familiar with what would cause an error like this:
Warning: Statement isn't valid anymore in includes\import.inc.php on
line 810
1. Which line is 810? That's going to really help someone determine why 
you may be getting this warning.

2. This is a warning, not an error. While annoying, it really can be 
ignored if the program actually works correctly. The warning can be 
hidden by using an appropriate error_reporing() level.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Re: Case sensitive search

2004-07-18 Thread John W. Holmes
Rui Cunha wrote:
i suggest you to use the LIKE operator instead of the relational operator.
You should try your suggestions before you.. er, suggest them:
mysql select 'a' like 'a';
+--+
| 'a' like 'a' |
+--+
|1 |
+--+
1 row in set (0.00 sec)
mysql select 'a' like 'A';
+--+
| 'a' like 'A' |
+--+
|1 |
+--+
1 row in set (0.00 sec)
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Not Like

2004-07-18 Thread John W. Holmes
Cole S. Ashcraft wrote:
I am trying to figure out how to display something where the condition 
is not like im a MySQL query. The query is

select * from class where classID like '_00'order by classID;

How would I make the like into a not like (aka negating it. The ! does 
not work)? I couldn't find anything in the MySQL manual.
SELECT * FROM class WHERE classID NOT LIKE '_00' ORDER BY classID
Do I get a doh! that was obvious prize?? ;)
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] PHP use in Federal Govt

2004-07-16 Thread John W. Holmes
Galbreath, Mark A wrote:
My division at State is trying to get PHP 5.0 approved for use by developers
in the Department, and the Powers That Be are requesting evidence that other
Federal agencies/military are using PHP, and the extent of it's use.
Anybody have a clue about this?  I sure would appreciate some help!
I use it extensively in my unit and know of others that are using it, 
too. I've made several PHP based programs (see 
http://www.bigredspark.com/survey) that are being used by the powers 
that be here. If you have any military that can get me on AKO, I can 
give more details.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Temporary table name

2004-07-16 Thread John W. Holmes
Rosen wrote:
I need to create temporary table in mysql. And I generate random name - i.e.
TMP21567. How can I check is this name already exist in database ?
If you're creating a true temporary table, then you don't need to worry 
about the name being unique.

CREATE TEMPORARY TABLE tmp21567 ...
Even if two PHP scripts run at the same time and issue this query, the 
temporary table is created on a per-connection basis and will not 
conflict with each other.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Temporary table name

2004-07-16 Thread John W. Holmes
Rosen wrote:
Yes, I'm creating temporary table to store temporary data and after thath I
delete this temporary table.
What is the longest table name (in chars) fo MySQL table name ?
How long does it exist for? If it's only used during the life of the 
script, then use TEMPORARY when you create it and you can use anything 
for the name. You don't have to worry about it being unique.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Temporary table name

2004-07-16 Thread John W. Holmes
Rosen wrote:
No, I don't use it only in range of one script - it must be as normal
table - several scripts to work with this table and after the last script
finish - it delete the table. This may take a time about 20-30 minutes (
until user enter data )
Okay. Use uniqid() to create a string for the table name. The only way 
you're going to know if it's duplicate is to either catch the error when 
you create the table or attempt to select something from it or show 
columns from it...

If you're using uniqid(), though, you shouldn't run into duplicates very 
often.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] session_start

2004-07-15 Thread John W. Holmes
Jason Wong wrote:
On Friday 16 July 2004 08:15, Steve Butzel wrote:
It appears that Apache/PHP still thinks the session.save_path is /tmp, even
though I changed this in php.ini-recommended and php.ini-dist. **What am I
doing wrong?**
Firstly, to see what your settings really are, use phpinfo(). Secondly, when 
you use phpinfo() you will see that the ini file you need to edit is called 
php.ini. Note the path and edit that file, if it's not there then copy one of 
php.ini-* there.
and actually rename it to php.ini, please. :)
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Getting a result from MAX() query

2004-07-13 Thread John W. Holmes
[EMAIL PROTECTED] wrote:
Would somebody be kind enough to explain why this query produces a false result
$latest=mysql_query(SELECT MAX(fee_recd) FROM members,$connectup)or die
(Query failed:br$latestbrError:  . mysql_error());
Would you be kind enough to tell us what text mysql_error() shows?
You probably just need to use an alias in your query:
SELECT MAX(fee_recd) AS max_fee_recd FROM members
and then you'll have $row['max_fee_recd'] when you fetch the value from 
your result set. Other wise you need to use $row['MAX(fee_recd)']...

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Mysql and rollbacks

2004-07-13 Thread John W. Holmes
Peter Westergaard wrote:
I'm developing a site where I anticipate the need to make several updates to
several forms, and I'll want to commit them all at once (i.e. if there's a
failure with any of the transactions, I'd like to be able to back out to
before I started).
Is there a decent way to do this with PHP and Mysql?  
Use InnoDB tables which have transaction support.
Or use a database abstraction layer that simulates transactions such as 
ADOdb: http://phplens.com/adodb/tutorial.smart.transactions.html

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Re: Mysql and rollbacks

2004-07-13 Thread John W. Holmes
Peter Westergaard wrote:
... or, am I barking up the wrong tree with Mysql, and should I change
database platforms?  (You'll never convince me to give up PHP though.
muahaha. Except for sql-level stored procedures where necessary, that is).
Maybe? :)
PostgreSQL and Firebird are two other open source free databases that 
have transaction support and stored procedures, IIRC. Check them out. If 
you run your own server, it's easy to get these. You may have trouble 
finding a hosting company consistently offering them, though.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Security Issues

2004-07-13 Thread John W. Holmes
Jonathan Haddad wrote:
so I've been doing a little thinking about web server security..
#1. Since all files on the web are 644, what is to stop someone on the 
same server from copying your files to their own directory?  
(specifically your database connection info)
#2. if a folder if 777, what's to stop someone from writing to that folder?
Answer to both questions is a combination of SAFE_MODE and open_basedir 
restrictions among other things discussed on the manual pages for those 
functions / features.

If those restrictions are not in place, then nothing is stopping someone 
 on the same server to read/write in your filespace with PHP.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Re: [PHP] Grab a range of rows from a mysql result

2004-07-13 Thread John W. Holmes
[EMAIL PROTECTED] wrote:
The resource is made up of 1000+ records from a mysql table that I am
breaking up to make my PHP application run faster.  I have figured out how
to compute the range but I dont know how to pull out a group of rows within
a range from a mysql result resource.
$query = SELECT * FROM yourtable WHERE range BETWEEN 400 AND 500;
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mysql auto increment

2004-07-12 Thread John W. Holmes
Michael Gale wrote:
I know this is more of a mysql question then php with 
 mysql but I can not find the answer. I have a primary
 key in a table the is setup and working with auto increment.
Now I want to change it so it will start auto incrementing 
 from 1000. So each entry will be:
First of all, why? There's no reason to do this.
Second, this link was just posted an hour ago or so. Check it out.
http://dev.mysql.com/doc/mysql/en/example-AUTO_INCREMENT.html
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Table locking

2004-07-08 Thread John W. Holmes
Rosen wrote:
I have the following situation: I have to prevent users to write at the same
time in one table in PHP script.
Is there a way the PHP to understand, thath another user is filling table,
and to wait before begin to fill data?
Most databases have a LOCK command that you can issue. The other scripts 
that end up running at the same time will wait until the lock is released.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] DB connections ?

2004-07-05 Thread John W. Holmes
Michael Gale wrote:
I am designing a web that will require access 
 to a specific database. I am also using sessions and
 am storing the session data in the database.
So on every page that loads there will be a connection 
 to the mysql server (local) to access the session db and
 tables and the web app database and tables.
My question is this would make two db connections per page 
 right ? one after another ? -- which would not be optimized
Would it be better to but the session tables in with the web app tables under a 
common database ?? At first I thought
that it would be more secure if the two where separate.
So long as you don't close the connection after you get your session 
data, the next call to mysql_connect() with the same parameters will 
realize there's already a connection open and use that.

Why not have a single include file that connects to your database, 
though? Then include your custom session hanlder which selects its 
database and retrieves the data. Then your main script selects it's 
database and does what it needs to do. Still one connection with less 
confusion.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] MySQL variable question

2004-07-03 Thread John W. Holmes
Chris Payne wrote:
I'm using MySQL 4's built-in Boolean handling abilities with PHP 4 which
works wonderfully, but I need to change:
ft_min_word_len
See here: http://dev.mysql.com/doc/mysql/en/Option_files.html
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] SELECT problem between MySQL 3.23 and MySQL 4

2004-07-02 Thread John W. Holmes
Chris Payne wrote:
  I'm using Booleans in my searches (New to it) but it works perfectly 
on my
local 3.23 version of MySQL, but on the main server which uses version 4 of
MySQL I get an error so there's an error in my Syntax.  Here's what I
currently use:
[snip]
LENGTH(REPLACE(LOWER(def),LOWER('as'),''))) 
[snip]
And here's the error I receive on the remote MySQL 4 server:

Warning: Bad arguments to implode() in
/var/www/html/www.planetoxygene.com/htdocs/funcs_mysql_boolean.php on line
45
You have an error in your SQL syntax. Check the manual that corresponds to
your MySQL server version for the right syntax to use near ') -
LENGTH(REPLACE(LOWER(),LOWER('as'),''))) /LENGTH('as'
This is not a MySQL 3 vs. MySQL4 issue. If it was, this is the wrong 
list, anyhow.

Take a look at the line of the query you _say_ you're running that I've 
included above and take a look at the last line of the error that you're 
getting from MySQL.

See the difference? Good... now troubleshoot.
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] new row object

2004-07-02 Thread John W. Holmes
Bob Lockie wrote:
I use $row = fetch_row_object, array_push($row) and I want to manually 
insert a row at the end of my array to indicate if there are more rows.

Is there a way to create a row object?
class row
{
  var $morerows = 'Yes';
}
$more = new row;
array_push($more);
about all there is too it, although I'm sure there is a better way to do 
whatever you're doing if you explained it more.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Query for Most Recent Entry

2004-07-02 Thread John W. Holmes
Thompson, Jimi wrote:
I'm trying to figure out how to write a MySQL query that will return the
highest primary key a table.  
1) Why?
2) SELECT MAX(id) FROM table
3) If you're trying to find the key of the last row inserted to an 
auto_increment column, use mysql_insert_id() or LAST_INSERT_ID() in PHP 
and MySQL, respectively.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mysql limit

2004-06-30 Thread John W. Holmes
Bob Lockie wrote:
If I select rows with a limit clause I need to know if there are more 
rows than the limit.
Either do a SELECT COUNT(*) prior to your LIMIT query to see how many 
total rows there are, or use SQL_CALC_FOUND_ROWS and FOUND_ROWS() (more 
info here: http://dev.mysql.com/doc/mysql/en/Information_functions.html)

oh, and
echo something about php;
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] $cookie error

2004-06-30 Thread John W. Holmes
Sukanto Kho wrote:
I'm using $_session to store user name and status
and the session is used as key to access some pages
and I set the cookie variables like this :
   setcookie (name,$user_name, $time+3600);
   setcookie (status,$status, $time+3600);
and the authentication of the session variable like this :
  if(!isset($_COOKIE['name']) or !isset($_COOKIE['status']) or 
$_COOKIE['status']!='user')
  {header(location:sign_in.php);exit;}
  else
  {$user_active=$_COOKIE['name'];$status=$_COOKIE['status'];}
But the problem is that sometimes when I link to (eg : product_add.php require 
$_session) it success but in the other time it's fail ..(although I do it continuous 
...I mean after the 1st time success and 2nd times fail)...
it couldn't be the problem of $_session lifetime ... I think.
I can't find why such problem occurs
$_SESSION and $_COOKIE are not the same thing. You seem to have them 
confused or are not explaining things very well.

on product_add.php print out the contents of $_COOKIE and $_SESSION 
using print_r() so you can track what's in them and how they are changing.

Cookies are tied to a domain, too. If you set a cookie on 
domain.com/product.php and then link to www.domain.com/product.php 
the cookie will not exist (unless you use the right parameters in 
setcookie()).

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Multiple word queries

2004-06-30 Thread John W. Holmes
Shiloh Madsen wrote:
say someone enters a search string of  cat dog mouse rabbit (without the
qoutes) into my search box. What I need for the results page to do is to
construct a query that will search through my keywords table for every
instance of ANY of those words. How would you suggest I handle this?
For that simple example, you can just explode the string on the space and
create a WHERE clause entry for each word.
For example:
$words = explode(' ',$_GET['search_text']);
foreach($words as $word)
{ $query .=  AND column LIKE '%$word%' ; }
Gets more complicated the more you want to parse the search text and is 
dependant upon what database you're using.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] $cookie error

2004-06-30 Thread John W. Holmes
Sukanto Kho wrote:
sorry, I was wrong ...
all the $session in my previous post should be $cookie... (I typed the wrong
word)
I think the domain is not the one that cause the problem...
remember that I refer to the same page (but sometimes success and the other
time it's fail)
What did u mean by unless you use the right parameters in setcookie()
Please more detail (I want to know if I miss something in setcookie
parameter)..
You can set the domain in setcookie() so that www.domain.com and 
domain.com will have the same cookies.

Note that if you use setcookie(), the cookie value isn't actually 
available until the next request. You should be using setcookie() before 
any output, also, but you'll get an error (or should) if you're not 
doing that right.

With some browsers, setting a cookie and then redirecting with header() 
will not make the cookies available on the next page. Maybe that's your 
issue?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] perfornance with POST or db check ??

2004-06-30 Thread John W. Holmes
Michael Gale wrote:
The question I have it .. on three of the select boxes .. if the data is
changed I require a extra function to get run. 

So for example if the owner value is changed I want to send a e-mail
to the new owner.
For performance should I just pass a hidden value with the original
owner and compare that with the owner value of the select box OR should
I do another db select to see if the field changed ???
I was thinking that passing a string would have less of a performance
impact ? then db activity. ?
It would, but the solution depends upon your users. Remember that a 
hidden field's value can be modified. So, if a user wanted to be 
malicious, they could set the hidden field to the new value matching 
what they select and your program would think that no change took effect.

Now, you could outsmart them and not actually update that column if the 
two values match. Then it wouldn't really do them any good to change the 
values because the database won't be updated anyhow.

The safest way is to just select the data before you make any changes 
and then compare it to what was submitted. The best way to do this, 
though, is to store the original values in the session when you first 
populate the form and then compare the submitted values to the session 
values. This way you're not actually adding a query (so long as you're 
using sessions already or aren't against adding them). The user can't 
modify the session values, so this method is safe.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] strange query

2004-06-01 Thread John W. Holmes
From: pete M [EMAIL PROTECTED]


 I'm running this query agains a mysql database, its a list of statuses 
 with a joined table that shows the number of job in that status with 
 more than 2. However I get the error
 
 Unknown column 'c' in 'where clause'
 
 select  job_stats.job_stat_id, job_stat, job_stat_code,
 count(works.job_stat_id) as c
 from job_stats
 inner join works on job_stats.job_stat_id = works.job_stat_id
 where c  2
 group by job_stats.job_stat_id, job_stat, job_stat_code
 order by job_stats.job_stat_order asc
 
 Any idead anyone please

Try having c  2 instead of where c  2

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] undefined function

2004-05-24 Thread John W. Holmes
From: Miguel Guirao [EMAIL PROTECTED]

 BTW, I have four different PHP.ini files in my system, where I can see
 which one is using it? I added it to all of them!!

phpinfo() will product a page that shows you what php.ini file PHP is using.
It's in the first block.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] how to reuse DB results

2004-05-20 Thread John W. Holmes
Aaron Wolski wrote:
Is there any way I can make a call to the DB for some records.
 Display some info from a column or two say at the top of the page and
then display the full result set in a while() loop?
Look for the seek() function of whatever database you're using, i.e. 
mysql_data_seek() to reset the results set.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] SQL Statement

2004-05-18 Thread John W. Holmes
Thompson, Jimi wrote:
So then I try do this  

?php
if ($fk_phone != NULL) {
$sqlwrk = SELECT `pk_phone_reports`, SUM(`calls`) AS `total_calls`,
 `date`, `calls` , `fk_ph_num` FROM `phone_reports`;
$sqlwrk .=  WHERE `pk_phone_number` =  . $fk_phone;
$rswrk = mysql_query($sqlwrk);
if ($rswrk  $rowwrk = mysql_fetch_array($rswrk)) {
echo $rowwrk[number];
}
@mysql_free_result($rswrk);
}
?
Note that this shouldnt work since it isnt a valid SQL statement.  
 I'm not sure why PHP doesn't return some kind of an error message.
PHP does return an error message, you're just not displaying it.
$rswrk = mysql_query($sqlwrk) or die(mysql_error());
$sqlwrk .=  WHERE (`pk_phone_number` =  . $fk_phone) AND 
 (`date` BETWEEN '$my_startdate' AND '$my_enddate');
Which brings me to my lovely parse error Parse error: 
You're not concatinating your string correctly.
$sqlwrk .=  WHERE (`pk_phone_number` =  . $fk_phone . ) AND
(`date` BETWEEN ' . $my_startdate . ' AND ' . $my_enddate . ');
or
$sqlwrk .=  WHERE (`pk_phone_number` = $fk_phone) AND
(`date` BETWEEN '$my_startdate' AND '$my_enddate');
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Select news based on dates

2004-05-17 Thread John W. Holmes
From: T. H. Grejc [EMAIL PROTECTED]

 I would like to display my news like this:
 
 *10.04.2004.*
 - news 1
 - news 2
 - news 3
 *14.04.2004.*
 - news 4
 *15.04.2004.*
 - news 5
 ...
 
 I'm thinking of some while loop but I'm not sure that it will work nor I 
 know how to create that query.

SELECT your data with the date and only display the date if it changes.

$query = SELECT * FROM table ORDER BY datecolumn ASC;
$result = mysql_query($query) or die(mysql_error());
$prevdate = '';
while($row = mysql_fetch_assoc($result))
{
  if($row['datecolumn'] != $prevdate)
  {
echo '*' . $row['datecolumn'] . '*br /';
$prevdate = $row['datecolumn']; 
  }
  echo '- ' . $row['news'] . 'br /';
}

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] upload files into MySQL database

2004-05-11 Thread John W. Holmes
From: PHPDiscuss - PHP Newsgroups and mailing lists
[EMAIL PROTECTED]

 I have problem for downloading files from MySQL database.
 Although I store and I see the filename and the extension in the database,
 when I try to download it, if there are blank spaces inside the filename,
 like my book store.doc
 I cannot open it and see it.

You shouldn't use spaces in file names.

Use urlencode() on the filename before you create a link to it.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] no temp var for mysql_fetch_array results

2004-05-11 Thread John W. Holmes
From: David T-G [EMAIL PROTECTED]

 $r = mysql_query($q,$dbro) ;
 $row = mysql_fetch_array($r) ;
 $i = $row[0] ;

$r = mysql_query($q,$dbro) ;
$i = mysql_result($r,0);

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Security Issues

2004-05-10 Thread John W. Holmes
From: Galbreath, Mark A [EMAIL PROTECTED]

 Does anybody know if the security issues outlined in

 http://www.securereality.com.au/archives/studyinscarlet.txt

 are still salient or not?  My boss wants a technical document outlining
the
 security risks of using PHP in an attempt to get it approved for general
use
 by Security.  I just bought Mohammed Kabir's Secure PHP Development
(Wiley
 2003) but would like some background white papers before delving into it.
 To that end, I'm using Google, but would appreciate references to any
recent
 documents covering the subject.

Yes, they are still relevant for the most part. There have been actions
taken to reduce some of them, though, like having register_globals OFF by
default, the move_uploaded_file() function, etc.

I would contend that these security issues are the fault of bad
programming, though, not the language. Some could argue that the langauge
should do more to get rid of these issues by default, though. I can't say
that I'd disagree with that, but I'd still hold the programmers responsible
instead of the language.

Bottom line, if you've actually read that page and implement what it says,
then you'll be fine. You can write completely safe programs without taking
any of the protective measures outlined on the site, though. You just have
to know what you're doing.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Dynamic Email Address in an HTML table

2004-05-09 Thread John W. Holmes
PHPDiscuss - PHP Newsgroups and mailing lists wrote:

How can I create the email address in the field as a hyperlink to the
email address? 
How would you create the link normally?

a href=mailto:[EMAIL PROTECTED][EMAIL PROTECTED]/a

right? Now if $row['email'] is equal to [EMAIL PROTECTED] or whatever 
you pull from the database, how would you do it? The same way...

echo a href=\mailto:{$row['email']}\{$row['email']}/a;
or
a href=mailto?=$row['email']??=$row['email']?/a
or
echo 'a href=mailto:'.$row['email'].''.$row['email'].'/a';
or
...
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals - www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] another strange MYSQL problem

2004-05-08 Thread John W. Holmes
[EMAIL PROTECTED] wrote:

First, I use this, and all is ok:

SELECT * FROM modele WHERE marca='Aprilia' ORDER BY tip ASC.

Then, I use this:

SELECT  * FROM modele WHERE marca='Cagiva' ORDER BY tip ASC

and the records are not ordered ascending by the field tip. In the
first case, the records were ordered. Anyone knows what is wrong?
Thank you!
 The first query works perfectly. The second returns no results. The
 data type for 'tip' is text.
Then you have no rows where marca is equal to 'Cagiva'...

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Insterting date in an MySQL table

2004-05-06 Thread John W. Holmes
From: charalambos nicolaou [EMAIL PROTECTED]

 I want to created a MYSQL table which will get the date in the form
 (-MM-DD) automatically. I have created the table below but it doesn't
 get the form of date that I want. It has the form (MMDDHHMMSS)

 CREATE TABLE questions1 (ID INT NOT NULL AUTO_INCREMENT,name
VARCHAR(30),day
 TIMESTAMP,question TEXT,email VARCHAR(30),answer TEXT, PRIMARY KEY(ID));

 Is there any other date field that gets the date form as I want?

TIMESTAMP and DATETIME columns are MMDDHHMMSS. DATE columns are MMDD
and TIME columns are HHMMSS.

Now, if you're looking for the features of a TIMESTAMP column (auto set to
current date/time upon insert/update), then you have two options. You can
make the column a TIMESTAMP(8) which will only store MMDD.  You can also
use DATE_FORMAT() when selecting your data to select the date formatted
however you want or use date() and strtotime() in PHP to format the date
from MMDDHHMMSS to whatever you want.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] looking for a variable

2004-05-06 Thread John W. Holmes
From: Robbie Staufer [EMAIL PROTECTED]
 $result = mysql_query (SELECT * FROM testdb WHERE Code_Name IN ('CLM',
 'CAM', 'CSIM', 'cpl5', 'POP'),$connection)
 is there a php variable that holds the number of elements in the ()
 after IN?

 I'm formatting the display in a browser window.  I need the second and
 consecutive elements to be indented below the first one.
 Something like this:
 echo element 0
 foreach additional element
 echo tab,element

Where are CLM, CAM, etc coming from? You're not going to get it from the
query, plain and simple. You're writing the query, though, so those values
have to come from somewhere.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] looking for a variable

2004-05-06 Thread John W. Holmes
From: Robbie Staufer 

 I supply those values.  Data associated with them 
 gets pulled out of the database and I need to format 
 them so that the first one is displayed differently than the 
 following ones.

Oh...

echo strongCLM/strong, CAM, CSIM, cpl5, POP;

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] MySQL Password() PHP encryption?

2004-05-06 Thread John W. Holmes
Theisen, Gary wrote:
I've recently upgraded my mysql to v 4.1.1 (on win nt 4.0) and set the
Passwords in the user table to the mysql Password() function. 

Now, this doesn't work anymore when call from a php web script (which is a
good thing, cause it's plain text): 

mysql_connect (localhost, theID, thePassord);
gives me this error: 

Client does not support authentication protocol requested by server ... 

Since my mysql.mysql user table now has the 41 bit encrypted passwords
stored...how to I connect with my php scripts? 

I've tried md5(), sha1()...but they don't generate the same 41 bit encrypted
password. 

Anyone have a suggestion? 
You need to use the mysqli extension with MySQL 4.1+
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] diference between == and ===

2004-05-03 Thread John W. Holmes
From: Bruno Braga [EMAIL PROTECTED]

 == means equality and what does the === means ?!

It matches the variable type, too.

$a = 1;

if($a == '1') = TRUE

if($a === '1') = FALSE

Most often used for function that can return a number including zero and
FALSE. If you're expecting a number to be returned and checking with

$a = somefunction();
if($a)

then it'll fail when zero is returned even though it's a valid value. So
you'd use

if($a === FALSE)

or

if($a !== FALSE)

to see whether the function truly failed or not.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] inserting same data into multiple tables question (?)

2004-04-30 Thread John W. Holmes
From: JeRRy [EMAIL PROTECTED]

 I want to input the same data into multiple tables in
 one query if possible.

It's not. You really have to question your database schema if you need to do
this.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] headers and if statements

2004-04-30 Thread John W. Holmes
From: matthew perry [EMAIL PROTECTED]

 ?if($logIn != 1) {header(Location: loginError.php);}?

 Why does this direct me to loginError.php even when $logIn = 1?

It doesn't. Double check your value of $logIn by printing it out or using
print_r/vardump/etc...

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] headers and if statements

2004-04-30 Thread John W. Holmes
From: Erik Meyer [EMAIL PROTECTED]

 Have you tried:
 ?php if (!$login=1) {header(Location: loginerror.php);)?

Uhmm... Have _YOU_ tried that???

= vs == ?

;)

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] SQL for Showing the number of queries served on each day.

2004-04-30 Thread John W. Holmes
Vern wrote:

I found this code below that allows me to retreive the queries served on my
server for each day but can't figure out how to actually display the
information using echo. Can some one give me an example using the following
SQL?
SELECT DATE_FORMAT(ex_date, '%Y %m %d %W'), COUNT(id)
FROM email
WHERE ex_dateNow()-INTERVAL 50 DAY
GROUP BY DATE_FORMAT(ex_date, '%Y %m %d %W')
ORDER BY DATE_FORMAT(ex_date, '%Y %m %d %W') DESC
You probably just need to use an alias.

SELECT DATE_FORMAT(ex_date, '%Y %m %d %W') as mydate,
  COUNT(id) as mycount
Then, you'll have columns called mydate and mycount in your result set.

Without knowing what database you're using, it's hard to give an example 
with exact code.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] converting scripts for register_globals=Off

2004-04-29 Thread John W. Holmes
From: Kim Jacobs (Crooks) - Mweb [EMAIL PROTECTED]


 I have written some scripts to access my online
 SQL db and I've tested the scripts on my machine
 with PHP 4.3.6 and register_globals = On
 Now where I host my site, uses PHP 4.3.5 and has
 register_globals = Off which means of course, that
 my scripts arent working, but I dont know why

 My question is, how do I convert my scripts so that they
 will work please? I know that $id and $submit are two
 of the 'inputs' that it doesnt like, but I dont know the rest

If your program is well written, you can get away with just switching $id
for $_REQUEST['id'].

This is assuming you already properly validate and sanitize all of the data
coming from the user. Using $_REQUEST['id'] doesn't make anything more or
less secure, it's a matter of what you're doing with the data coming from
the user.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] From mysql to mssql...

2004-04-29 Thread John W. Holmes
[EMAIL PROTECTED] wrote:
I've been given a one page project to do, that needs to add the 
contecnt of a form to an mssql database...

I'm fine with doing all the page, apart from talking to mssql... how 
drasitally does this differ from the standard mysql functions tha tI 
use..?
There's not much of a difference (with regards to the php functions). 
I'd recommend you get into the habit of using ADOdb or PEAR::DB so that 
even if you do switch databases like this, you still have a familiar 
syntax.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Session

2004-04-27 Thread John W. Holmes
From: Ng Hwee Hwee [EMAIL PROTECTED]

 okie, my 'session.gc_maxlifetime' = 1440 and session.gc_probability = 1.

 so, should I change it to something like 43,200 (12hours*60mins*60sec)??
 for example, one person works a maximun of 12 hours a day. But does
 it mean that by lengthening this value, the session will still be kept
even
 if the user closes his browser??

Setting your gc_maxlifetime to that means that the server will not delete
the users session data files until they are over 43200 seconds old, meaning
the user hasn't requested a page in over 12 hours.

The session does not exist past the point of closing the browser unless you
increase the lifetime of the session cookie itself. I would recommend you
just leave it at zero, though, meaning it only persists for as long as the
browser window is open. The longer you make the sessions last, the easier it
is for someone to hijack them.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Session

2004-04-27 Thread John W. Holmes
From: Hans Lellelid [EMAIL PROTECTED]

 - keep your gc_maxlifetime as small as possible; that way if a user does
 close their browser their session won't remain active for 12+ hours.
 You might want to consider ways of periodically refreshing the page
 using an iframe or even just a meta refresh... solution.  That will
 address the need to stay logged-in while the browser is open, while also
 allowing you to have a very brief session lifetime.

Excellent points, Hans.

One other thing to add. When a user requests a page and you determine that
their session is not valid (probably because they've been inactive too long
and the garbage collection deleted their session file), start a new session
and store the filename and query string of the request before you redirect
back to the login page. Then, after you validate any login, check for the
existance of a saved page and query string and redirect there instead of
your page page.

The end result is a lot cleaner for the user. Sure, they'll have to log in
again, but they'll be redirected right back to the page they requested,
anyhow. You end up with shorter session files making hijacking harder and
less frustration from the user having to navigate back to wherever they
were.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Cursor in text box.

2004-04-27 Thread John W. Holmes
matthew perry wrote:
My users complain about everything. The most common is Why do I have to 
move the mouse over to this box every time?  Wh!
How do I get the cursor to que into the first input area of my form?
JavaScript, not PHP.

document.yourform.yourtextbox.focus(), I think.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Scrolling drop down menu

2004-04-27 Thread John W. Holmes
matthew perry wrote:

When my users choose an option in the drop down menu, they sometimes 
accidentally change what they have chosen when the move the center 
scrolling button of their mouse. I was giving a presentation in front of 
my company's owner and did this myself. 5 or so index fingers instantly 
pointed at me saying See you do that to!  Wh!
Is there a way to stop a menu from scrolling with the center scrolling 
mouse button?
Your questions have nothing to do with PHP.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] more detail..passing array_var with $_get

2004-04-26 Thread John W. Holmes
From: Sukanto Kho [EMAIL PROTECTED]

 My problem is I want to pass var array with $_get..
 
 eg : $a=array()  then i pass to other pages www.main.com?b=$a
after that echo $b
the result is array... just that...

$safe = urlencode(serialize($a));

$url = http://www.main.com/?b=$safe;;

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] How to display table columns

2004-04-25 Thread John W. Holmes
andy amol wrote:
hi,
  I want to display the table coulumns along with those values below it. I am only able to display the table values, now I want to diplay the corresponding table attribut above the value.
 
eg : name age sex
   abc1m
   xyz 2f
 
I want to display name, age and sex.
http://us2.php.net/manual/en/function.mysql-field-name.php

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Inserting date into a table

2004-04-24 Thread John W. Holmes
Pambos Nicolaou wrote:

I have created the table below:

CREATE TABLE questions (ID INT NOT NULL AUTO_INCREMENT,name 
VARCHAR(30),day TIMESTAMP, question TEXT, email VARCHAR(30),answer TEXT, 
PRIMARY KEY(ID));

I want to insert into the TIMESTAMP field the date automatically. How 
can I do it using the  insert command

INSERT INTO $table 
VALUES('','$name','TIMESTAMP','$question','$email','NULL');
Two ways:

1: INSERT INTO $table (name, question, email) VALUES 
('$name','$question','$email')

This way, the ID and TIMESTAMP columns will be populated automatically. 
The ID column will get the next available number and the day column 
will be assigned the current date/time. Note how you can leave out the 
answer column, too, since you weren't assigning a value to it, anyhow. 
It will be given the default value of the column, which in this case is 
NULL.

2: INSERT INTO $table (name, day, question, email) VALUES 
('$name',NULL,'$question','$email')

Setting the TIMESTAMP column to NULL will cause it to be set to the 
current date/time. This works for the first TIMESTAMP column in a table 
(since you only have one, it doesn't matter).

I recommend method 1.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Re: [PHP] Adding includes to files

2004-04-22 Thread John W. Holmes
From: Robert Sossomon [EMAIL PROTECTED]

 I need to add PHP calls to include a file to each page as it is
 generated, the only thing is I can't get the includes to come through
 correctly:
 
 ! Code
$display_block .= ?php include(\nav/top_nav.html\); ?;
$display_block .= ?php include(\nav/side_nav.html\); ?;
 ! End Code
 
 At the end of the generation I write $display_block to a file as

You can use output buffering:

ob_start();
include(nav/top_nav.html); 
include(nav/side_nav.html); 
$display_block = ob_get_contents();
ob_end_clean();

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: [PHP] What's wrong with this IF statement?

2004-04-22 Thread John W. Holmes
From: Robert Sossomon [EMAIL PROTECTED]

   if ($cat_id != 53 || $cat_id != 54 || $cat_id != 55 || $cat_id
 != 117 || $cat_id != 118 || $cat_id != 74)

Okay, if $cat_id is 53, this will work out to:

if(FALSE || TRUE || TRUE || TRUE || TRUE || TRUE)

which results in TRUE overall. 

You want  instead of ||

if ($cat_id != 53  $cat_id != 54  $cat_id != 55  $cat_id
!= 117  $cat_id != 118  $cat_id != 74)

which results in

if(FALSE  TRUE  TRUE  TRUE  TRUE  TRUE)

which results in FALSE overall.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Inserting a date in to DATE field

2004-04-22 Thread John W. Holmes
Pambos Nicolaou wrote:

Is there any MySQL command which inserts the date into a DATE field of a 
table automatically. For example the user inserts into the table several 
values (name, age, etc) and the date is inserted automatically.
Set the column equal to NOW() or use a TIMESTAMP column (which will be 
set to NOW() when the row is created or updated unless you specify a 
specific value).

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Drop-down box in php

2004-04-21 Thread John W. Holmes
From: andy amol

I am using the following code, but it is not populating my script. If
you can help I would be grateful.
   I am using mysql as database.
 ?
 $sql = SELECT course_id FROM course;
 $sql_result = mysql_query($sql)
 or die(Couldn't execute query.);
 while ($row = mysql_fetch_array($sql_result)) {
 $type = $row[course_id];
 $typedesc =$row[dept_id];
 $option_block .= OPTION value=\$type\$typedesc/OPTION;

You're using [dept_id], but not selecting that column in your query.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Drop-down box in php

2004-04-20 Thread John W. Holmes
From: andy amol [EMAIL PROTECTED]

I would like to know how to create and populate drop down boxes in php.
 I want the value to be populated from database.
 What I am try to do is to provide the forign key value as combo box
option, so that I do not have to check for referential integrity.

You still have to check. Just because you provide a discreet number of
options in a select box doesn't mean that's really all the user can choose
from. There are many ways to manipulate the data.

That being said, just create a loop as you draw items from your database.

?php
echo 'select name=something size=1';
$sql = SELECT name FROM products WHERE ...;
$result = query($sql);
while($row = fetch_assoc($result))
{ echo option value=\{$row['name']}\{$row['name']}/option\n; }
echo /select;

I don't know what database you're using, so query() and fetch_assoc() are
generic.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Displaying Date from Value in MySQL DB

2004-04-20 Thread John W. Holmes
From: Justin @ Dreaming in TO [EMAIL PROTECTED]

 SELECT ditoevents.eventstatus, ditoevents.eventdate,
 DATE_FORMAT(ditoevents.eventdate, '%a, %b %d %Y'), ditoevents.eventtime,
 ditoevents.eventlocation, ditoevents.topic, ditoevents.presenter
 FROM ditoevents
 WHERE ditoevents.eventstatus = 'next'

Use an alias:

SELECT ditoevents.eventstatus, ditoevents.eventdate,
DATE_FORMAT(ditoevents.eventdate, '%a, %b %d %Y') AS myformatteddate,
ditoevents.eventtime,
ditoevents.eventlocation, ditoevents.topic, ditoevents.presenter
FROM ditoevents
WHERE ditoevents.eventstatus = 'next'

Then display $row['myformatteddate'] when you're displaying the data.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] about unsecure connection to mysql

2004-04-14 Thread John W. Holmes
Sukanto Kho wrote:

I've created a file named 'connection'(used to connect to mysql server)...

This file connect to mysql server with user=root en password inserted

The problem is user name (in this case root) and password appeared in
file...
so that anyone who get the file may know what the password and user name
is...
Are there any solution to more secure connection??
1. Put the file outside of your web root
2. Deny access to the file using .htaccess
3. Give the file a .php extension so people will only get the _result_ 
of the file (which if it just contains variables, the result will be 
empty).

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Pass database id through href

2004-04-13 Thread John W. Holmes
Gavin Amm wrote:

EXAMPLE:
(I know you can't use value with the a tag, but bear with me for
illustration purposes in this pseudo-code)
form name=theForm

input type=text name=title
!-- etc with the fields --
input type=text name=formInput
a href=javascript:document.theForm.submit(); name=parent
value=23Auditing Home/a
a href=javascript:document.theForm.submit(); name=parent
value=17Finance Home/a
a href=javascript:document.theForm.submit(); name=parent
value=122Planning Home/a
a href=javascript:document.theForm.submit(); name=parent
value=231Tax Home/a
/form

When the admin clicks on one of the parent hyperlinks, the form is
submitted with (in this example) (say they click on the Tax Home link)
the values:
  $title == [whatever the user types into the text field]
  $parent == 231
How do I get this $parent value from the html page??
Instead of calling theForm.submit(), all another function that sets a 
form variable before submitting the form.

a href=javascript:mysubmit(231);Tax Home/a

script
function mysubmit(var)
{
  document.theForm.parent.value = var;
  document.theForm.submit();
}
/script
parent might be a reserved word, so watch out for that. I'm no JS wiz, 
but I think that's something along the lines of what you want to do. You 
basically use JS to add a form element based upon what link was clicked.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] File there or not?

2004-04-07 Thread John W. Holmes
From: Robert Sossomon [EMAIL PROTECTED]

 My question:
 How do I pull the item and turn it to lower? Strtolower?   

strtolower()
 
 How do I check it against a directory to see if the file exists?

file_exists()

Imagine that. :)

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] File there or not?

2004-04-07 Thread John W. Holmes
From: Robert Sossomon [EMAIL PROTECTED]

 Oh well, thanks for the kick in the pants and commands!

That's what I'm here for, to get into pants... or something... um, back to
work.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] HELP: mySQL table name

2004-04-06 Thread John W. Holmes
From: Adrian Donoiu [EMAIL PROTECTED]

 I need information about how can I get the table name from this query :
  select * from test_table as t
 when I use :
  $field=mysql_fetch_field($result, $i);
$field-table return the name of the table as t but I need the real
 name of the table test_table.
 How can I do it?

You can't. If you alias the table as t, then that's the table name. Either
don't use an alias or write a function that'll parse the query to retrieve
the table name.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Graphing - bar charts

2004-04-06 Thread John W. Holmes
From: Craig Hoffman [EMAIL PROTECTED]

 I am looking for an open source and simple PHP script that will graph
 (bar) a few MySQL fields.  Does anyone have any recommendations?

The easiest way is to just have an image that you dynamically vary with
width of

img src=dot.jpg height=10 width=$width

Or take a look at JPGraph, which offers a lot of features.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] How to troubleshoot MySQL Error 1040: Too many processes

2004-04-06 Thread John W. Holmes
From: John Hicks [EMAIL PROTECTED]

 Twice recently my little homebrew PHP/MySQL content
 management system has essentially crashed when MySQL
 starts returning a 1040 error: Too many connections.
 Restarting MySQL fixes things ... for a little while
 at least.
[snip]
 Most of my connections are made with PHP's
 mysql_pconnect.

I wouldn't use mysql_pconnect for this vary reason. Read through some of the
user comments on the manual page and it's explained in detail. Try with
mysql_connect(), first.

You can raise the number of connections (default is 100) using a my.cnf file
(explained in MySQL manual), but if you're not getting the actual traffic to
produce 100 simultaneous users, then that's not the issue.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] checkboxes and loops

2004-03-29 Thread John W. Holmes
matthew perry wrote:

input type = checkbox name = box?echo $counter;? value = delete
$counter++;

*Bad solution 2 (doesn't work)***
$counter = 1;
while (whatever)
{
if ($box . $counter == 'delete')   do whatever
$counter++;
}
***
if(${$box . $counter} == 'delete')

However, like someone else said, if you named your checkboxes as box[1], 
box[2], etc, then you'd have a nice $_POST['box'] array that you could 
loop through.

foreach($_POST['box'] as $count = $value)
{ do_whatever($count); }
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mysqli - using PREPARED STATEMENTS - worth it?

2004-03-29 Thread John W. Holmes
PHP freak wrote:

Looking at this page:
http://us2.php.net/manual/en/function.mysqli-prepare.php
Also the new book ADVANCED PHP PROGRAMMING uses 
the new MySQLi Prepared Statements for all queries.

Wondering if that extra code, trouble, and lack 
of flexibility is worth it? Will it be a HUGE 
performance increase that will be worth those 
added lines of code for every single query?
I don't know if the queries are compiled when you prepare them or not, 
but if they are, that could be a large performance increase.

Also, I believe the point to prepared statements is for security. The 
parameters you bind to the query will be escaped and validated (?) to 
be the correct type.

Can anyone back this up?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mysqli - using PREPARED STATEMENTS - worth it?

2004-03-29 Thread John W. Holmes
PHP freak wrote:

Looking at this page:
http://us2.php.net/manual/en/function.mysqli-prepare.php
Read this, too: http://www.zend.com/php5/articles/php5-mysqli.php

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] DATE_SUB Issues

2004-03-29 Thread John W. Holmes
From: Craig Hoffman [EMAIL PROTECTED]

 still no luck - any other suggestions?

Please define no luck

---John Holmes...


 On Mar 29, 2004, at 8:18 AM, John W. Holmes wrote:
  From: Craig Hoffman [EMAIL PROTECTED]
 
  Perhaps someone could lend me a hand here on this query.  I have a
  query where I would like it to SUM up the last 7 days of records
  further, It needs  to start a new week on Monday. The 'time_upload'
  field is a  datetime field. What am I doing wrong or not doing here ?
 
  SELECT SUM(distance), DATE_FORMAT('time_upload', '%u'),
  WEEK('time_upload', '7') FROM TRAININGLOG WHERE 
  DATE_SUB(NOW(),INTERVAL
  7 DAY )
   =time_upload
 
  If time_upload is a column, it should not be between single quotes in 
  the
  WEEK() function.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] exporting data to excel

2004-03-24 Thread John W. Holmes
matthew perry wrote:

I am looking for the easiest way to export data to an excel file.  Is 
the easiest way to use PHP's file handling functions?
Easiest way is to just send Excel headers and output an HTML table. 
Excel will convert it to a spreadsheet.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mySQL Parse Error

2004-03-22 Thread John W. Holmes
Nadim Attari wrote:

insert into cashmire ('itemcode', 'collection', 'promotion', 'bestSeller',
You should not have quotes around the column names.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] escape chars continued

2004-03-22 Thread John W. Holmes
From: matthew perry [EMAIL PROTECTED]

 Actually I think the problem is before you can use either addslashes or
 mysql_escape_string() functions.  The value with  or ' never reaches
 the database.  I think I need a way to ignore quotes for input values in
 HTML.

 Say I have this:
 input type=text size = 2 name=Q
 And my user enters:2  copper tubing
 The value for Q will be: 2

No, the value of $Q will still be 2  copper tubing, but if you tried to
show that value inside of a text box again, you'd lose everything after the
second quote, because you end up with this:

input type=text size=2 name=Q value=2  copper tubing

HTML interprets the value as 2  and the rest of the value as an
unrecognized attribute.

The solution is to run htmlentities() on the value to convert double quotes
into quot; so you end up with

input type=text size=2 name=Q value=2 quot; copper tubing

Which will appear correctly to the user.

Note that if you deal with text that's going to be shown on HTML pages,
running the text through htmlentities($value,ENT_QUOTES) will prevent the
text from being used for cross site scripting and SQL injection.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] RE: escape chars continued

2004-03-22 Thread John W. Holmes
From: Brock Jimmy D Contr DODHSR5 [EMAIL PROTECTED]

 When you want to display this value from the database onto your webpage
use stripslashes

 stripslashes($row['q']; // this will remove the backslash that was
inserted from addslashes

You don't need to use stripslashes on the data pulled from the database
unless magic_quotes_runtime is on. If It\'s okay is inserted into the
database, the backslash is only there to tell the database that a literal
single quote follows and not the end of the string. The data is stored as
It's okay in the database. If you ever see It\'s okay actually within
your database, then you are running addslashes/escape_string twice!

Also, if you want to display $row['q'] on your web page or within a form
input element's value attribute without creating cross site scripting
vulnerabilities, then run it through htmlentities() first. Use ENT_QUOTES
for the second parameter to encode both double and single quotes that way if
you use either in your SQL queries or form elements, you'll be safe, also.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Date Manipulation

2004-03-21 Thread John W. Holmes
Shannon Doyle wrote:

My question, how do I get the date entered into the form add 35days to it
and then include that into the same sql query as the first one. Or do I have
to use a second sql query? If the second query how would I get the date and
add 35days??
INSERT INTO table (date1, date2) VALUES (20040321, 20040321 + INTERVAL 
35 DAY)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] MySQL category tree db sorting

2004-03-19 Thread John W. Holmes
From: Age Bosma [EMAIL PROTECTED]

 I'm trying to work out what the most efficient way will be to get the
 complete tree structure from top to bottom of a category tree db.

Search the archives or Google for nested sets. That's going to be the most
efficient database scheme to use. Any parent-child-relationship solution is
going to require a lot of queries when your trees get large.

I second the recommendation for SQL for Smarties by Joe Celko, too.
Excellent book.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Stuck on basic concept, how to use a list selection?

2004-03-19 Thread John W. Holmes
From: Doug F [EMAIL PROTECTED]

 Populate a dropdown list with values from a MySQL db (done and working).
 Use the selected value as the 'where' clause in a second query.
 Return the results and display them to the user.

 Any pointers are appreciated - noob^3 (html, mysql, and php).

 Doug

 Code that I'm using:

 html
 body
 ?php

 // connect to db
 $db = mysql_connect(localhost);
 mysql_select_db(test,$db);

 // build query
 $sitequery = SELECT site from sitedata order by site;

 // generate result set
 $siteresult = mysql_query($sitequery);

 // use results
 echo Select a site from the list below: brbrselect name='site';
 while($siterow = mysql_fetch_array($siteresult))
 echo option value='.$siterow[site].'
 $siterow[site]./option;
 echo /select/td;

When the form is submitted, the value chosen will be in $_REQUEST['site']
(or $_GET['site'] or $_POST['site'], depending upon your form method).

Then just create your query:

$query = SELECT * FROM sitedata WHERE site = '{$_REQUEST['site']}';

If magic_quotes_gpc is not ON, then you'll want to run mysql_escape_string()
on the value first.

$site = mysql_escape_string($_REQUEST['site']);
$query = SELECT * FROM sitedata WHERE site = '$site';

See the recent threads on SQL Injection for a reason why. :)

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Stuck on basic concept, how to use a list selection?

2004-03-19 Thread John W. Holmes
From: dogu [EMAIL PROTECTED]

 I'm still not quite there, I can see the misty shape of a solution but
 the details are still a bit hazy.

 The code I posted it the whole shebang.  I've made some attempts to
 'form enable' it, but can't figure out where to put the form.../form,
 and submit stuff so the entire thing renders as a form and creates the
 variable you describe.

Well, I think it's a little out of the scope of this list to explain forms
and HTML to you. You need a second page that your form is going to be
posted to that'll receive the value the user has selected. Then on this
second page you create a second query with the value the user selected to
pull the specific data. If anyone just writes the whole thing for you,
what'll you learn? :)

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Selecting one row by random, where a column is set

2004-03-19 Thread John W. Holmes
Mathias Hunskår Furevik wrote:

I've got the SQL line: $sql = SELECT * FROM shop_items ORDER BY RAND() 
LIMIT 1;

I've got a column which is called image_large. The tricky part is, not 
all of the image_large rows exists. Whis the query above, I want to get 
only a row where image_large is present.
So add a WHERE clause...

SELECT image_large FROM shop_items WHERE image_large != '' ORDER BY 
RAND() LIMIT 1

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals - www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Stuck on basic concept, how to .. here's how

2004-03-19 Thread John W. Holmes
dogu wrote:

Figure out a way to pass the db connection to the 2nd file rather than 
reconnecting.
You can't pass resources. You connect on each PHP page. Put _that_ in a 
function to make it easy. :)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] MySQL - separating web and database servers

2004-03-18 Thread John W. Holmes
From: Operator [EMAIL PROTECTED]

 Probably I need to change this behaviour in
 ext/mysql/libmysql/libmysql.c for my installation, but this is
 my last hope (mostly because I'm not a C programist...) If some
 of you could tell me if it's possible without breaking
 something else, or point me to the lines that do the job... I
 suppose the change needed would be quite simple.

Why are you fighting the obvious so hard? You're not connecting to
localhost by any means so just suck it up and realize that you'll need to
change the code. How are you going to carry all of these hacks over when you
upgrade servers or MySQL versions or put in load balancing, etc, etc...

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] MySQL Multi-DB Join

2004-03-18 Thread John W. Holmes
From: Rod Strumbel [EMAIL PROTECTED]

 If you can select just one db, then what is that
 select_db command really doing?

All it's doing is issuing a USE database query so you can say

SELECT * FROM table

instead of

SELECT * FROM database.table

You want to use select_db() so that you don't have prefix all of the tables
in your queries with a database name.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Connect to MSDE using PHP

2004-02-22 Thread John W. Holmes
I've downlownded and installed the Desktop Edition of MSSQL and am 
trying to connect to it with PHP. Has anyone ever accomplished this?

I've uncommented the line in php.ini to load the MSSQL functions and 
they show up on a phpinfo() page, so that part is good.

When I installed MSDE I tried it without a named instance first and just 
set an SA password.

Neither of these worked:
mssql_connect('localhost','sa','password')
mssql_connect('coconut','sa','password')
where coconut is the name of my computer.

Then I tried installing MSDE again with a named instance and tried

mssql_connect('namedinstance\localhost','sa','password')
mssql_connect('namedinstance\coconut','sa','password')
and those wouldn't work either. The only response I get is failed to 
connect to server ...

I'm off to try ODBC. Anyone have any suggestions?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Connect to MSDE using PHP

2004-02-22 Thread John W. Holmes
Robert Twitty wrote:

I have never used MSDE, but from my understanding if is suppose to behave
like SQL Server.  When you installed it, did it mention anything about
whether or not TCP/IP connectivity should be supported? You may need to
ensure that the server is communicating over port 1433.  If you are
unsuccessful with either mssql or odbc, then you should try the odbtp
extension at http://odbtp.sourceforge.net. If you use odbtp, use (local)
for the SERVER parameter.
I was able to get it to work through ODBC both using the ODBC functions 
in PHP and through ADOdb, so I guess I'll have to settle for that. I 
just want an MSSQL test environment (for free) that I can use to develop 
scripts on.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals . www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Stored procedure with UNION---no unique id, how to page?

2004-02-19 Thread John W. Holmes
Karen Resplendo wrote:

I have a stored procedure in msSQL that UNIONs 3 queries. 
There is no unique identifier that is sequential that I can
use to page on webpage because the data comes from different
tables/databases.
Would you be able to use mssql_data_seek() to jump to the result set row 
that you want to start with? You'd have to execute the whole SP each 
time, but then jump to the row (page) that you want and start retrieving 
rows. mssql_num_rows() will give you the number of rows, too.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] sql, grouping problem

2004-02-16 Thread John W. Holmes
mayo wrote:

 cold fusion allows you to group output (see below)

  Select c.classId, c.classTexts, c.classDescription,
  cc.classCodeSection, cc.classDate, cc.classTime,
  cc.classLocation, cc.classInstructor
  FROM CLASSES c, CLASSCODES cc
  WHERE c.classId = cc.classId
  AND ...
  ORDER BY c.classId, ...
  cfoutput query=myQuery group=classId
  	#classTitle#
  	#classDescription#br...
  cfoutput
  
#classCodeSection#br
#classDate#br
#classTime#br

  /cfoutput
  /cfoutput
I can't figure out how to do this in php.
You just have to remember the value of the classID as you loop through 
the results, and only show the header row when the classID changes.

//Empty classID
$old_classID = '';
//Loop through results
while($row = mysql_fetch_assoc($result))
{
  //show title and description when
  //classID changes
  if($row['classID'] != $old_classID)
  {
echo trtd colspan=\3\{$row['title']}/td/tr;
echo trtd colspan=\3\{$row['description']}/td/tr;
$old_classID = $row['classID'];
  }
  //show rest of data
  echo trtd{$row['code']}/td;
  echo td{$row['section']}/td;
  echo td{$row['location']}/td/tr;
}
The logic is that the title and description rows are only shown when 
classID changes in the result set. I showed it using MySQL functions, 
but that can apply to any database/abstraction layer you've got running.

Hope that helps.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Need SQL Help

2004-02-12 Thread John W. Holmes
From: J. Kevin C. Burton [EMAIL PROTECTED]

 I have a SQL statement that looks like this:
 SELECT EMPLOYEENAME,SUPERVISORID WHERE EMPLOYEEID='$employeeid'

 what I want to do is lookup the supervisor's name in the same SQL
 statement. If not, I would have to use an function, and if I have a 100
 employee's in the list, that takes an enormous  amount of time if I have
 to load that function every row.

 Is there a way to do it all in the same 1 SQL statement?

Is this a Parent-Child type relationship, where the supervisor ID is
actually just another employee ID in the same table? If so, you could do it
like this:

SELECT t1.employeename, t1.supervisorid, t2.employeename as supervisorname
FROM employees t1, employees t2 WHERE t1.supervisorid = t2.employeeid NAD
employeeid = '$employeeid'

If that's not your table structure, then you'll have to tell us what it is.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Building A Query

2004-02-11 Thread John W. Holmes
From: Benjamin Jeeves [EMAIL PROTECTED]

 I have a form with a number of checkboxs on it and
 what I would like to be able to do is build a query
 base on the checked checkedboxes.

All depends on what you're actually doing, but I assume each checkbox is
related to a row in the database? And each row as a unique identifier (like
an auto_increment number)?

If you name you checkboxes such as box[] and put the unique identifier as
the value, it's easy to build a list of checkboxes that were checked.

input type=checkbox name=box[] value=1
input type=checkbox name=box[] value=2
input type=checkbox name=box[] value=3

You can now build a query such as:

?php
if(isset($_POST['box']) AND is_array($_POST['box']) 
!empty($_POST['box']))
{ $query = 'SELECT * FROM table WHERE id IN (' . implode(',',$_POST['box'])
. ')'; }

You may want to actually loop through $_POST['box'], though, and validate
each value as a number, string, etc, before you stick then in your query.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Question

2004-02-09 Thread John W. Holmes
From: [EMAIL PROTECTED]

 Parse error: parse error, unexpected $end in C:\webroot\display.php on
line
 131

I'm not going to go through all of your code, but this error means you
missed a quote or bracket somewhere, i.e. you didn't supply a closing
bracket for an IF() condition.

?php
if($condition == 1)
{
  dothis();
?

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Help with an UPDATE query please

2004-02-05 Thread John W. Holmes
  I have (among others) two DATE columns in a table; Booking_Date and
  Booking_Completion_Date. How can I run a query that updates
  Booking_Completion_Date to be 2 days after Booking_Date where
  Booking_Completion_Date is NULL?

UPDATE table SET Booking_Completion_Date = Booking_Date + INTERVAL 2 DAY
WHERE Booking_Completion_Date IS NULL;

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] multiple fields all unique?

2004-02-04 Thread John W. Holmes
From: Jas [EMAIL PROTECTED]

 Now I have used the following to check if duplicate records exist before
 updating:

 ?php
 // Try and update with posted fields form html form
 $update = mysql_query(UPDATE hosts SET hostname='$_POST[hostname]',
 mac='$_POST[mac]', ip='$_POST[ip]', vlan='$_POST[vlan]' WHERE
 id='$_SESSION[id]',$db);
 $rows = mysql_affected_rows();

 // Check results of operation
 if($rows == 0) {
echo No matching records found;
 } else {
echo Matching records found; }

 Hope this helps anyone else, and thanks for the tip on MySQL's UNIQUE
 field, wish I would have known it sooner, I wouldn't be so pissed off
 from frustration.

One thing to note here, also... if you update a row with the same exact
information, mysql_affected_rows() will return zero. So, even though a row
is matched and updated, nothing is really affected. Not sure if that
matters here, but something to be aware of.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] multiple fields all unique? [almost solved]

2004-02-04 Thread John W. Holmes
From: Jas [EMAIL PROTECTED]

 for instance, say you change the mac and hostname and there is a record
 in the database with the same mac string, how can I flag the field that
 matched from the 3?

Your update will actually fail in the case, so you need to catch the error
with mysql_error() (and maybe mysql_errno()) and examine it to see which
key (or index) was matched (a unique column is an index).

When you update the table with an existing mac value, the error will be
similar to Duplicate value for Key XX where XX is what key was duplicated.
I can't remember if the keys start at zero or one, but your ID column will
be the first key, then mac, hostname, and finally ip (in the order they were
created).

So, if you examine the result of mysql_error() and it say duplicate for key
2, then the mac column was duplicated.

Although this sounds a little harder than doing a SELECT prior to and just
comparing values, it lets you do this with just a single query and only have
extra processing upon errors instead of every single update.

If you need a working example, let me know.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] multiple fields all unique? [almost solved]

2004-02-04 Thread John W. Holmes
From: Jas [EMAIL PROTECTED]

 If I do this statement:
 mysql_query(UPDATE hosts SET hostname=\$_POST[hostname]\,
 mac=\$_POST[mac]\, ip=\$_POST[ip]\, vlan=\$_POST[vlan]\ WHERE
 id=\$_SESSION[id]\,$db)or die(mysql_error() . mysql_errno());

 I get this error:
 Duplicate entry '128.110.22.139' for key 41062

 I have tried using these types of checks with no success:
 $update = mysql_query(UPDATE hosts SET hostname=\$_POST[hostname]\,
 mac=\$_POST[mac]\, ip=\$_POST[ip]\, vlan=\$_POST[vlan]\ WHERE
 id=\$_SESSION[id]\,$db)or die(mysql_error() . mysql_errno());
 $rows = mysql_affected_rows();
while($match = mysql_fetch_assoc($update)) {
  echo $match[hostname];
  echo $match[mac];
  echo $match[ip]; }
 if($rows == 0) {
echo update worked;
 } else {
echo update didn't work; }

 And...
 while($match = mysql_fetch_object($update)) {

 And..
 while($match = mysql_fetch_array($update)) {

 So far everything I have tried will not allow me to find the exact field
 and contents of a record that matches an existing record in the
 database.  See below for details on database structure etc.
 Any help is appreciated,

You're not going to be able to fetch anything from the result set because
you're excuting an UPDATE query, not a SELECT.

You also do not want to die() when the query fails, otherwise you won't be
able to react to the error. Execute the query, then check mysql_error() for
a value. If it contains a value, then the query failed more than likely
because of a duplicate key.

The format of the error message is always the same, Duplicate entry ''
for key , where  is the value that was duplicated and  is the
key number. It looks like key 41062 is the IP column. So you can look for
the 41062 and display a message about duplicate IP.

If it were me, I'd just match the value between single quotes, and echo a
message such as Duplicate value . The difference between a mac, ip,
and hostname are pretty obvious, so you don't really _have_ to tell the user
which one it is.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] multiple fields all unique?

2004-02-03 Thread John W. Holmes
From: Jas [EMAIL PROTECTED]

 Has anyone every performed such a feat as to check for matching fields
 before updating?  And if so could you show me some code that used to
 accomplish this.  I have written my own but the if - else statements are
 getting ridiculous.

Are the columns actually declared UNIQUE in your database? That's the first
step. Then you can just do the update, and if it fails with a specific
error, you know you've hit a duplicate.

The long way to do it is to just SELECT the data first, then update if there
are no matches

(assuming MySQL, here, but the concept is the same)

$query = SELECT mac, ip FROM table WHERE mac = '{$_POST['mac']}' OR ip =
'{$_POST['ip']}';
$result = mysql_query($query) or die(mysql_error());
if($row = mysql_fetch_assoc($result))
{
if($_POST['mac'] == $row['mac'])
{ echo {$row['mac']} is already being used. ; }
elseif($_POST['ip'] == $row['ip'])
{ echo {$row['ip'] is already being used. ; }
}
else
{
$query = UPDATE table SET mac = '{$_POST['mac']}', ip =
'{$_POST['ip']}' WHERE hostname = '{$_POST['hostname']}';
$result = mysql_query($query) or die(mysql_error));
echo Record updated!;
}

If you want an example of the first (and better) method, let me know.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



  1   2   3   4   5   6   7   >