Re: [PHP] Division by 0

2010-03-10 Thread Joseph Thayne
Looks to me like you are closing your form before you put anything in 
it.  Therefore, the loan_amount is not set making the value 0.  Follow 
the math, and you are dividing by 1-1.


Change this line:



to:



and you should be good to go.

Joseph

Gary wrote:
I have a mortgage amortization script that was working fine,now it seems to 
have gone awry. Below is the entire script plus input page.  I am getting an 
error


Warning: Division by zero in 
/home/content/J/a/y/Jayski/html/one2one/Ricksrecursivefunctions.php on line 
47


Which is  (pow($intCalc,$totalPayments) - 1);

Frankly I am not even sure the information is being passed to the script.

Anyone see what I am missing?

Gary


Calculate your Loan




 
  Loan Amount
 USD
src="images/help.png" class="noborder"/>

  

  Type of Loan
  

  Installment
  Balloon

class="noborder"/>

  
   
 Term of Loan

Months
src="images/help.png" class="noborder" />


 
 Interest Rate
 Per 
Annum/>








   $paymentNum
   \$".number_format($balance,2)."
   \$".number_format($periodicPayment,2)."
   \$".number_format($paymentInterest,2)."
   \$".number_format($paymentPrincipal,2)."
   ";
 # If balance not yet zero, recursively call amortizationTable()
 if ($newBalance > 0) {
$paymentNum++;
amortizationTable($paymentNum, $periodicPayment, $newBalance,
  $monthlyInterest);
 } else {
exit;
 }
} #end amortizationTable()

   # Loan balance
   $balance =($_POST['loan_amount']);

   # Loan interest rate
   $interestRate = ($_POST['int_rate']);

   # Monthly interest rate
   $monthlyInterest = ("$interestRate / 12");

   # Term length of the loan, in years.
   $termLength =($_POST['loan_term']);

   # Number of payments per year.
   $paymentsPerYear = 12;

   # Payment iteration
   $paymentNumber =($_POST['loan_term']);

   # Perform preliminary calculations
   $totalPayments = $termLength * $paymentsPerYear;
   $intCalc = 1 + $interestRate / $paymentsPerYear;
   $periodicPayment = $balance * pow($intCalc,$totalPayments) * ($intCalc - 
1) /

(pow($intCalc,$totalPayments) - 1);
   $periodicPayment = round($periodicPayment,2);

   # Create table
   echo "";
   print "
  Payment
NumberBalance
  PaymentInterestPrincipal
  ";

   # Call recursive function
   amortizationTable($paymentNumber, $periodicPayment, $balance, 
$monthlyInterest);


   # Close table
   print "";

?>
 




__ Information from ESET Smart Security, version of virus signature 
database 4932 (20100310) __

The message was checked by ESET Smart Security.

http://www.eset.com





  


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



Re: [PHP] Error Message - Need help troubleshooting

2010-03-02 Thread Joseph Thayne
I do not know if the question has been answered, but how are you opening 
the session?  Are you using session_start() or are you using 
session_register()?


Rick Dwyer wrote:

On Mar 2, 2010, at 8:48 AM, Ashley Sheridan wrote:


How is $item_id created? You've not shown that in your PHP script 
examples.


// parse item id from the url
$refer=$_SERVER['HTTP_REFERER'];
$thispage=$_SERVER['PHP_SELF'];
$item_id=substr($thispage, -9);
$item_id=substr($item_id, 0, 5);

$_SESSION['item_id'] = "$item_id";   


The above is where item_id is created and added to a session.

The important thing is that this error never showed up before until I 
added the Javascript link below:


var oss_itemid = "";
var loadOSS = window.open("http://www.myurl/myfile.php?iid="; + 
oss_itemid, "", 
"scrollbars=no,menubar=no,height=600,width=600,resizable=yes,toolbar=no,location=no,status=no"); 




When I was testing initially, I had removed the variable above in the 
link with a hard coded value and I never received this error.  Only 
when I made it dynamic did this error appear.


Thanks for any help.

--Rick



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



Re: [PHP] $_POST vs $_REQUEST

2010-02-22 Thread Joseph Thayne



Richard wrote:

It's a wise choice to go with $_POST, unless your form is a GET form,
in which case use $_GET. $_REQUEST has the potential to open your
script(s) up to security issues.

  
I am not sure what the security issues are you are referring to as the 
$_REQUEST superglobal contains both $_GET and $_POST values.  Could you 
expound on that?  Thanks.

Use quoted strings - either single or double quotes. Eg:

$myArray['myKey']
$myArray["myKey"]

  
To answer your question though, the quotes will not protect you from SQL 
injection at all.  It simply has to do with processing the values.


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



Re: [PHP] Dumb Question - Casting

2010-02-18 Thread Joseph Thayne
According to the PHP manual using the same expression, "Never cast an 
unknown fraction to integer, as this can sometimes lead to unexpected 
results".  My guess is that since it is an expression of floating 
points, that the result is not quite 8 (for whatever reason).  
Therefore, it is rounded towards 0.  Of course, that is only a guess, 
and I have no true documentation on it.


Ashley Sheridan wrote:

On Thu, 2010-02-18 at 09:47 -0600, Chuck wrote:

  

Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad
rusty.

Can someone explain why the second expression in this code snippet evaluates
to 7 and not 8?

$a = (int) (0.1 +0.7);

echo "$a\n";

$x = (int) ((0.1 + 0.7) * 10);

echo "$x\n";

$y = (int) (8);

echo "$y\n";




It works as expected if you take out the int() parts in each line. I'm
not sure why, but the use of int() seems to be screwing around with the
results. That's why the first line outputs a 0.

Thanks,
Ash
http://www.ashleysheridan.co.uk



  


RE: [PHP] SQL insert () values (),(),(); how to get auto_increments properly?

2010-02-13 Thread Joseph Thayne
In order to make this as "sql server independent" as possible, the first
thing you need to do is not use extended inserts as that is a MySQL
capability.  If you are insistent on using the extended inserts, then look
at the mysql_info() function.  That will return the number of rows inserted,
etc. on the last query.

-Original Message-
From: Rene Veerman [mailto:rene7...@gmail.com] 
Sent: Saturday, February 13, 2010 12:08 AM
To: php-general
Subject: [PHP] SQL insert () values (),(),(); how to get auto_increments
properly?

Hi.

I'm looking for the most efficient way to insert several records and
retrieve the auto_increment values for the inserted rows, while
avoiding crippling concurrency problems caused by multiple php threads
doing this on the same table at potentially the same time.

I'm using mysql atm, so i thought "stored procedures!"..
But alas, mysql docs are very basic.

I got the gist of how to setup a stored proc, but how to retrieve a
list of auto_increment ids still eludes me; last_insert_id() only
returns for the last row i believe.
So building an INSERT (...) VALUES (...),(...) at the php end, is
probably not the way to go then.

But the mysql docs don't show how to pass an array to a stored
procedure, so i can't just have the stored proc loop over an array,
insert per row, retrieve last_insert_id() into temp table, and return
the temp table contents for a list of auto_increment ids for inserted
rows.

Any clues are greatly appreciated..
I'm looking for the most sql server independent way to do this.

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


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



RE: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne
I was going to write an example as to what should happen instead of what
actually does when id dawned on me why MySQL works the way it does.  One of
the biggest complaints people have with MySQL is in speed.  To demonstrate
what I just realized, take the following statement that will select the hour
from a given time as well as the value from the hour field:

SELECT HOUR('13:42:37') as thehour, hour FROM mytable;

Not a big deal and pretty straight forward.  What about the following?

SELECT HOUR(mydate) as thehour, hour FROM mytable;

Still pretty simple to determine which are the functions and which are the
field names.  However, take the following:

SELECT HOUR(NOW()) as thehour, hour FROM mytable;

As humans, glancing at it, it makes perfect sense to us as to which is
which.  However, try telling a computer how to interpret the above
statement.  You could look for parenthesis.  That would work fine on the
first two statements, but once you get to the third, you have to worry about
recursion and all possible permutations of the data that could come through.
This exponentially increases the complexity and processing time/power
required to run the query.  Granted, that query is a simple one, but plug it
into a query filled with multiple joins, and you have the potential of a
nightmare.  So why focus on adding in functionality that adds so much
complexity and will end up requiring that much extra support when a simple
character (the tick mark) will take care of the work for you and you can
then focus on other things such as data integrity and general processing
speed?

Joseph

-Original Message-
From: Paul M Foster [mailto:pa...@quillandmouse.com] 
Sent: Thursday, February 11, 2010 9:15 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Mysql statement works in phpmyadmin but not in php page

On Fri, Feb 12, 2010 at 09:44:47AM +1030, James McLean wrote:

> On Fri, Feb 12, 2010 at 9:31 AM, Joseph Thayne 
wrote:
> > As for the backticks, they are required because of MySQL, not because of
> > phpMyAdmin.  The issue was not that phpMyAdmin uses backticks, it is
that
> > MySQL pretty much requires them when naming a field the same as an
internal
> > function to my knowledge.  If someone else knows of another way to
designate
> > to MySQL that a field named HOUR is the name of a field rather than the
name
> > of the internal function, I would love to know.

Backticks are also required to preserve casing in MySQL, if you name
something in mixed or upper case; MySQL lowercases table and field names
otherwise. It's a silly misfeature of MySQL. 

I can't conceive of why a DBMS would assume something which should be
understood in the context of a field name should instead be interpreted
as a function call. Buy maybe that's just me.

Paul

-- 
Paul M. Foster

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


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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne
Yeah, I am a lot more descriptive now.  I ran into it quite a bit when I 
was first starting out.


James McLean wrote:

On Fri, Feb 12, 2010 at 9:31 AM, Joseph Thayne  wrote:
  

As for the backticks, they are required because of MySQL, not because of
phpMyAdmin.  The issue was not that phpMyAdmin uses backticks, it is that
MySQL pretty much requires them when naming a field the same as an internal
function to my knowledge.  If someone else knows of another way to designate
to MySQL that a field named HOUR is the name of a field rather than the name
of the internal function, I would love to know.



Ahh I see :) Wasn't aware of that. Personally i've always been
over-descriptive when designing my tables which is possibly why I've
never run into that limitation :)

Thanks.

  


Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne
That is a good idea to use the curly braces.  I consistently forget 
about them, and fell like an idiot every time I am reminded of them.


As for the backticks, they are required because of MySQL, not because of 
phpMyAdmin.  The issue was not that phpMyAdmin uses backticks, it is 
that MySQL pretty much requires them when naming a field the same as an 
internal function to my knowledge.  If someone else knows of another way 
to designate to MySQL that a field named HOUR is the name of a field 
rather than the name of the internal function, I would love to know.


James McLean wrote:

On Fri, Feb 12, 2010 at 8:27 AM, Joseph Thayne  wrote:
  

Actually, the syntax is just fine.  I personally would prefer it the way you
mention, but there actually is nothing wrong with the syntax.



The ,'$date1'"." is not correct syntax, change it to ,'".$date."'
  


My personal preference these days is to use Curly braces around
variables in strings such as this, I always find excessive string
concatenation such as is often used when building SQL queries hard to
read, and IIRC there was performance implications to it as well
(though I don't have access to concrete stats right now).

In your case, the variable would be something like this:

$query="INSERT INTO upload_history (v_id,hour,visits,date) VALUES
({$v_id}, {$hour}, {$visits}, '{$date}')";

Much more readable and maintainable IMO.

No need for the trailing semicolon in SQL that uses an API like you
are using so save another char there too.
Backticks around column names are not required and IMO again they just
make the code hard to read. Just because phpMyAdmin uses them, doesn't
mean we all need to.

Cheers

  


Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne


Actually, the syntax is just fine.  I personally would prefer it the way 
you mention, but there actually is nothing wrong with the syntax.



The ,'$date1'"." is not correct syntax, change it to ,'".$date."'


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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne
Try putting tick marks (`) around the field and table names.  So your 
SQL query would then look like:


INSERT INTO `history` (`v_id`, `hour`, `visits`, `date`) VALUES (45, 0, 
59, '2010 01 27');


This is a good practice to get into.  The problem is that MySQL allows 
you to create tables and fields with the same name as functions.  If the 
tick marks are not there, then it assumes you mean to try using the 
function.  In your case, hour is a function in mysql.  I would assume 
that the reason it works in phpmyadmin is that it filters the query 
somehow to add the tick marks in.


Joseph

james stojan wrote:

I'm at my wits end trying to make this mysql statement insert work in
PHP. I'm not getting any errors from PHP or mysql but the insert fails
(nothing is inserted) error reporting is on and is reporting other
errors. When I echo out the query and manually paste it into PHP
myAdmin the query inserts without a problem. I know that I am
connecting to the database as well part of the data being inserted
comes from the same database and that the mysql user has permission to
do inserts (even tried as root no luck).

$query="INSERT INTO upload_history (v_id,hour,visits,date) VALUES
(".$v_id.",".$hour.",".$visits.",'$date1'".");";

$r2=mysql_query($query) or die("A fatal MySQL error
occured.\nQuery: " . $query . "\nError: (" .
mysql_errno() . ") " . mysql_error());

This is an echo of $query and runs in phpmyadmin.

INSERT INTO history (v_id,hour,visits,date) VALUES (45,0,59,'2010 01 27');


Any idea what is going on here?

  


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



Re: [PHP] PHP generated HTML has submit button which picks up the wrong url.

2010-02-05 Thread Joseph Thayne
"What you maybe ought to consider is using several submit buttons, and 
give each a name and a value. That way, your PHP script can check for a 
specifically named variable sent from the form. That way, you keep many 
people happy, and your site still works perfectly."


The problem with doing it that way is that IE is not happy with multiple 
submit buttons in a single form.  To get around that, you can use image 
input types or buttons.  Also, a return key does not send values the 
same way as a mouse click.  I can't remember which browser does what, 
but the three possible submitted values are (providing the name of the 
button is submit):


submit
submit_x and submit_y
submit_x, submit_y, and submit

Just something to be aware of if you are looking for the value of the 
submit button -- not 100% reliable.  It would be better to use a hidden 
form value or just check to see if submit or submit_x is set.


Joseph

Ashley Sheridan wrote:

On Fri, 2010-02-05 at 14:33 -0600, Joseph Thayne wrote:
This is actually a javascript issue rather than a PHP issue.  What is 
happening is that the action of the form is what is being submitted.  
The action never changes.  What you need to do is have the javascript 
change the action as well as submit the form (which means you will need 
to move it to a function).  It would also help to empty out the form 
action as well.


Example JS function:
function retrieveAllPerm()
{
document.display_data.action='http://unproto.demog.berkeley.edu/memdemo/edit_query_form.php?perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries'
 
<http://unproto.demog.berkeley.edu/memdemo/edit_query_form.php?perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries%27>;
document.display_data.submit();
}

Example submit button:
onClick="javascript:retrieveAllPerm();" >Revise query


Joseph

Mary Anderson wrote:
> Hi,
>   I am writing code in PHP which generates HTML script.  My app is 
> fairly complex.  Twice in the development of the application I have 
> run into a problem with submit buttons which pick up the wrong url.  
> Instead of call the url for that submit button, it appears to call the 
> url for the first submit button on the page.  The problem may be 
> intermittent, which seems to suggest that something funny is happening 
> with the cache.  Clearing the cache did not help in the last go around.
> I am including the generated html code.  Hitting the button 'Retrieve 
> all ...' should call up the url get_query_forms.php.  Instead it calls 
> up the url query_form_display_data.php, which is the url for the first 
> submit button on the page.

>
>   Any clues to clear up this mystery would be greatly appreciated!
>
> Mary Anderson
>
> 
>
>
>
>
>
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

> http://www.w3.org/1999/xhtml";>
> 
> 
> 
> Display Data
> 
>  > action=./query_form_display_data.php?perm_batch_file=perm&pg_query_form_id=518&data_table_id=255&data_batch_id=&query_form_schema=permanent_queries&batch_input_file_id=&create_tmp_data_tables=0"> 
>

>
> 
> 72 rows have been returned by this query
> 
> 
>
> 
>
> 
>
> 
>
> 
>
> 
> 
>
> 
>
> 
>
> 
> 
> 
> > value='Change worksheet : Change max row count' 
> onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries' <http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries%27>" 
> >
> > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries' <http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries%27>" 
> >
> > onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries' <http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=per

Re: [PHP] PHP generated HTML has submit button which picks up the wrong url.

2010-02-05 Thread Joseph Thayne
This is actually a javascript issue rather than a PHP issue.  What is 
happening is that the action of the form is what is being submitted.  
The action never changes.  What you need to do is have the javascript 
change the action as well as submit the form (which means you will need 
to move it to a function).  It would also help to empty out the form 
action as well.


Example JS function:
function retrieveAllPerm()
{
document.display_data.action='http://unproto.demog.berkeley.edu/memdemo/edit_query_form.php?perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries';
document.display_data.submit();
}

Example submit button:
onClick="javascript:retrieveAllPerm();" >Revise query


Joseph

Mary Anderson wrote:

Hi,
  I am writing code in PHP which generates HTML script.  My app is 
fairly complex.  Twice in the development of the application I have 
run into a problem with submit buttons which pick up the wrong url.  
Instead of call the url for that submit button, it appears to call the 
url for the first submit button on the page.  The problem may be 
intermittent, which seems to suggest that something funny is happening 
with the cache.  Clearing the cache did not help in the last go around.
I am including the generated html code.  Hitting the button 'Retrieve 
all ...' should call up the url get_query_forms.php.  Instead it calls 
up the url query_form_display_data.php, which is the url for the first 
submit button on the page.


  Any clues to clear up this mystery would be greatly appreciated!

Mary Anderson







"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

http://www.w3.org/1999/xhtml";>



Display Data

 action=./query_form_display_data.php?perm_batch_file=perm&pg_query_form_id=518&data_table_id=255&data_batch_id=&query_form_schema=permanent_queries&batch_input_file_id=&create_tmp_data_tables=0"> 




72 rows have been returned by this query





















value='Change worksheet : Change max row count' 
onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries'" 
>
onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries'" 
>
onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/query_form_display_data.php?worksheet_join_element_initialize=1&perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries'" 
>



onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/edit_query_form.php?perm_batch_file=perm&pg_query_form_id=518&query_form_schema=permanent_queries'" 
>
value='Retrieve all permanent query forms for this table type' 
onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file='perm'&query_form_schema=permanent_queries&user_name=&data_table_type_id='" 
>
value='Retrieve all temporary query forms for this table type' 
onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file='perm'&query_form_schema=temporary_queries&user_name=&data_table_type_id='" 
>
onClick="form.action='http://unproto.demog.berkeley.edu/memdemo/get_query_forms.php?perm_batch_file=perm&user_name='" 
>




onClick="form.action='http://unproto.demog.berkeley.edu/memdemo'" 
>


value='perm'>name='tmp_data_values_table' 
value='display.perm_tmp_data_values_518'>id='pg_query_form_id' name='pg_query_form_id' value='518'>type='hidden' id='query_form_schema' name='query_form_schema' 
value='permanent_queries'>name='data_table_id' value='255'>id='data_batch_id' name='data_batch_id' value='218'>type='hidden' id='batch_input_file_id' name='batch_input_file_id' 
value=''>value=''>value=''>name='data_table_type_id' value=''>name='user_name' value=''>







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



Re: [PHP] MySQL ID -- what happens when you run out of range?

2010-01-25 Thread Joseph Thayne

That is incorrect.  What will happen is as follows:

1.  The value will be incremented by 1 causing the value to be greater 
than the maximum integer allowed.

2.  MySQL will see this as a problem and "truncate" it to the closest value.
3.  MySQL will then try and insert the new row with the updated id.
4.  MySQL will find that the id already exists, and will return a 
duplicate ID error.


If you want to verify what occurs, create a table with a tinyint value 
for the id and autoincrement it.


It is correct also, that you cannot use negative numbers for the 
autoincrement field.


Camilo Sperberg wrote:

On Mon, Jan 25, 2010 at 17:15, Parham Doustdar  wrote:

  

Hello there,
A friend called me today and was wondering what happens if the ID colomn of
an MYSQL database, set to autoinc reaches the int limit. Will it return and
begin choosing the ID's that have been deleted, or... what?
Thanks!





from what I know, MySQL will convert that number into a negative number,
which would be invalid for an auto-increment field (auto-increment ==
unsigned). That would raise an error ;)

Greetings :)

  


Re: [PHP] MySQL ID -- what happens when you run out of range?

2010-01-25 Thread Joseph Thayne

It will continue to use the max number which of course will cause an error.

Joseph

Parham Doustdar wrote:

Hello there,
A friend called me today and was wondering what happens if the ID colomn of 
an MYSQL database, set to autoinc reaches the int limit. Will it return and 
begin choosing the ID's that have been deleted, or... what?
Thanks! 




  


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



Re: [PHP] Cookies & sessions

2010-01-20 Thread Joseph Thayne

Bruno Fajardo wrote:

You don't need to use output buffering at all. You only need this
mechanism if your script needs to output stuff before the
session_start() or setcookie() functions get executed.
Output buffering is also used if you need to "output" something before 
the headers are sent either by the header() function or simply using 
echo or print().


Joseph

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



Re: [PHP] Backup to local drive

2009-12-11 Thread Joseph Thayne
PHP cannot create a folder structure on your local machine.  I don't 
think Javascript or VBScript can either.  Your best bet is with the zip 
files.  Windows users have it fairly simple actually (as much as I hate 
to admit it) as all they would have to do is right-click and "Extract".  
You can always include instructions in either an on-screen format or a 
README file (or both). 

As I have been thinking about it, you are going to need to do a zip file 
so that the user only has to download a single file.


Joseph

Ashley Sheridan wrote:

On Fri, 2009-12-11 at 15:04 -0700, Ben Miller wrote:
  

That’s exactly why I need something that will put all the needed files
directly onto the flash drive – to take that responsibility away from
the user.  Pulling the data from the DB and creating the folder
structure is easy with PHP – just not sure how to copy that folder
structure and related files to the flash drive without the user having
to know much of anything about computers.  Was hoping there is maybe a
PHP extension that I didn’t know about, but sounds like a client side
is going to be my best bet.

 



From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Friday, December 11, 2009 2:39 PM

To: Ben Miller
Cc: 'Roberto'; php-general@lists.php.net
Subject: RE: [PHP] Backup to local drive



 

On Fri, 2009-12-11 at 14:36 -0700, Ben Miller wrote: 



 
Too much reliance on the user knowing how to extract the files to the flash drive – need something that does it all for them so all they have to do is insert the flash drive on their own computer to store the preformatted presentation and then insert into a prospect’s computer and either a) (preferred) run the presentation via an autoplay command or b) open the presentation.html file.
 
 
Ben
 
 
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Friday, December 11, 2009 2:25 PM

To: Ben Miller
Cc: 'Roberto'; php-general@lists.php.net
Subject: RE: [PHP] Backup to local drive
 
 
On Fri, 2009-12-11 at 14:25 -0700, Ben Miller wrote: 
 
Users would be updating data via form input (address, tel, product

catalogues, etc.) as well as uploading files (images, PDFs, etc.), creating
their own presentations and saving those presentations to a flash drive as
HTML files with calls to the images/PDFs so that they can simply plug their
drive into a USB port and present the info on the road, regardless of
connection to the internet.
Ben
-Original Message-
From: Roberto [mailto:prof...@gmail.com] 
Sent: Friday, December 11, 2009 11:58 AM

To: Ben Miller
Cc: php-general@lists.php.net
Subject: Re: [PHP] Backup to local drive
Hi,
you lost me a bit. Let say a user uploads a PDF file to one of your servers.
What do you mean when you say "I want the users to be able to save the
HTML output of their data"?!?
Roberto Aloi
http://aloiroberto.wordpress.com
Twitter: @prof3ta
On Fri, Dec 11, 2009 at 6:44 PM, Ben Miller  wrote:


Hello - I have an application I'm building that allows users to store
personal information and files (images, PDFs, etc.) in our database, but I
need a way for them to be able to save the HTML output of that personal
  

data


to a local (for the user) flash drive.  I'm guessing I'm going to need a
clientSide language like javascript for this, but was wondering if maybe
there was a PHP addon or something like that for downloading content to
  

the


user's PC.  Thanks in advance.



Ben


  
 
 
 
 
Why not create all the HTML files and images on the server, and zip it up then send that down to the user?
 
 
Thanks,

Ash
http://www.ashleysheridan.co.uk
 
 
 
 




That could end up in a lot of HTML and image files. Also, if you can't
rely on people to unzip a file, can you rely on them to know that they
need to keep the images with the HTML?

Thanks,
Ash
http://www.ashleysheridan.co.uk





 






PHP can't do anything like that, PHP is all on the server. Javascript
doesn't have anything like that either, but JScript and VBScript do I
believe, although that limits you to only Internet Explorer, and only if
the user has allowed the unsafe actions.

Your best bet is to maybe try to use a format that keeps it all in one
file, such as a PDF.

Another solution would be to have the HTML reference the images from
your own hosting, and put the entire presentation in one file.

Thanks,
Ash
http://www.ashleysheridan.co.uk



  


Re: [PHP] move_uploaded_file

2009-12-11 Thread Joseph Thayne
When used in PHP, an absolute path does not go off the web root.  In 
Premise 3 below, an absolute path of "/upload" will NOT bring up the 
directory "/home/prof3ta/projects/moodle/htdocs/upload" but rather 
simply "/upload"  In Windows terms, an absolute path would be 
"C:\upload" versus "C:\home\prof3ta\projects\moodle\htdocs\upload".  The 
only time an absolute path is figured relative to the web root is when 
it is referenced in a browser.  At this point, for all intents and 
purposes, it locates the file based on the web root.  This is a 
fundamental difference between absolute and relative paths.


Absolute:  begins at "/" in Linux operating systems and "C:\" in Windows OS
Relative:  begins wherever the running script is located in the file system.

Joseph

Roberto wrote:

HI,

Premise 1:
echo exec("pwd"); -> "/home/prof3ta/projects/moodle/htdocs/feedback_tool"

Premise 2:
I have an "upload" folder with 777 permissions under:
/home/prof3ta/projects/moodle/htdocs/upload

Premise 3:
The server root is obviously htdocs:
/home/prof3ta/projects/moodle/htdocs

This said, the following doesn't work:



The following does work:



I consider it as a documentation bug (in the sample code they use an
absolute path).
I indeed believe I *should* be able to use both of them if not
documented otherwise.
I will dig into the C implementation of the move_uploaded_file
function and I'll check, though.

Cheers,

Roberto Aloi
http://aloiroberto.wordpress.com
Twitter: @prof3ta

  


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



Re: [PHP] Backup to local drive

2009-12-11 Thread Joseph Thayne
If you are wanting to save the information as a PDF (formatted the same 
as the HTML page), check out tcpdf at www.tcpdf.org.  It is fairly 
simple to implement and can interpret an HTML page causing it to be 
saved as PDF.


Joseph

Ben Miller wrote:

Hello - I have an application I'm building that allows users to store
personal information and files (images, PDFs, etc.) in our database, but I
need a way for them to be able to save the HTML output of that personal data
to a local (for the user) flash drive.  I'm guessing I'm going to need a
clientSide language like javascript for this, but was wondering if maybe
there was a PHP addon or something like that for downloading content to the
user's PC.  Thanks in advance.

 


Ben


  


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



Re: [PHP] move_uploaded_file

2009-12-11 Thread Joseph Thayne
You should be able to use either an absolute or relative path.  In the 
code below, the path specified is absolute (it starts with /).  If you 
want it to be relative to your current directory, change the line to:


$uploads_dir = 'uploads'; or $uploads_dir = '../uploads';

So basically, it all depends on how you define your path.

Joseph


Roberto wrote:

Am I just drunk or blind or the documentation is simply wrong?

>From the official doc
(http://uk2.php.net/manual/en/function.move-uploaded-file.php):

 $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
?>

The path for the upload dir should be a relative one, not an absolute one.

Roberto Aloi
http://aloiroberto.wordpress.com
Twitter: @prof3ta

  


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



Re: [PHP] Using Curl to replicate a site

2009-12-10 Thread Joseph Thayne
If the site can be a few minutes behind, (say 15-30 minutes), then what 
I recommend is to create a caching script that will update the necessary 
files if the md5 checksum has changed at all (or a specified time period 
has past).  Then store those files locally, and run local copies of the 
files.  Your performance will be much better than if you have to request 
the page from another server every time.  You could run this script 
every 15-30 minutes depending on your needs via a cron job.


Joseph

Ashley Sheridan wrote:

Hi,

I need to replicate a site on another domain, and in this case, an
iframe won't really do, as I need to remove some of the graphics, etc
around the content. The owner of the site I'm needing to copy has asked
for the site to be duplicated, and unfortunately in this case, because
of the CMS he's used (which is owned by the hosting he uses) I need a
way to have the site replicated on an already existing domain as a
microsite, but in a way that it is always up-to-date.

I'm fine using Curl to grab the site, and even alter the content that is
returned, but I was thinking about a caching mechanism. Has anyone any
suggestions on this?

Thanks,
Ash
http://www.ashleysheridan.co.uk



  


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



Re: [PHP] Browsing PHP documentation from Emacs

2009-12-09 Thread Joseph Thayne
Check the following link for help on integrating with Vim:  
http://vim.wikia.com/wiki/PHP_manual_in_Vim_help_format


Kim Emax wrote:

Hello

Roberto wrote on 2009-12-09 17:08:

Hi all,

I've just written a small tool for Emacs that will allow to browse PHP
documentation directly from within Emacs.
I thought you might be interested in it:

http://aloiroberto.wordpress.com/2009/12/09/php-and-emacs-how-to-browse-documentation/ 



It is released with GNU GPLv3 license and it might be integrated with
existing php-mode implementations.
Looking forward to hear feedback from you.


Interesting stuff, is this against the php.net documentation?

And do you believe it would be possible to do the same from Vim?



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