Re: [PHP-DB] Doctrine or another recomended ORM?

2011-02-01 Thread Philip Thompson
http://cakephp.org/


On Jan 16, 2011, at 6:02 AM, Miriam Natanzon wrote:

 Hi,
 
 I want to choose an open-source ORM platform to use as a base for many
 different applications as a standard environment in my organization. ( we
 used DBI for PERL in the past).
 I saw and read about Doctrine - Does anyone have any positive/negative
 experience with it? Is it efficient enough (in the term of runtime)? another
 recommend environment??
 
 (I have to mention that we are working with relational-DB but not in all
 projects. maybe there is another environment that is more tailored to the
 case of just performing queries in constant syntax and security checking?)
 
 thanks a lot!!!
 Miriam


Re: [PHP-DB] Stuck in apostrophe hell

2010-08-02 Thread Philip Thompson
On Aug 2, 2010, at 4:42 PM, Bret Hughes wrote:

 I would turn on query logging and see what exactly is making it to mysql.
 
 Niel Archer wrote:
 Before I send the following SQL to MySQL from PHP I print it to screen. PHP 
 chokes on it, but I can paste the exact same query from the screen directly 
 to MySQL and it works just fine. For example:
 
 Here's the relevant PHP code:
 ==
 $sql_insert_registration = sprintf(INSERT INTO
  Registrations (
Class_ID,
prid,
Registrant,
Company,
Phone,
Email
  )
 VALUES (
$_POST[Class_ID],
$_POST[prid],
'%s',.
parseNull($_POST['Company']).,
'$_POST[Phone]',
'$_POST[Email]'
 ), mysql_real_escape_string($_POST['Registrant']));
 
 echo pre.$_POST[Registrant]./pre;
 echo pre.mysql_real_escape_string($_POST[Registrant])./pre;
 echo pre.$sql_insert_registration./pre;
 
 if (!mysql_query($sql_insert_registration, $con)) {   die('Error: ' . 
 mysql_error()); 
 ==
 
 
 Here's the output:
 ===
 
 INSERT INTO
  Registrations (
Class_ID,
prid,
Registrant,
Company,
Phone,
Email
  )
 VALUES (
355,
257,
'Brian O\'Brien',NULL,
'612-456-5678',
'paul_s_john...@mnb.uscourts.gov'
 )
 Error: 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 
 'Brien', 'Class registration confirmation', ' This email ' at line 16
 ==
 
 
 Also very oddly if the name O'Brien is input into the HTML form with two 
 apostrophes side by side (O''Brien) then MySQL will take it (but then of 
 course we have the problem of two apostrophes side by side inserted into 
 the MySQL table). For example:
 
 ===
 
 INSERT INTO
  Registrations (
Class_ID,
prid,
Registrant,
Company,
Phone,
Email
  )
 VALUES (
355,
257,
'Brian O\'\'Brien',NULL,
'612-456-5678',
'paul_s_john...@mnb.uscourts.gov'
 )
 You have been signed up for the class,
 and a confirmation email has been sent to you.
 =
 
 Very strange.
 
 I've checked various PHP variables and cannot figure out. It works fines 
 from another PHP server that's using the same MySQL database.
 
 Thanks,
 
 Paul

 
 Probably needs a double backslash for O'Brien. One to escape the
 apostrophe and one to escape the backslash escaping the apostrophe. ;-)
 This would be because you're not using mysql_real_escape_string() on the
 third parameter. Try this (not tested):
 
 $sql_insert_registration = sprintf(INSERT INTO
  Registrations (
Class_ID,
prid,
Registrant,
Company,
Phone,
Email
  )
 VALUES (%s, %s, '%s', '%s', '%s', '%s'), $_POST[Class_ID],
 $_POST[prid],
 mysql_real_escape_string(parseNull($_POST['Company'])),
 mysql_real_escape_string($_POST[Phone]),
 mysql_real_escape_string($_POST[Email]),
 mysql_real_escape_string($_POST['Registrant']));
 
 
 --
 Niel Archer
 niel.archer (at) blueyonder.co.uk

To reduce the amount of repetitive called to mysql_real_escape_string(), create 
a method/function to do the work for you

?php
function escape ($item) {
if (is_array ($item)) {
foreach ($item as $field = $value) {
$escaped[$field] = escape ($value);
}
}
else {
$escaped = mysql_real_escape_string ($item);
}

return $escaped;
}

$_POST['Company'] = parseNull ($_POST['Company']);
$p = escape ($_POST);

$sql = INSERT INTO Registrations (Class_ID, prid, Registrant, Company, Phone, 
Email) VALUES ('{$p['Class_ID']}', '{$p['prid']}', '{$p['Registrant']}', 
'{$p['Company']}', '{$p['Phone']}', '{$p['Email']}');
?

Don't know if that helps any, but it may take some of the monotony out of it.

Cheers,
~Philip

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



Re: [PHP-DB] help in implementing a progress bar

2010-01-11 Thread Philip Thompson
On Jan 7, 2010, at 2:36 PM, Vinay Kannan wrote:

 Hello,
 
 Theres this project that I am working on, and a specific module does take
 few secs to process, I am thinking it would be cool to be showing a progress
 bar(some kind on a .gif image) while the script runs, does any one have an
 idea how to implement this?
 
 Thanks,
 Vinay K

This isn't really database related, but ok...

?php
// Progress.php
class Progress {
public function start () {
echo file_get_contents ('progress.html');
flush ();
}
public function end ($url) {
$text  = script type=\text/javascript\;
$text .= window.location = '$url';;
$text .= /script;

echo $text;
flush ();
}
}
?

?php
// process.php - process the stuff
$progress = new Progress();
$progress-start();
// ... Do your processing here ...
$progress-end('nextpage.php');
?

In the progress.html file, it would just be an html page that has an animated 
gif (and whatever else you want on it). Hope this helps.

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



Re: [PHP-DB] Random pick

2009-12-18 Thread Philip Thompson
On Dec 15, 2009, at 6:02 PM, David McGlone wrote:

 On Monday 14 December 2009 21:44:24 Chris wrote:
 Chris wrote:
 David McGlone wrote:
 On Monday 14 December 2009 21:02:37 Chris wrote:
 David McGlone wrote:
 Hi everyone,
 
 I've been lurking in the shadows on the list for quite some time and
 now
 I'm in need of a little info or advise.
 
 I'm looking for a way to grab a record out of a database on a
 certain day
 each month and I'm wondering if this can be accomplished with just a
 mysql query or would I need to use PHP also?
 
 A mysql query would do it but you'd use something to talk to mysql and
 process the results (whether it's php, perl, python, ruby etc depends
 on your other requirements).
 
 What I'm trying to do is to have a record picked from the database at
 random on the 1st of every month and display it on the page. Here is
 some code I have been working with:
 
 $query = SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0);
 $result = @mysql_query($query);
 if (!$result){
 
 $query = SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1;
 $result = @mysql_query($query);
 
 while ($row = mysql_fetch_array($result)){
 echo $row[poochName] ;
 echo $row[Birthdate];
 
 }
 }
 
 You can check the day of the month in php then do your other query:
 
 $today = date('j');
 
 See http://php.net/date for date formats and what they return.
 
 if ($today !== 1) {
  echo Today isn't the first. No need to continue.\n;
  exit;
 }
 ..
 random query etc here.
 
 
 Hmmm. This isn't exactly what I'm looking for. What I'm trying to do is get a 
 new picture on the 1st of every month and display it for that whole month.

Could you not just create a mysql table that contains the month and a url to a 
file?

?php
// image.php
$currentMonth = date('n');
$sql = SELECT `image_location` FROM `monthly_images` WHERE `month` = 
$currentMonth LIMIT 1;
$result = mysql_query($sql);
list ($loc) = mysql_result ($result);

header (Content-type: image/png);
readfile ($loc);
exit;
?

And then in your HTML:

img src=image.php alt=MonthlyImage title=Yay for me! /

I just wrote that code here in the email, but it should get you going in the 
right direction. Hope that helps!

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



[PHP-DB] Group by

2009-12-09 Thread Philip Thompson
Hi.

In a mysql query, it is recommended that GROUP BY fields be indexed? Using 
EXPLAIN on one of my queries, I noticed no change between having indexed by 
GROUP BY field and not indexing it. Any thoughts would be appreciated.

In this example, should `history_field` be indexed...?

SELECT MAX(`timestamp`) AS `max_ts` 
FROM `history` 
WHERE `req_id` = 17 AND `history_record_id` = 35
GROUP BY `history_field`

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



Re: [PHP-DB] Group by

2009-12-09 Thread Philip Thompson
On Dec 9, 2009, at 12:58 PM, h...@deweywilliams.com wrote:

 The only SELECT is on MAX('timestamp').  There is really nothing to Group BY 
 in this query.
 
 Dewey
 
 Philip Thompson wrote:
 Hi.
 
 In a mysql query, it is recommended that GROUP BY fields be indexed? Using 
 EXPLAIN on one of my queries, I noticed no change between having indexed by 
 GROUP BY field and not indexing it. Any thoughts would be appreciated.
 
 In this example, should `history_field` be indexed...?
 
 SELECT MAX(`timestamp`) AS `max_ts` FROM `history` WHERE `req_id` = 17 AND 
 `history_record_id` = 35
 GROUP BY `history_field`
 
 Thanks,
 ~Philip

Well, that was just an example query. My real one is

SELECT `h`.*
FROM (
SELECT MAX(`history_timestamp`) AS `max_ts`
FROM `history`
WHERE `req_id` = 17 AND `history_record_id` = 35
GROUP BY `history_field`
) AS `max`
INNER JOIN `history` `h` ON `max`.`max_ts` = `h`.`history_timestamp`
WHERE `req_id` = 17 AND `history_record_id` = 35
GROUP BY `history_field`

This returns the results I need. The explain (split up) from this query is...

++-++--++
| id | select_type | table  | type | possible_keys  
|
++-++--++
|  1 | PRIMARY | h  | ref  | 
req_id_history_record_id,history_timestamp |
|  1 | PRIMARY | derived2 | ALL  | NULL   
|
|  2 | DERIVED | history| ref  | req_id_history_record_id   
|
++-++--++

--+-+-+--+--+
 key  | key_len | ref | rows | Extra
|
--+-+-+--+--+
 req_id_history_record_id | 8   | const,const |3 | Using temporary; 
Using filesort  |
 NULL | NULL| NULL|2 | Using where  
|
 req_id_history_record_id | 8   | |3 | Using where; Using 
temporary; Using filesort |
--+-+-+--+--+
  
3 rows in set (0.01 sec)

There's only 10 records in table right now... but the # of rows it's going to 
traverse before find the results is very small. 

Do I need to include `history_field` in the inner select?

Thanks,
~Philip

[PHP-DB] Multiple MySQL schemas

2009-12-08 Thread Philip Thompson
Hi all.

We are wanting to create an app that contains multiple clients. Each clients 
has anywhere from 1 user to more than a hundred. We had the idea of separating 
each client into its own database schema. This reduces the single point of 
failure - if 1 client db dies, it doesn't kill the others. This keeps the 
individual schemas smaller, which will allow us to asynchronously (for lack of 
a better word) transfer our backups to our network w/o causing bottlenecks. It 
also guarantees the separation of data (even though the application takes care 
of this, it's *that extra step*).

Is it reasonable to create a new database per client? Or should we cluster 
several clients together (5-10) into a single database? What are the pros and 
cons of each? Note that some clients are *linked* and share data, so those 
would not be mutually exclusive. What is the maximum number of schemas per 
MySQL instance - I'm guessing this is based on the filesystem (RHEL)?

Thanks in advance,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Doc to PDF with mssql

2009-11-07 Thread Philip Thompson

On Nov 4, 2009, at 4:00 PM, Chris wrote:


Chris wrote:

Rafael Costa Pimenta wrote:
But the link http://doc2pdf.sourceforge.net/overview.html seems to  
use e-mail, i did not understand, I just want to extract a  
word .doc file from the mssql database, save in a temp directory,  
convert to the PDF format and let the user download the PDF file.
There's a lot of stuff in there. Concentrate on each part  
separately and don't worry about the next part just yet.
try http://www.phplivedocx.org/2009/02/06/convert-doc-to-pdf-in- 
php/ for changing your doc to a pdf.
To get a doc in/out of mssql, there seems to be some magic you have  
to do:

http://www.webdeveloper.com/forum/archive/index.php/t-213799.html
If they don't work you're going to have to be more specific about  
what you're having problems with.


See also http://www.rochester.edu/it/web/WebHelp/mssql/datatypes.html


Could you not just encode the doc file before putting it in the  
database. Decode it when you get it out.


http://php.net/base64_encode
http://php.net/base64_decode

Hope that helps.
~Philip


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



Re: [PHP-DB] SELECT LIKE with % and without %

2009-05-04 Thread Philip Thompson

On May 2, 2009, at 6:43 PM, Emiliano Boragina wrote:


Hello.

I am using this:
$sql = SELECT * FROM table WHERE ID LIKE '%$_GET[id]%' AND title LIKE
'%$_GET[word]%';

But I want exactlu ID, not one part of many possibles Ids in the DB.
How can I do that?


PLEASE tell me your cleaning that input...

http://php.net/mysql_real_escape_string

And to answer your question:

?php
$id = mysql_real_escape_string ($_GET['id']);
$word = mysql_real_escape_string ($_GET['word']);

$sql = SELECT * FROM `table` WHERE `ID` = '$id' AND `title` = '$word';
?

Read more on MySQL's LIKE functionality. Google can help you.

HTH,
~Philip

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



Re: [PHP-DB] Question about databases and foreign keys

2008-09-15 Thread Philip Thompson

On Sep 15, 2008, at 10:03 AM, Jason Pruim wrote:


On Sep 15, 2008, at 10:59 AM, Micah Gersten wrote:


Use 2 tables.  You never know what the app might grow into and you
should do it right the first time.


That's what I was thinking too... Just wanted to hear it from  
someone else... NOW I get to learn about foreign keys and how to  
update things with them!


So if anyone knows of a good resource I'd appreciate it... Until  
then, I'm off to search the web and figure this stuff out!


I'm sure Google will probably be your best resource for what you need  
to find out. ;)


I'll throw this out there though. When dealing with foreign keys and  
multiple tables, remember to index appropriately. For example:


Table `users`:
user_id int(10) primary key
-- other fields here --
clock_id int(10)

Table `clocking`:
clock_id int(10) primary key
clock_in int(10)
clock_out int(10)

In table `clocking`, clock_id is already indexed because it's primary.  
Be sure to index clock_id in `users` so that when you join on the two,  
you'll have optimal speed!


ALTER TABLE `users` ADD INDEX (`clock_id`);

And an example query...

SELECT `u`.`user_id`, `c`.`clock_in`, `c`.`clock_out` FROM `users` `u`  
INNER JOIN `clocking` `c` ON `u`.`clock_id` = `c`.`clock_id` WHERE  
(`u`.`user_id` = '$user_id' AND `c`.`clock_in`  'sometime' AND  
`c`.`clock_out`  'someothertime');


Something along those lines. I always find it useful to have unique  
names throughout the database, so if you reference a name, you know  
where it originated. Because of this, I can just look at `users` and  
determine that `clock_id` is a foreign key.


Hope that helps a little!

~Philip

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



Re: [PHP-DB] Question about databases and foreign keys

2008-09-15 Thread Philip Thompson

On Sep 15, 2008, at 2:12 PM, Micah Gersten wrote:

You'll actually want to have the User Id in the clocking table, not  
the

other way around.  User Id is the foreign key because it has a many to
one relationship with the time logging.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com


Yes, I agree with that. That was just a quick example that I whipped  
up (and obviously didn't think enough about). ;) So, follow Micah's  
advice, people. =D


~Philip



Philip Thompson wrote:



I'll throw this out there though. When dealing with foreign keys and
multiple tables, remember to index appropriately. For example:

Table `users`:
user_id int(10) primary key
-- other fields here --
clock_id int(10)

Table `clocking`:
clock_id int(10) primary key
clock_in int(10)
clock_out int(10)

In table `clocking`, clock_id is already indexed because it's  
primary.
Be sure to index clock_id in `users` so that when you join on the  
two,

you'll have optimal speed!

ALTER TABLE `users` ADD INDEX (`clock_id`);

And an example query...

SELECT `u`.`user_id`, `c`.`clock_in`, `c`.`clock_out` FROM `users`  
`u`

INNER JOIN `clocking` `c` ON `u`.`clock_id` = `c`.`clock_id` WHERE
(`u`.`user_id` = '$user_id' AND `c`.`clock_in`  'sometime' AND
`c`.`clock_out`  'someothertime');

Something along those lines. I always find it useful to have unique
names throughout the database, so if you reference a name, you know
where it originated. Because of this, I can just look at `users` and
determine that `clock_id` is a foreign key.

Hope that helps a little!

~Philip



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



innerHTML is a string. The DOM is not a string, it's a hierarchal  
object structure. Shoving a string into an object is impure and  
similar to wrapping a spaghetti noodle around an orange and calling it  
lunch.



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



Re: [PHP-DB] PDO prepared statements and value list for MySQL IN

2008-07-08 Thread Philip Thompson

On Jul 8, 2008, at 11:55 AM, TK wrote:

I'd like to use a PDO prepared statement to perform a MySQL query  
that uses the IN function.


I.e.:
$stmt = $pdo-prepare('
  select *
  from mytable
  where myfield IN (:contents)
);
$stmt-bindValue(':contents', $contents);
$stmt-execute();

Here's the problem:

If $contents is set to a single value, everything's fine:
  $contents = 'mystring';

How can I include multiple values in here?  If $contents is set to  
an array, PHP throws an Array to string conversion notice.

i.e. $contents = array('mystring1', 'mystring2');

If $contents is set to a comma-separated list, no matches are  
returned (probably because the entire list is being passed to  
MySQL as a single value, not multiple values).

I.e. $contents = 'mystring1,mystring2';

What's the proper way to do this?  Can it be done?  (Note that I do  
not know how many elements will be in $contents ahead of time, so  
something like IN (:contents1, :contents2) wouldn't make sense.)


Thanks for any help!

- TK



$contents = array('string1', 'string2', 'string3');
$ins = implode (',', $contents);
$sql = SELECT * FROM `table` WHERE `field` IN ($ins);

I'm not sure if the IN function only works on numeric values or if it  
also works on strings as well. If contents contains strings, you may  
need to put single quotes around each item. If so, change the above  
to.


$ins = ' . implode (',', $contents) . ';

Hope that helps,

~Philip


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



[PHP-DB] SELECT FOR UPDATE

2008-06-02 Thread Philip Thompson

Hi all.

Which is more efficient in order to use SELECT FOR UPDATE?

% SELECT * FROM `table` WHERE (`table_id` = 32) LIMIT 1 FOR UPDATE;
% UPDATE `table` SET `field_name` = 'Pizza' WHERE (`table_id` = 32)  
LIMIT 1;


OR

% SELECT `field_name` FROM `table` WHERE (`table_id` = 32) LIMIT 1  
FOR UPDATE;
% UPDATE `table` SET `field_name` = 'Pizza' WHERE (`table_id` = 32)  
LIMIT 1;



Note: the 2nd query in each is the same. Is there any difference in  
using * and specifying the actual field you want to update? It seems  
like there would be very little difference because this is causing a  
row-lock - all the data in that row is not-updatable anyway.


I'm adding transactions and row-locking into my application. If I can  
just use the first method (because it's easier to specify '*' instead  
of every column I want to update), then I'd like to. Any thoughts are  
welcome!


Thanks in advance,

~Philip


Personally, most of my web applications do not have to factor 13.7  
billion years of space drift in to the calculations, so PHP's rand  
function has been great for me... ~S. Johnson


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



Re: [PHP-DB] Timestamps

2008-05-02 Thread Philip Thompson

On May 2, 2008, at 8:00 AM, Jason Pruim wrote:


On May 1, 2008, at 8:31 PM, Chris wrote:

PS... Was it you, Jason, or someone else who asked about the  
security
of the community knowing their database structure and I  
encouraged the

use of `backticks` around all field and table names?


Yeah it was me... Old habits die hard :) I'm working on converting
everything :)


A little caveat with that:

1) it's mysql specific


Currently the system is just running on my server, and probably  
always will... so I'm not too worried about it being mysql specific.


So is the query (mysql-specific). If you change to another *SQL, then  
you'll probably have to change the query anyway, so the backticks are  
not the biggest issue and they'll help you in the meantime.




2) I can disable you using backticks

http://www.php.net/manual/en/language.operators.execution.php


I'll have to take a look at that and see what it says in a little bit.


As you mentioned Chris, the backticks are in a string, so there's not  
a security risk in this method.


~Philip

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



Re: [PHP-DB] Timestamps

2008-05-01 Thread Philip Thompson

On May 1, 2008, at 7:56 AM, Jason Pruim wrote:


On Apr 30, 2008, at 5:03 PM, Philip Thompson wrote:


On Apr 30, 2008, at 10:54 AM, Jason Pruim wrote:

Hi Yves,

Thanks for the tip, that worked, I think I'll use that from now on..

Just out of curiosity though, any idea why it wasn't working as I  
was writing it :)


Did you try putting the query that PHP is generating in phpMyAdmin  
or MySQL Query Browser? See if it throws an error when attempting  
to update. It *appears* that the query should work.


No I haven't, I don't have phpMyAdmin installed since I do it all  
from the command line, and I don't pay for hosting yet... But I am  
going to need to change that. I don't believe I have heard about  
MySQL Query Browser though... Is it a webapp? Or do I need to  
install it on my local computer?


Query Browser is part of the MySQL GUI tools. You can download them  
here and use on your local computer:


http://dev.mysql.com/downloads/gui-tools/5.0.html

However, if you're using command line, then that should provide the  
same error messages (if any) that may assist you.




~Philip

PS... Was it you, Jason, or someone else who asked about the  
security of the community knowing their database structure and I  
encouraged the use of `backticks` around all field and table names?


Yeah it was me... Old habits die hard :) I'm working on converting  
everything :)





On Apr 30, 2008, at 11:47 AM, YVES SUCAET wrote:


Hi Jason,

It's not because you create a date/time value that you  
automatically have an
integer-value. You need to specify first that you want the date/ 
time value

converted to an integer value first.

See
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_unix-timestamp
for an example of how to do this.

Actually, by using this function, you probably don't even need to  
create the
$modifiedTimestamp variable anymore. You can just write your SQL  
query as

follows:

$sql = Update `mytable` set timestamp=UNIX_TIMESTAMP() where  
Record='1';


HTH,

Yves

-- Original Message --
Received: Wed, 30 Apr 2008 10:39:11 AM CDT
From: Jason Pruim [EMAIL PROTECTED]
To: Stut [EMAIL PROTECTED]Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Timestamps


On Apr 30, 2008, at 11:35 AM, Stut wrote:


On 30 Apr 2008, at 16:29, Jason Pruim wrote:

Okay... So I know this should be simple...

Trying to store a timestamp in a MySQL database... The  
timestamp I

am making like so: $modifiedTimestamp = time();

and then just $sql = Update `mytable` set
timestamp='$modifiedTimestamp' where Record='1';

Simple right? Not quite...in my database it's storing a 0 in  
the

timestamp field which is a int(10) field.

I have googled, and searched manuals, but have not been able to
figure out what is going on

Any Ideas?


timestamp is a reserved word. Try putting it in backticks.



Okay, so I did a really crappy job at my sudo code... The field  
name

is actually Last_Updated.

so my update code looks like this:  
Last_Updated='$modifiedTimestamp'


*Slaps his wrist... Bad copy/paste! BAD!!!


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



Re: [PHP-DB] Timestamps

2008-04-30 Thread Philip Thompson

On Apr 30, 2008, at 10:54 AM, Jason Pruim wrote:

Hi Yves,

Thanks for the tip, that worked, I think I'll use that from now on..

Just out of curiosity though, any idea why it wasn't working as I  
was writing it :)


Did you try putting the query that PHP is generating in phpMyAdmin or  
MySQL Query Browser? See if it throws an error when attempting to  
update. It *appears* that the query should work.


~Philip

PS... Was it you, Jason, or someone else who asked about the security  
of the community knowing their database structure and I encouraged the  
use of `backticks` around all field and table names?




On Apr 30, 2008, at 11:47 AM, YVES SUCAET wrote:


Hi Jason,

It's not because you create a date/time value that you  
automatically have an
integer-value. You need to specify first that you want the date/ 
time value

converted to an integer value first.

See
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_unix-timestamp
for an example of how to do this.

Actually, by using this function, you probably don't even need to  
create the
$modifiedTimestamp variable anymore. You can just write your SQL  
query as

follows:

$sql = Update `mytable` set timestamp=UNIX_TIMESTAMP() where  
Record='1';


HTH,

Yves

-- Original Message --
Received: Wed, 30 Apr 2008 10:39:11 AM CDT
From: Jason Pruim [EMAIL PROTECTED]
To: Stut [EMAIL PROTECTED]Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Timestamps


On Apr 30, 2008, at 11:35 AM, Stut wrote:


On 30 Apr 2008, at 16:29, Jason Pruim wrote:

Okay... So I know this should be simple...

Trying to store a timestamp in a MySQL database... The timestamp I
am making like so: $modifiedTimestamp = time();

and then just $sql = Update `mytable` set
timestamp='$modifiedTimestamp' where Record='1';

Simple right? Not quite...in my database it's storing a 0 in the
timestamp field which is a int(10) field.

I have googled, and searched manuals, but have not been able to
figure out what is going on

Any Ideas?


timestamp is a reserved word. Try putting it in backticks.



Okay, so I did a really crappy job at my sudo code... The field name
is actually Last_Updated.

so my update code looks like this: Last_Updated='$modifiedTimestamp'

*Slaps his wrist... Bad copy/paste! BAD!!!


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



Re: [PHP-DB] playing longblob media

2008-04-29 Thread Philip Thompson

On Apr 28, 2008, at 12:49 AM, Chris wrote:

Philip Thompson wrote:

On Apr 27, 2008, at 9:15 AM, Ron wrote:

Hi,

How can i retrieve via php a media stored in a mysql database as  
longblob?


I'd like to be able to retrieve the media and stream it.

TIA

regards,
ron
Just like any other field type. Doesn't matter to PHP what the  
field type is...


But it does to the browser.

You'll need to send the appropriate headers for the browser to do  
the right thing, and since it's probably a big field instead of  
saving it to a variable, just echo it out.


No idea what the right headers are though :)


I understand that the headers are important. However, that was not the  
question. The question asked how to retrieve data from a mysql  
database using PHP. I answered that question...


~Philip

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



Re: [PHP-DB] playing longblob media

2008-04-29 Thread Philip Thompson

On Apr 28, 2008, at 9:22 AM, Ron wrote:

hi yves,

not sure how large the file is, but i'm assuming a caller would not  
leave a voicemail longer than a minute. max maybe 30 secs. is there  
a query to get the size of a data in a certain row/column?


thank you

regards
ron


Assuming you're storing the data as binary, you *should* be able to do  
a strlen() on the output to get the *file* size.


~Philip



Yves Sucaet wrote:
So how large is the file/BLOB? How many seconds/minutes of data  
does it contain? The previous author was right: you can retrieve  
BLOB fields just like any other fields. The problem is sending them  
back to the client.

Yves
- Original Message - From: Ron [EMAIL PROTECTED]
To: php-db@lists.php.net
Sent: Sunday, April 27, 2008 10:02 PM
Subject: Re: [PHP-DB] playing longblob media
i'm trying to play a WAV file, this file is a voicemail file  
generated by asterisk pbx. it is stored in mysql and i would like  
users to be able to check their voicemail via web using php script  
that will retrieve it from the db as a wav format already. thank you


Yves Sucaet wrote:
What kind of media are you trying to retrieve? Are you trying to  
retrieve the MySQL data and stream that through your script to  
the client? How big is the BLOB?


If nothing else, you'll need to adapt the MIME-type in the header  
of your HTTP-message.


HTH,

Yves

- Original Message - From: Ron [EMAIL PROTECTED]
To: php-db@lists.php.net
Sent: Sunday, April 27, 2008 9:15 AM
Subject: [PHP-DB] playing longblob media



Hi,

How can i retrieve via php a media stored in a mysql database as  
longblob?


I'd like to be able to retrieve the media and stream it.

TIA

regards,
ron

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








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




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



Personally, most of my web applications do not have to factor 13.7  
billion years of space drift in to the calculations, so PHP's rand  
function has been great for me... ~S. Johnson



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



Re: [PHP-DB] playing longblob media

2008-04-27 Thread Philip Thompson

On Apr 27, 2008, at 9:15 AM, Ron wrote:

Hi,

How can i retrieve via php a media stored in a mysql database as  
longblob?


I'd like to be able to retrieve the media and stream it.

TIA

regards,
ron


Just like any other field type. Doesn't matter to PHP what the field  
type is...


?php
$sql = SELECT `longblob_fieldname` FROM `table` WHERE (`id` = '$id')  
LIMIT 1;

$result = mysql_query ($sql);
if (mysql_num_rows ($result)) {
$contents = mysql_result ($result, 0);
}
?

~Philip

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



[PHP-DB] UPPER(AES_DECRYPT(...)) bug?

2008-04-01 Thread Philip Thompson

Hi all.

Here's my disclaimer: this question is solely MySQL-related - I just  
happen to be programming in PHP.


I have found some functionality which *appears* to be a bug, but I  
didn't want to report it before asking some intelligent people. I have  
this simple query:


SELECT UPPER('just a lower case string') AS `UPPER_STRING`,  
UPPER(AES_DECRYPT(AES_ENCRYPT('Bob Frapples', '1234ABCD'),  
'1234ABCD')) AS `UPPER_NAME`;


Expected result:

UPPER_STRING  UPPER_NAME
  
JUST A LOWER CASE STRING  BOB FRAPPLES

Real result:

UPPER_STRING  UPPER_NAME
  
JUST A LOWER CASE STRING  Bob Frapples


There is a similar bug report http://bugs.mysql.com/bug.php?id=28072  
that uses LCASE instead of UPPER. But, they have the same *lack of  
desired functionality*. MySQL people say it's not a bug due to how  
binary blah blah blah. Whatever - I don't buy that. It's not working  
*as it should*. On top of that, the docs for this encrypt stuff is  
quite minimal.


My questions to you: do you think this is a bug? And... is there an  
alternative to searching on fields that are encrypted using the LIKE  
operator?


Thanks,
~Philip


Personally, most of my web applications do not have to factor 13.7  
billion years of space drift in to the calculations, so PHP's rand  
function has been great for me... ~S. Johnson


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



[PHP-DB] mssql_connect issues

2005-01-06 Thread Philip Thompson
Hi all.
I have worked with a MySQL database a whole lot, but never really an MS 
SQL database before. Here's the problem I'm having. I call this 
function and then nothing else happens. No other information shows up 
on the page.

$link = mssql_connect(myServer, me, pw);
Of course, I replace the values here with the real ones, but nothing 
happens. I know the database exists b/c I am looking at it right now.

If I echo something to the screen before this call, then it shows. If I 
echo something after, it does not show. If I add or die (...) after 
the function call, it does not show. I'm kinda lost on what it could be 
at this point. I have commented out everything else that it could 
potentially be so that I know it's this line. I get no error message... 
I just get nothing.

Any thoughts? Thanks in advance,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] mssql_connect

2005-01-06 Thread Philip Thompson
Hi again all!
Right after I sent the email... I think I figured out what it was! I do 
not have it `uncommented` in my php.ini file! Therefore, none of the 
mssql_* functions would work.

Sorry for that last email.
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Aliased mysql queries and mysql_fetch_array()

2004-10-22 Thread Philip Thompson
Hi all.
I am having a problem obtaining the specific information I need. I have 
a table of people that can have multiple rows - ie, Director, 
Manager, etc. However, in the projects table, each project has a 
director AND manager, but not necessarily the same person.

I have the query to pull the information - and I know it works for 
everything else. Now how do I reference the director/manager to store 
it in a variable without having to use numerical indexing?


	$query = select projects.*, locations.*, funding.*, people.* from 
people as people_1 RIGHT JOIN  .
(people RIGHT JOIN (funding RIGHT JOIN (locations RIGHT JOIN 
projects on locations.id =  .
projects.location_id) on funding.id = projects.funding_id) on 
people.id = projects.manager_id) on  .
people_1.id = projects.director_id $whereCondition order by 
$criteria;

$result = @mysql_query($query, $link);
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	// there are much more fields, but I have only included the
	// two important ones (manager and director)
$_SESSION[manager][$i] = $row[first_name] .   . 
$row[last_name];
$_SESSION[director][$i] = $row[people_1.first_name] .   . 
$row[people_1.last_name];

  $i++;
}

It does not work whenever I include the table within the $row[]. 
Otherwise, it shouldn't be a problem. Any suggestions?

Thanks in advance,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mysql_query

2004-10-12 Thread Philip Thompson
On Oct 12, 2004, at 7:15 AM, [EMAIL PROTECTED] wrote:
hello,
I have a begining question.
I've got simple html form and php script, but insert doesn' t work. 
What is
wrong in my insert mysql_query?

mysql_query( insert into obiskovalci (ime, priimek, ulica, hstevilka,
pstevilka, posta) values('$ime', '$priimek', '$ulica', '$hstevilka',
'$pstevilka', '$posta'));
There's a little more you need. First you have to use the connection 
you should have already opened up:

$link = mysql_connect('some_db', 'some_user', 'some_pw');
Then you have to include the `link` whenever you do a query:
mysql_query(your query, $link);
If I recall, you may not actually have to include the link every single 
time if you have already established which one you're using... but it's 
always safe to specify which one you're using. Maybe someone can 
clarify on this.

There is also id, which is auto_increment. After fill form and press 
Submit, id
is writen in table, but there is no other inputs. Nothing, except id.
Yes, consider using the $_POST[some_variable] to obtain the values.
thanks for answers
BR, Balo
Hope this helped a tiny bit.
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Setting a timed-session

2004-10-01 Thread Philip Thompson
Hi all.
This may be a bit elementary, however, I am confused on the 
functionality of it. I am wanting to create a session that logs out 
after a certain amount of time, no matter if the user is doing 
something or not. I have used the function `set_time_limit()`, but I 
don't know if I'm using it properly.

What I do is whenever a certain page is accessed, I call that function. 
I tested it with 10 seconds, but nothing seemed to happen. Is it 
supposed to kill the session and all of the $_SESSION variables? Or 
what exactly is it supposed to do?

I looked on the php site, but I'm still a bit baffled? Any insight?
http://us4.php.net/function.set-time-limit
Thanks in advance,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] ip address

2004-09-30 Thread Philip Thompson
balwant,
It seems to be working for me. I have looked at it from multiple 
computers, and it always gives the ip of that computer. Try for yourself:

http://housing.uark.edu/resnet/ip.php
Let me know if you get something other than your ip.
~Philip
balwantsingh wrote:
i tried the $_SERVER['REMOTE_ADDR'] it is giving ip address of server which
is hosting the webpage not the user's ip address.   pls. suggest how can IP
address of an user can be obtained.
with best wishes
balwant
-Original Message-
From: Philip Thompson [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 30, 2004 3:45 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: getenv() alternative
Oh, before I get a slew of emails about this one, I think I figured it
out: $_SERVER['REMOTE_ADDR']
I knew it couldn't have been that difficult... brain fart! Sorry for
wasting your time.
~Philip
On Sep 29, 2004, at 5:02 PM, Philip Thompson wrote:
 

Hi all.
I am needing to obtain the IP address of a user who logs into the
system. I tried to use `getenv(REMOTE_ADDR)`, however, this function
does not work in ISAPI mode, which is what I am running.
Is there an alternative to obtaining the IP address? I have looked
around, but I cannot seem to find anything.
Thanks in advance,
~Philip
   

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

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


Re: [PHP-DB] ip address

2004-09-30 Thread Philip Thompson
Ramil,
On Sep 30, 2004, at 1:17 AM, Ramil Sagum wrote:
On Thu, 30 Sep 2004 11:00:35 +0530, balwantsingh
[EMAIL PROTECTED] wrote:
i tried the $_SERVER['REMOTE_ADDR'] it is giving ip address of server 
which
is hosting the webpage not the user's ip address.   pls. suggest how 
can IP
address of an user can be obtained.
what exactly did you do? the following script works:
===
htmlbody
Your IP Address is :
?php echo $_SERVER[REMOTE_ADDR]; ?
/body/html
===

ramil
Yes, that's what I did (with a tad bit of error-testing), and it seems 
to work fine for me.

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


[PHP-DB] getenv() alternative

2004-09-29 Thread Philip Thompson
Hi all.
I am needing to obtain the IP address of a user who logs into the 
system. I tried to use `getenv(REMOTE_ADDR)`, however, this function 
does not work in ISAPI mode, which is what I am running.

Is there an alternative to obtaining the IP address? I have looked 
around, but I cannot seem to find anything.

Thanks in advance,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Re: getenv() alternative

2004-09-29 Thread Philip Thompson
Oh, before I get a slew of emails about this one, I think I figured it 
out: $_SERVER['REMOTE_ADDR']

I knew it couldn't have been that difficult... brain fart! Sorry for 
wasting your time.

~Philip
On Sep 29, 2004, at 5:02 PM, Philip Thompson wrote:
Hi all.
I am needing to obtain the IP address of a user who logs into the 
system. I tried to use `getenv(REMOTE_ADDR)`, however, this function 
does not work in ISAPI mode, which is what I am running.

Is there an alternative to obtaining the IP address? I have looked 
around, but I cannot seem to find anything.

Thanks in advance,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Using sessions to gather visitor information

2004-09-15 Thread Philip Thompson
Hi.
On Sep 15, 2004, at 6:55 AM, Vincent Jordan wrote:
I am trying to track the users that visit one page on a site. I am 
having a
couple of problems. The time seems to be 5 hours off. I do not have any
tables as of yet what I would like to do is only count an ip address 
as one
in a 24 hour period, if more than one visit then update visit count.I 
have
played around with the time using date() and localtime().  Here is 
what I
have sofar.


ini_set('display_errors',1);
error_reporting(E_ALL  ~E_NOTICE);
session_start();
$_SESSION['ip_address'] = $IP;
$_SESSION['user_agent'] = $Browser;
$_SESSION['host_name'] = $Host;
$_SESSION['visit_time'] = $now;

$now = localtime();
$now = $now[2] . : . $now[1] . : . $now[0];
$IP = getenv(REMOTE_ADDR);
$Browser = $_SERVER['HTTP_USER_AGENT'];
$Host = getHostByName($IP);

I have not setup tables yet but I think I will use this:
vid init(5) not null auto_incriment
ip varchar(25) null
agent varchar(100) null
host varchar(100) null
time varchar(10) nul
visitcount int(100) null

when a visitor loads the page I can run this

mysql_query(SELECT ip, time FROM tablename where 
ip=$_SESSION['ip_address']
and time=$_SESSION['visit_time'])


I would like to query if $_SESSION['ip_address'] has visited in less 
then 24
hours then kill session and close mysql connection. If last visit was 
more
than 24 hours update time and add +1 to visitcount. If new visit add to
table.


Once all done how can I properly clean up the session. I have tried the
following bur get an error
unset($_SESSION);
session_destroy();
I tried this with a link to another page and got this error:
Warning: session_destroy(): Trying to destroy uninitialized session in
/home/content/html/killtest.php on line 5
I assume I forgot something.
Any help would be appreciated.
You might make sure that on the page where it says session_destroy(); 
that you have actually carried the session over. Meaning, if it's on a 
different page than you originally started the session, make sure you 
include session_start(); at the beginning of that next page.

Also, something you might want to try is first testing to see if the 
session is set.

if (session_id())
session_destroy();
That part doesn't really help your specific situation (as far as 
destroying the session), but I think it's good practice and will not 
give an error message if your session has not been started yet and you 
try to destroy it.

Hope this helps you some.
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Insert Query PROBLEMS

2004-09-13 Thread Philip Thompson
Aaron,
I agree with what Mark said. But I just want to say what I noticed off  
hand...

On Sep 10, 2004, at 11:13 AM, Aaron Todd wrote:
I'm trying to run an INSERT query on my mysql database and it isnt  
working.

Here is the query:
$updatequery = UPDATE `users`
  SET
('company','fname','lname','address1','address2','city','state','zip',' 
phone','extension','fax','email')
When I do an UPDATE and refer to these columns, I do not include the  
single quotes (or tick marks) around my fields, and it works fine. But  
like Mark said, cleaning it up (1 per line) might also help - that's  
just personal preference.

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


Re: [PHP-DB] mysq query without subselects

2004-09-13 Thread Philip Thompson
Blackwater,
On Sep 10, 2004, at 12:39 PM, blackwater dev wrote:
Hello,
I need to grab the max value of all of the data in a table grabbing
the max total for each client.  Example.
T1
idtotal  clientid
1  100   111
2  200   111
3  100   112
4  150   112
I need a query that will grab the highest total per clientid (200, and
150) then average them.  My first inclination is to do a subselect
select avg(total) from t1 where t1.total=(select max(total) from t1 t2
where t2.clientid=t1.clientid)
But can't use subselects with mysqlhow do I do it??
Yes you can. Check this out and see if all your syntax is correct.
http://dev.mysql.com/doc/mysql/en/Subqueries.html
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Please help

2004-09-10 Thread Philip Thompson
I think everyone knows that $sql is a statement. But what people are 
asking is: what is that statement?! Because if there are incorrect 
characters or 's in that statement, then that can break your 
code/statement.

~Philip
On Sep 9, 2004, at 5:49 PM, Stuart Felenstein wrote:
Just getting back to this thing.  There are 3 files
involved, search.php, connections.php and
functions.php.
I searched through all and couldn't find the meaning
of the $sql_ext.   $sql is just the sql statement I
inserted into the code.
Great that I can't get a response from the company.
If anyone thinks it would be useful to post the code I
will. That is if anyone would want to see and look at
it.
The weird thing is searching on one table is great.
The list (all records) works great.  The problem
starts when I insert all my joins.  Now I've tested
and retested the query and I know it's fine.
Thank you ,
Stuart
--- Steve Davies [EMAIL PROTECTED] wrote:
What's contained in $sql and $sql_ext ???
Stuart Felenstein wrote:
I'm using a product called dbqwiksite pro.  PHP
generator for PHP - MySQL
The code seems to be working fine except in my
search
page where I receive an invalid query
$result = mysql_query($sql .   . $sql_ext . 
limit
0,1)
or die(Invalid query);
This is the place I where the code is taking the
die
path.
I'm guessing something belongs between the
quotation
marks , just not sure.
Anyone ?
Thank you
Stuart

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

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


Re: [PHP-DB] functions via event handlers

2004-09-06 Thread Philip Thompson
Yemi,
On Sep 6, 2004, at 7:14 AM, Yemi Obembe wrote:
i'd just luv to ask if it is possibble to call a function in PHP by 
using event handlers (like onmouseover, onload) as done in javascript? 
if its possible, i'd appreciate someone to tutor me on it.

As far as I know, this is not possible. Since PHP is server-side 
scripting (not client-side like JavaScript), all the code-processing is 
done before it ever reaches the client's computer. Because of this, you 
will never be able to use the code via event handlers.

If anyone knows something different, please let me and Yemi know.
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Passing variables from HTML to PHP

2004-08-31 Thread Philip Thompson
Hi all.
This might be a simple answer, but I'm still not sure what the case is. 
Okay, so I have a form in my html that has some inputs. These each 
have a `name` and a `value` attribute to them, of course.

I cannot seem to access the name/value pair in my php without using the 
$_POST method/variable names. Are you able to without $_POST? Example:

---
html:
input type=checkbox name=foo value=bar
php:
do this:
echo foo =  . $foo; // foo = bar
or this:
echo foo =  . $_POST[foo]; // foo = bar
---
So, should both of those php examples work the same?
Thanks!
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Re: Passing variables from HTML to PHP

2004-08-31 Thread Philip Thompson
Thanks for your reply. Those who have responded, I am thankful to.
~Philip
On Aug 31, 2004, at 4:14 PM, Jasper Howard wrote:
if the checkbox is checked then you'll get the value in the php 
script. If
globals are turned on then echo $foo; will work, otherwise you have to 
use
something like: echo $_POST['foo'];

its a good idea to write your scripts without dependency on globals 
being
turned on, its a security risk for it to be on.

--
--
Jasper Howard :: Database Administration
Velocity7
1.530.470.9292
http://www.Velocity7.com/
--
Philip Thompson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hi all.
This might be a simple answer, but I'm still not sure what the case 
is.
Okay, so I have a form in my html that has some inputs. These each
have a `name` and a `value` attribute to them, of course.

I cannot seem to access the name/value pair in my php without using 
the
$_POST method/variable names. Are you able to without $_POST? Example:

---
html:
input type=checkbox name=foo value=bar
php:
do this:
echo foo =  . $foo; // foo = bar
or this:
echo foo =  . $_POST[foo]; // foo = bar
---
So, should both of those php examples work the same?
Thanks!
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Webpage response to selection $_POST

2004-08-30 Thread Philip Thompson
Peter,
On Aug 30, 2004, at 12:49 PM, Peter Ellis wrote:
It doesn't look like you're actually retrieving data using the $_POSTed
data from that code snippet.  Are you doing anything like $j = $_POST
['j']; in order to get the value of j before you retrieve your array
data?  Or are you allowing PHP to declare $_POST variables globally?
Yes, I tried setting the $_POST information to a variable, but that 
does not work either. I think I am allowing PHP to declare them 
globally... how is that done exactly?

The reason you need brackets is because brackets are always used in the
declaration of a user array, assuming that this is what you want.  If
you don't want an array, than your original code was correct -- []
always signals an array type to PHP.
--
Peter Ellis - [EMAIL PROTECTED]
Web Design and Development Consultant
naturalaxis | http://www.naturalaxis.com/

Do you recommend I use an array over a lot of variables? I can use 
either or - there was no particular reason why I chose a single 
variable.

Thanks,
~Philip
On Mon, 2004-08-30 at 11:02 -0500, Philip Thompson wrote:
Peter,
On Aug 29, 2004, at 6:26 PM, Peter Lovatt wrote:
Hi
you need to check for $_POST[user1], $_POST[user2] etc - is that
what
you are doing?
Yes, this is how I am checking the post variables.
Your other variables are done as an array - $firstName[$j] etc, 
should
your
check box be

 echo ' tdinput type=checkbox name=user[' . $j . ']
value=1/td' . \n;
(note the [])
Why do you have to have the []'s? I did add those, but it didn't seem
to help.
Otherwise try vardump($_POST) to see exactly what is being returned.
I also tried the vardump($_POST), and it did not seem to return
anything. I did not find anything about vardump() on the php site...
besides some non-built in function. Any more thoughts on using it?
If this does not fix it try posting the code that handles the 
response
and
we will try and help.

Peter
Ok, quick question. Does the $_POST variable transfer the information
to all the pages? or just the page called in that form
action=apage.php? Because in my code I call a certain page, but 
then
that page merely redirects to another page, depending what selection
was made.

The code that uses the $_POST information follows...
~Philip
?php
for ($j=0; $j=$largestDBID; $j++) {
 $user = user[ . $j . ];
 if ($_POST[$user]) {
 echo 'tr' . \n;
 echo ' td' . $dbid[$j] . '/td' . \n;
 echo ' td' . $firstName[$j] . '/td' . \n;
 echo ' td' . $lastName[$j] . '/td' . \n;
 echo ' td' . $uid[$j] . '/td' . \n;
 echo ' td' . $username[$j] . '/td' . \n;
 echo ' td' . $classification[$j] . '/td' . \n;
 echo '/tr' . \n;
 }
}
?

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


[PHP-DB] Webpage response to selection $_POST

2004-08-29 Thread Philip Thompson
Hi all.
I have a list of users in a database that I would like to show on a 
dynamic webpage. With each of these users that shows up on the page, 
there is going to be a checkbox next to their name so that I can 
perform multiple tasks, such as 'Remove User' or 'Modify Information'. 
I have all of the appropriate information showing up on the page, 
including the checkboxes.

My question is... if I select a checkbox for a user, the other pages do 
not even recognize that I have selected that checkbox and I am using 
the $_POST method - why is that? I have even attempted to use the 
import_request_variables function - no luck. So, I cannot verify which 
users I want to perform an action on.

Anyone have any ideas? Snippets of code to follow...
Thanks in advance,
~Philip
form action=performaction.php method=post
table
?php
for ($j=0; $j$numRows; $j++) {
echo 'tr' . \n;
echo '	tdinput type=checkbox name=user' . $j . ' 
value=1/td' . \n;
echo '	td' . $dbid[$j] . '/td' . \n;
echo '	td' . $firstName[$j] . '/td' . \n;
echo '	td' . $lastName[$j] . '/td' . \n;
echo '	td' . $uid[$j] . '/td' . \n;
echo '	td' . $username[$j] . '/td' . \n;
echo '	td' . $classification[$j] . '/td' . \n;
echo '	/tr' . \n;
}
?
/table

input type=submit name=removeuser value=Remove User /
input type=submit name=modifyclass value=Modify Classification /
input type=hidden name=beenSubmitted value=1 /
/form


[PHP-DB] Enabling LDAP support

2004-08-02 Thread Philip Thompson
Hi again all.
Sorry to bug you again. But I thought I would throw this out here again 
and see if anyone has any input. It would be greatly appreciated.

I am running PHP on a Windows 2000 Server, and I need to enable LDAP 
support. So I have viewed the 
http://us3.php.net/manual/en/ref.ldap.php page on how to get LDAP 
running. However, I have run into a snag.

I have copied the two required .dlls (libeay32  ssleay32) into the 
system folder. I also put the configuration option 'ldap.max_links = 
-1' in my php.ini file. Is there anything else I need to add to the 
.ini file? I tried uncommenting the extension for php_ldap.dll, 
thinking that that might make it work... but it didn't.

Anyone have any suggestions b/c I'm stuck?
Thanks,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] sendmail

2004-08-02 Thread Philip Thompson
Aaron,
On Aug 2, 2004, at 1:31 PM, Aaron Todd wrote:
So far, I have been doing ok with PHP.  I feel that I have picked it up
rather easily.  But now I need some help.  I am trying to use the 
sendmail
functions to send data entered in a form to my email address.  
Currently its
not working at all.  I am getting a

Fatal Error:  Call to undefined function: sendmail() in
/home/virtual/site341/fst/var/www/html/register.php on line 87
You might want to consider using the 'mail()' function instead. It's 
given at:
http://us2.php.net/manual/en/ref.mail.php

I use it, and it works perfectly!
I havent found very much info on the sendmail function so I was 
shooting in
the dark with it.  I did read in the manual some stuff about seting it 
u in
the php.ini file that just went over my head.  Can anyone enlighten me 
on
this function.

Thanks,
Aaron
Hope that helps you!
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Enabling LDAP support on Win2k Server

2004-07-30 Thread Philip Thompson
Hi all.
I am running PHP on a Windows 2000 Server, and I need to enable LDAP 
support. So I have viewed the 
http://us3.php.net/manual/en/ref.ldap.php page on how to get LDAP 
running. However, I have run into a snag.

I have copied the two required .dlls (libeay32  ssleay32) into the 
system folder. I also put the configuration option 'ldap.max_links = 
-1' in my php.ini file. Is there anything else I need to add to the 
.ini file? I tried uncommenting the extension for php_ldap.dll, 
thinking that that might make it work... but it didn't.

Anyone have any suggestions b/c I'm stuck?
Thanks,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Empty query result

2004-07-26 Thread Philip Thompson
Hi all.
I am querying a database of single information multiple times using a 
simple 'select' statement. However, whenever the data in the DB is 
empty or is 0 (zero), then it throws an error. However, I don't want it 
to throw an error, I just want it to move on to the next query.

This is being shown on a webpage I have. Note that I am using a 
function for this select statement because I just have to change the 
identifier that I am looking for - saves space. So I don't use 
mysql_error() to show my errors, I redirect to a global 'error' page.

Is there a way to get around this empty set problem? Yes, I know 
about using @ to suppress warnings, but it's more than this.

Thanks a bunch,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Empty query result

2004-07-26 Thread Philip Thompson
Pablo,
Hello Philip,
pse.. can you paste the error information?
There is no known empty set problem.
Here's my function:
function getMysqlSelectResultForUsername($identifier, $userName, $link)
{
$queryResult = mysql_query(select $identifier from theTable where 
username = '$userName', $link);

if (!($queryResult = mysql_result($queryResult, 0))) {
session_register('_selectIdentifierFromTheTable');
header(location:error.php);
exit;
}
return $queryResult;
}
Here's the code that calls it:
$hall = getMysqlSelectResultForUsername('buildingID', $_userName, 
$link);
$roomNum = getMysqlSelectResultForUsername('roomNum', $_userName, 
$link);
$phone1 = getMysqlSelectResultForUsername('phone1', $_userName, $link);
$phone2 = getMysqlSelectResultForUsername('phone2', $_userName, $link);
$lastLogin = getMysqlSelectResultForUsername('lastLogin', $_userName, 
$link);

If the mysql_result($queryResult, 0) returns zero/nothing, then it goes 
to the 'error.php' page. However, I just want it to move on. For 
example, if there is no 'phone2' given in the database, I want it to 
just assign $phone2 to zero/nothing, not go to the error page.

Hope this helps.
Thanks,
~Philip
--
Best regards,
 Pablo
PT Hi all.
PT I am querying a database of single information multiple times 
using a
PT simple 'select' statement. However, whenever the data in the DB is
PT empty or is 0 (zero), then it throws an error. However, I don't 
want it
PT to throw an error, I just want it to move on to the next query.

PT This is being shown on a webpage I have. Note that I am using a
PT function for this select statement because I just have to change 
the
PT identifier that I am looking for - saves space. So I don't use
PT mysql_error() to show my errors, I redirect to a global 'error' 
page.

PT Is there a way to get around this empty set problem? Yes, I know
PT about using @ to suppress warnings, but it's more than this.
PT Thanks a bunch,
PT ~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Empty query result

2004-07-26 Thread Philip Thompson
Thanks all! I will try some of the suggestions that you guys gave. I 
appreciate it.

~Philip
On Jul 26, 2004, at 12:52 PM, Pablo M. Rivas wrote:
Hello Philip,
  read:
  http://www.php.net/manual/en/function.mysql-result.php
  when you do $queryResult = mysql_result($queryResult,0) you get
  the error... so, you can do something like this:
 function getMysqlSelectResultForUsername($identifier, $userName, 
$link)
 {
  $queryResult = mysql_query(select $identifier from theTable 
where
 username = '$userName', $link);
  if ($queryResult) {
 $queryResult = mysql_result($queryResult, 0);
  }
  return $queryResult;
 }

 $hall = getMysqlSelectResultForUserName('buildingID', 
$_userName,$link);
 if (!$hall) die (error)
 

or you can do:
  function getMySqlSelectResultForUserName($identifier,
  $userName,$link) {
   return mysql_query(select $identifier from TheTable where
   username='$userName',$link);
   }
 $hall= getMysqlSelectResultForUsername('buildingID', $_userName, 
$link);
 if (!$hall) die(not found building!!!);
 $roomNum = getMysqlSelectResultForUsername('roomNum', 
$_userName,$link);
 $phone1 = getMysqlSelectResultForUsername('phone1', $_userName, 
$link);
 $phone2 = getMysqlSelectResultForUsername('phone2', $_userName, 
$link);
 $lastLogin = getMysqlSelectResultForUsername('lastLogin', 
$_userName,$link);

  if ((!$roomNum) or (!$phone1) or (!$phone2) or (!$lastLogin)) {
 echo data is missing;
  
  } else {
 ...
  }
PT Pablo,

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


Re: [PHP-DB] value error in PHP form

2004-06-21 Thread Philip Thompson
Hi. You left out the 'php' after the '?'. So it should read:
?php
print $action;
print $Name;
?
See if that helps any.
~Philip
body
form name=frmname
input type=text name=Name value=Rinku
input type=submit name=action  value=Login
?
print $action;
print $Name;
?
/form
/body
/html
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] delete a record not working

2004-06-16 Thread Philip Thompson
Yeah, you should have a single apostrophe around the $id. So it should 
read:

mysql_query(DELETE FROM open_trades WHERE id='$id');
That should do it.
~Philip
On Jun 16, 2004, at 12:04 AM, Justin wrote:
Hello, I have a simple script to retrieve and then delete a selected 
script, but it does not work.

When I hit the button I get:
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 'id' at line 11064

Any help would be appreciated.
Thanks
form action=? echo $PHP_SELF ? method=post
?php
mysql_pconnect(localhost,root,password);
mysql_select_db(options);
$result = mysql_query(select * from open_trades);
while ($row = mysql_fetch_array($result))
{
print trtd;
print INPUT TYPE='RADIO' NAME='id' VALUE='id';
print /tdtd;
print $row[id];
print /tdtd;
print $row[open_date];
print /tdtd;
print $row[short_long_trade];
print /tdtd;
print $row[expiry];
print /td/tr\n;
}
print /table\n;
?
input type=submit name=submit value=close/form
?php
if($submit)
 {
  mysql_query(DELETE FROM open_trades WHERE id=$id);
  echo Thank you! Information updated.;
  echo mysql_error();
  echo mysql_errno();
  }
?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Re: Erroneous date and time

2004-06-16 Thread Philip Thompson

Have you tried with a insted of A for am/pm indication?
Yes, I have tried both 'a' and 'A'. Still gives an incorrect time.
~Philip

Hope can help
Bye
Franciccio
Philip Thompson [EMAIL PROTECTED] ha scritto nel messaggio
news:[EMAIL PROTECTED]
Hi all.
Maybe there's something I'm doing incorrectly, but I cannot get the
date() function to return the appropriate time. It's always 12 hours
off. I've tried using 24-hour time and 12-hour time (with AM/PM), but
they both give the wrong time. I even emailed the server admin to make
sure that the server clock was set correctly, and he said that it was.
I don't know... Here's my PHP:
$problemDateTime = date(Y-m-d g:i:s A);
which returns: 2004-06-13 11:24:21 PM
To the untrained eye ;), that might appear correct. But that was
actually submitted at 11:24 AM, not PM. So, that's my code. Any
suggestions??
Thanks a bunch,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Fwd: [PHP-DB] anonymous select error

2004-06-15 Thread Philip Thompson
I agree about the semi-colon: not allowed. But also, specify '$link' in 
your mysql_error(). This tells it explicitly what the error is 
referring to, even though it should be able to figure it out on it's 
own.

echo 'MySQL Error: ' . mysql_error($link);
Hope this helps - seems to work for me.
~Philip
I'm not sure you need a semi-colon after the table name.
$result = mysql_query( 'Select * From newsletter_subscribers', $db );
To: [EMAIL PROTECTED]
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
I'm trying this query:
$link = mysql_connect( $site, $id, $pass );
if (!$link) {
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfullybr';
$db = mysql_select_db( $dbname, $link);
if( !$db ) {
  echo DB falsebr;
  exit;
}
$result = mysql_query( 'Select * From
newsletter_subscribers;', $db );
if (!$result) {
  echo DB Error, could not list tablesbr;
  echo 'MySQL Error: ' . mysql_error();
  exit;
}
with this output:
Connected successfully
DB Error, could not list tables
MySQL Error:
I dont understand why there is an error, but it prints
nothing for the error.  Any ideas?  Thanks, Josh

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


[PHP-DB] Erroneous date and time

2004-06-15 Thread Philip Thompson
Hi all.
Maybe there's something I'm doing incorrectly, but I cannot get the 
date() function to return the appropriate time. It's always 12 hours 
off. I've tried using 24-hour time and 12-hour time (with AM/PM), but 
they both give the wrong time. I even emailed the server admin to make 
sure that the server clock was set correctly, and he said that it was. 
I don't know... Here's my PHP:

$problemDateTime = date(Y-m-d g:i:s A);
which returns: 2004-06-13 11:24:21 PM
To the untrained eye ;), that might appear correct. But that was 
actually submitted at 11:24 AM, not PM. So, that's my code. Any 
suggestions??

Thanks a bunch,
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] mysql results, arrays, and for loops

2004-06-11 Thread Philip Thompson
Hi all!
I am using a select statement to obtain all the dates whenever someone 
submitted a problem in a database. Well, I want to get the result 
(which could be multiple dates) and then print that in a table format 
with some other information on a webpage. So I want to use a FOR loops 
and go through each of the dates and dynamically create a table.

My question is: how do I store the results of the select query? Would I 
want to store them in an array, and then just parse through each 
element of the array, and what is the syntax for that? Or is there a 
better way?

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


Re: [PHP-DB] Re: mysql results, arrays, and for loops

2004-06-11 Thread Philip Thompson
Yes, thanks to all that assisted. I got it working like a charm!
~Philip
On Jun 11, 2004, at 9:30 AM, Torsten Roehr wrote:
Philip Thompson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hi all!
I am using a select statement to obtain all the dates whenever someone
submitted a problem in a database. Well, I want to get the result
(which could be multiple dates) and then print that in a table format
with some other information on a webpage. So I want to use a FOR loops
and go through each of the dates and dynamically create a table.
My question is: how do I store the results of the select query? Would 
I
want to store them in an array, and then just parse through each
element of the array, and what is the syntax for that? Or is there a
better way?
You can loop through your query results in this way:
$result = mysql_query('SELECT * FROM table');
while ($row = mysql_fetch_assoc($result)) {
// row is now the current record set as an associative array, keys
represent the field names
// do what you want with row, e.g. print a field value from column 
date
echo $row['date'];
}

Is this what you are looking for?
Regards,
Torsten Roehr
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] HTTP header information

2004-06-10 Thread Philip Thompson
Hi all.
I am running a website to where a user needs to login to authenticate 
themselves to perform certain tasks. So a user logs in, and I start a 
session (in PHP, of course). Well, the catch is, I am doing this all 
from one page, 'viewer.php', and I just tack on the specific view/page 
that I want them to see, depending on the link selected on that page. 
Meaning, they click on the 'submit problem' link and it goes to 
'viewer.php?type=submitproblem'.

The problem comes whenever I load the view 'submitproblem' and I start 
a session with session_start(), which carries over the variable to tell 
whether or not the user is logged in. If they have not logged in 
whenever they click on 'submitproblem' then it will redirect them to 
'viewer.php?type=login'. So I log in, and then go to 'submitproblem'.

This is where I get the error: Warning: session_start(): Cannot send 
session cookie - headers already sent. Essentially, I understand why 
this is occurring, but is there an easy way to get around it without 
creating a new page, such as 'submitproblem.php' instead of 
'viewer.php?type=submitproblem'???

Thanks a bunch
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Re: HTTP header information

2004-06-10 Thread Philip Thompson
On Jun 10, 2004, at 9:44 AM, Torsten Roehr wrote:
Philip Thompson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hi all.
I am running a website to where a user needs to login to authenticate
themselves to perform certain tasks. So a user logs in, and I start a
session (in PHP, of course). Well, the catch is, I am doing this all
from one page, 'viewer.php', and I just tack on the specific view/page
that I want them to see, depending on the link selected on that page.
Meaning, they click on the 'submit problem' link and it goes to
'viewer.php?type=submitproblem'.
The problem comes whenever I load the view 'submitproblem' and I start
a session with session_start(), which carries over the variable to 
tell
whether or not the user is logged in. If they have not logged in
whenever they click on 'submitproblem' then it will redirect them to
'viewer.php?type=login'. So I log in, and then go to 'submitproblem'.

This is where I get the error: Warning: session_start(): Cannot send
session cookie - headers already sent. Essentially, I understand why
this is occurring, but is there an easy way to get around it without
creating a new page, such as 'submitproblem.php' instead of
'viewer.php?type=submitproblem'???
Make sure that NO output is done before session_start() is called. Can 
you
post some of your code?

Regards,
Torsten Roehr
See, that's the case. Because I'm essentially just changing the content 
within the page, it never leaves the page 'viewer.php' - it just 
changes the content by tacking on '?type=login, submitproblem, etc'.

But my code in the beginning of the file 'submitproblem.view' is:
?php
session_start();
if (!session_is_registered('_isLoggedIn')) {
header (Location:viewer.php?type=login);
} else {
// do the stuff to submit a problem if they have
// logged in and have pressed the submit button
// in the html
}
?
// then here is all the html for that page
So, does that help any?
~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php