[PHP] New to PHP form attributes

2003-10-07 Thread Matthew Oatham
Hi,

I am new to PHP and am more used to JSP. My question is - if I submit a form 
to a php3 page using action==""  for some processing all is 
well I can see that form data. After the processing the page is redisplayed 
- but the data originally sent persits (in the request) this can be a pain 
if the user was to hit the refresh button then the data is submitted to the 
server again and if for example the php page does an insert into a database 
then a new row would be created etc...

Is this normal behaviour of php and jsp ? I am not sure but I am noticing it 
now with php ? Should I be clearing the data from the request somehow after 
I have done my processing?

Thanks

Matt

_
It's fast, it's easy and it's free. Get MSN Messenger today! 
http://www.msn.co.uk/messenger

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


[PHP] Forms

2003-11-19 Thread Matthew Oatham
Hi,

This is probably more of a javascript question but thought someone here 
might have an answer.

I have a form in a pop up windoe I want this form data to be submited to the 
window that opened the popup - how can I do this? I have tried setting the 
target attribute on the form tag to window.opener() but that just opens a 
new window.

Any ideas?

Thanks

_
Tired of 56k? Get a FREE BT Broadband connection 
http://www.msn.co.uk/specials/btbroadband

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


[PHP] html text area and mysql text fields

2004-07-27 Thread Matthew Oatham
Hi,

If I have a html textarea for inputting text into a database text field how can I keep 
the formatting of the entered text?

i.e. on the html textarea if the user enters carriage returns i.e. a new paragraph I 
want that to go into the database then when I retrieve it and display it on a normal 
html page I want to keep those carriage returns!

Thanks

Matt

[PHP] How do I return the error

2004-07-28 Thread Matthew Oatham
Hi I have this function below - if it reurns false I want to also return the error so 
I can print it in my calling function. Can I do this?

Cheers

Matt

function fileUpload($file) {
  if ($file['type'] == "image/gif" || $file['type'] == "image/pjpeg"){ 
if (@copy ($file['tmp_name'], "images/" . $file['name']))
  return true;
  }else { 
return false;
  }
}


Re: [PHP] How do I return the error

2004-07-28 Thread Matthew Oatham
what about returning the error the copy function would have thrown ?

Thanks

- Original Message - 
From: "John Nichel" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 28, 2004 3:00 PM
Subject: Re: [PHP] How do I return the error


> Matthew Oatham wrote:
> > Hi I have this function below - if it reurns false I want to also return
the error so I can print it in my calling function. Can I do this?
> >
> > Cheers
> >
> > Matt
> >
> > function fileUpload($file) {
> >   if ($file['type'] == "image/gif" || $file['type'] == "image/pjpeg"){
> > if (@copy ($file['tmp_name'], "images/" . $file['name']))
> >   return true;
> >   }else {
> > return false;
> >   }
> > }
> >
>
> $error = "";
> function fileUpload($file) {
>global $error;
>if ($file['type'] == "image/gif" || $file['type'] == "image/pjpeg"){
>  if (@copy ($file['tmp_name'], "images/" . $file['name']))
>return true;
>}else {
>  $error = "Something went wrong";
>  return false;
>}
> }
>
> if ( ! fileUpload ( $file ) ) {
> echo ( $error );
> }
>
> Course, there are numerous other ways of doing this.  I persoanlly use
> two custom functions to handle/display errors.
>
> -- 
> John C. Nichel
> ÜberGeek
> KegWorks.com
> 716.856.9675
> [EMAIL PROTECTED]
>
> -- 
> 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



[PHP] string manipulation

2004-08-12 Thread Matthew Oatham
Hi I am trying to track down a method for transferring a database id such as 5 into a 
nice formatted order id such as ORD0005 - where the format for the order id is "ORD" + 
5 digits made up of the database id

Thanks

Matt

[PHP] odd results with database string comparisons

2004-08-12 Thread Matthew Oatham
I have a database table with the column described as

address_line_2 varchar(255) NOT NULL default '',

when I do a select I want to see if there is anything in that column if there is text 
I will display it in a html table if there is nothing (the table default) I will write 
  However the following statement returns false regardless of if I have entered 
data or not!

if($row["address_line_2"]==' ')   // there is a space between the quotes

Please can you help me solve this, and let me know how I should construct my table and 
perform string comparisons.

Thanks



[PHP] gzip

2004-09-07 Thread Matthew Oatham
Hi,

I have a file on my server that I want to compress in a php page i.e take file.txt and 
add it to the archive file.zip.

How the hell do I do it using gzip cant understand the manual, or is there another way 
to create a zip file or other compressed file.

cheers

matt

[PHP] create a zip file

2004-09-07 Thread Matthew Oatham
Hi,

I have been trying to find a way of creating a zip file. I have a file on my server 
that I want to compress I have had a look at gzip but cant work out what to do. 

Can someone point me to a function or an example of how to do this.

thanks

matt

[PHP] MySQL backup

2004-05-13 Thread Matthew Oatham
Hi,

I am using MySQL database accessed via myphp admin - there is an export option which 
allows me to export the structure and data to an sql file but this is a manual 
procedure is there anyway to automate this via myphp admin i.e. using a cron job?

Thanks

Re: [PHP] MySQL backup

2004-05-13 Thread Matthew Oatham
Mmmm my provider doesn't give me access to this area !

- Original Message - 
From: "John W. Holmes" <[EMAIL PROTECTED]>
To: "Matthew Oatham" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Thursday, May 13, 2004 6:40 PM
Subject: Re: [PHP] MySQL backup


> From: "Matthew Oatham" <[EMAIL PROTECTED]>
>
> > I am using MySQL database accessed via myphp admin -
> > there is an export option which allows me to export the structure
> > and data to an sql file but this is a manual procedure is there
> > anyway to automate this via myphp admin i.e. using a cron job?
>
> The mysqldump program in the mysql/bin folder is used for this. Make a
call
> to it through cron or a PHP script.
>
> ---John Holmes...
>
> -- 
> 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



[PHP] html form elements as php arrays

2004-05-06 Thread Matthew Oatham
Hi,

I am retrieving data from a database and displaying results on a html so the user can 
edit them, I am sending the html form back to the server as an array, i.e on my html 
for I might have 10 name fields so in the html code all name fields are named name[] 
then I can iterate through the array on the server. My problem isn't strictly php but 
more html / javascript. if I have a load of form field elements all named name[] how 
do I access them to do javascript validation? i.e document.form.name[].value doesn't 
work! 

Cheers

Matt

[PHP] displaying database results with forward and back buttons

2004-07-11 Thread Matthew Oatham
Hi,

I have a query that returns lots of rows so I want to display the results in blocks of 
25 or so on my web page and have forward and back buttons to navigate the results. Can 
someone point me in the right directions please I have tried to look around for 
something using google but cant think of a suitable search term

Thanks

Matt

[PHP] form array

2004-02-11 Thread Matthew Oatham
Hi,

I have a form on page1 that i want to submit to another php page - page2

the form has the fields





Basically I want to have these form field values as an array of values I can
loop through on page 2 but what do I put on page 2 too get the array and
loop through ?

Thanks.

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



[PHP] PHP FILE SIZE LIMIT

2004-02-11 Thread Matthew Oatham
hi is there a limit to the filesize of a php ? 

I know tomcat had limits on the file size of jsps.

My problem is I have a 13kb php file when I add some more lines of code to it the html 
output becomes currupt - it could well be bad html but I cant find it so thought I 
would ask this question?

Cheers.

Matt

[PHP] MySQL update

2004-02-24 Thread Matthew Oatham
Hi,

I have an update statement that tries to update a number of values - these values have 
unique value constraint so when I do the update it will either succeed or fail. If it 
fails how can I determine where the update failed. i.e. pinpoint the value that was 
not unique?

At the moment I am doing ...

$sql = mysql_query("UPDATE dis_user SET first_name = '$firstName', last_name = 
'$lastName', email_address = '$emailAddress' WHERE user_id = '$userId'");

if(!$sql) {
echo "Data not inserted due error";
}

How can I improve on the above to give specific error information.

Thanks

Matt

[PHP] date functions

2004-02-24 Thread Matthew Oatham
Hi,

You might already be fed up with my posts but I'm a complete PHP newbie and find these 
groups are the best way to learn! Anyway I have the database date in the format: 
-mm-dd hh:mm:ss e.g. 2004-02-24 07:57:59 but when in some situations I only want 
to show the user the date in the format dd-mm- what is the correct / best php 
function to use for this purpose ?

Cheers.

Matt

[PHP] setting request variables

2004-03-03 Thread matthew oatham
Hi, 

I have created a small login system for my website. However if a user logs in 
incorrectly I want to display a error message currently I use the code

echo "You could not be logged in! Either the username and password do not match or 
you have not validated your membership! 
Please try again! ";
include  ("login.php");

However this appears at the top of my website but I want it to appear above the login 
form so I though I could set a variable in the request called "error" or similar then 
on the login page just above the login form check for the presence of the request 
variable "error" and print the appropriate message. So I want to do the following:

SET REQUEST VARIABLE ERROR HERE
include  ("login.php");

But can I set a request variable? i.e in JAVA I would do 
HttpRequest.setAttribute("error", true); etc..

Any help?

Cheers

[PHP] setting request variables

2004-03-03 Thread matthew oatham
Hi, 

I have created a small login system for my website. However if a user logs in 
incorrectly I want to display a error message currently I use the code

echo "You could not be logged in! Either the username and password do not match or 
you have not validated your membership! 
Please try again! ";
include  ("login.php");

However this appears at the top of my website but I want it to appear above the login 
form so I though I could set a variable in the request called "error" or similar then 
on the login page just above the login form check for the presence of the request 
variable "error" and print the appropriate message. So I want to do the following:

SET REQUEST VARIABLE ERROR HERE
include  ("login.php");

But can I set a request variable? i.e in JAVA I would do 
HttpRequest.setAttribute("error", true); etc..

Any help?

Cheers

[PHP] server side redirects

2004-03-03 Thread matthew oatham
Hi,

I have a page that checks to see if a session exists and if so does a server side 
redirect - i tired using header("Location: membersArea.php"); but I got an error about 
headers already sent, guess this is because I have already output html before this php 
command. So I tried include ("membersArea.php"); this kind of worked but because I am 
using php includes for my website header and footer I got strange results when the 
webpage was rendered. Therefor I used echo ""; This works but are there any drawbacks? i.e. is 
there a more elegant way to deal with my situation? Is this method supported by all 
browsers etc..

Cheers.

Matt

[PHP] Re: server side redirects

2004-03-03 Thread matthew oatham
Unfortunately I include the session_start();  method in the file header.php
(because I am checking for a value here to determine whether to show a
logout button or not) therefore I cant do the



at the top of the page because the server will not be able to get hold of
the session to see if session_is_registered('userId') evaluates to true!

I suppose I could remove session_start(); from the header.php and hard code
it at the top of every page !

Matt.


- Original Message - 
From: "Ben Ramsey" <[EMAIL PROTECTED]>
Newsgroups: php.general
To: "Matthew Oatham" <[EMAIL PROTECTED]>
Sent: Thursday, March 04, 2004 12:49 AM
Subject: Re: server side redirects


> > guess this is because I have already output html before this php command
>
> Exactly right.  Why don't you use the header() function at the top of
> the page before sending any other headers?  It will definitely work that
> way.  And if the problem is because you're doing some evaluation down in
> your page, take that evaluation out and bring it up above the headers,
> as well.  I usually do all my page processing and evaluation at the top
> of my pages before I write any HTML.
>
> As for the meta redirect, I'm not sure of any problems there (others
> will likely know better than I), but I think it's best to have your
> application do the redirect from the server-side rather than the
> client-side.  If your evaluation is high enough in the page to know to
> print the meta redirect tag, then you can probably afford to move it
> just a few lines higher than the  tag and use header() instead.
> Doing things on the server-side is always best and more secure;
> end-users are less likely to be able to screw things up.
>
> -- 
> Regards,
>   Ben Ramsey
>   http://benramsey.com
>   http://www.phpcommunity.org/wiki/People/BenRamsey
>

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



Re: [PHP] setting request variables

2004-03-03 Thread matthew oatham
but what if I wanted the variable $error to be a message. I want to set a
variable called $error to something like "invalided password" then display
this on the login page.

Cheers

Matt
- Original Message - 
From: "Tom Rogers" <[EMAIL PROTECTED]>
To: "matthew oatham" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, March 04, 2004 12:24 AM
Subject: Re: [PHP] setting request variables


> Hi,
>
> Thursday, March 4, 2004, 9:08:19 AM, you wrote:
> mo> Hi,
>
> mo> I have created a small login system for my website. However
> mo> if a user logs in incorrectly I want to display a error message
> mo> currently I use the code
>
> mo> echo "You could not be logged in! Either the username and
> mo> password do not match or you have not validated your membership!
> mo> 
> mo> Please try again! ";
> mo> include  ("login.php");
>
> mo> However this appears at the top of my website but I want it
> mo> to appear above the login form so I though I could set a variable
> mo> in the request called "error" or similar then on the login page
> mo> just above the login form check for the presence of the request
> mo> variable "error" and print the appropriate message. So I want to
> mo> do the following:
>
> mo> SET REQUEST VARIABLE ERROR HERE
> mo> include  ("login.php");
>
> mo> But can I set a request variable? i.e in JAVA I would do
> mo> HttpRequest.setAttribute("error", true); etc..
>
> mo> Any help?
>
> mo> Cheers
>
> add something like this to login.php
>
> if(!empty($error)){
>   echo ''.$error.'';
> }
>
> as it is included it will have $error available to it
> -- 
> regards,
> Tom
>
> -- 
> 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: Re[2]: [PHP] setting request variables

2004-03-04 Thread matthew oatham
Thanks for your reply,

I am still a bit confused though as the var error is never set! i.e. in your
code example below $error is never going to be set! Basically I have 2 pages
as follows:

page1.php - login form page
page2.php - validation page

page2.php checks the usernae and password against database and if all is
well it sends to the members area. If there was an error then it sends back
to the login page. When there is an error on page2.php I want to set a
request variabel called "$someError" with a value representing the error
that occured i.e. "Please enter a username" or "Please enter a password" or
"Invalid username" or "invalid password" etc.. Then on page1.php just before
the login form I would do:

if (!empty($_POST('someError'))) {
  echo $_POST('someError');
}
//display login form.

So my question is how do I add the variable $someError to the request with
the value "invalid usernam" and disaply this on page1.php

   $error = ''; //assume no errors
   if(isset($_PHP['password'] && !empty($_POST['username']){
$sql = "SELECT id FROM members WHERE
username = '".$_POST['username']."'
AND password = '".$_POST['password']."'";
 $result = mysql_query($sql);
 if(!$mysql_num_rows($result) > 0){
  $error = 'Error: Invalid password';
  include('login.php');
  exit;
}
   //password ok
   echo 'Welcome '.$_POST['username'].'';
 }else{
  //first pass and $error is still empty
  include('login.php');
 }
- Original Message - 
From: "Tom Rogers" <[EMAIL PROTECTED]>
To: "matthew oatham" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, March 04, 2004 2:02 AM
Subject: Re[2]: [PHP] setting request variables


> Hi,
>
> Thursday, March 4, 2004, 11:08:06 AM, you wrote:
> mo> but what if I wanted the variable $error to be a message. I want to
set a
> mo> variable called $error to something like "invalided password" then
display
> mo> this on the login page.
>
> mo> Cheers
>
> mo> Matt
> mo> - Original Message - 
> mo> From: "Tom Rogers" <[EMAIL PROTECTED]>
> mo> To: "matthew oatham" <[EMAIL PROTECTED]>
> mo> Cc: <[EMAIL PROTECTED]>
> mo> Sent: Thursday, March 04, 2004 12:24 AM
> mo> Subject: Re: [PHP] setting request variables
>
>
> >> Hi,
> >>
> >> Thursday, March 4, 2004, 9:08:19 AM, you wrote:
> >> mo> Hi,
> >>
> >> mo> I have created a small login system for my website. However
> >> mo> if a user logs in incorrectly I want to display a error message
> >> mo> currently I use the code
> >>
> >> mo> echo "You could not be logged in! Either the username and
> >> mo> password do not match or you have not validated your membership!
> >> mo> 
> >> mo> Please try again! ";
> >> mo> include  ("login.php");
> >>
> >> mo> However this appears at the top of my website but I want it
> >> mo> to appear above the login form so I though I could set a variable
> >> mo> in the request called "error" or similar then on the login page
> >> mo> just above the login form check for the presence of the request
> >> mo> variable "error" and print the appropriate message. So I want to
> >> mo> do the following:
> >>
> >> mo> SET REQUEST VARIABLE ERROR HERE
> >> mo> include  ("login.php");
> >>
> >> mo> But can I set a request variable? i.e in JAVA I would do
> >> mo> HttpRequest.setAttribute("error", true); etc..
> >>
> >> mo> Any help?
> >>
> >> mo> Cheers
> >>
> >> add something like this to login.php
> >>
> >> if(!empty($error)){
> >>   echo ''.$error.'';
> >> }
> >>
> >> as it is included it will have $error available to it
> >> -- 
> >> regards,
> >> Tom
> >>
> >> -- 
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
>
>
> well that would be easy, for example
>
> $error = ''; //assume no errors
> if(isset($_PHP['password'] && !empty($_POST['username']){
>   $sql = "SELECT id FROM members WHERE
>   username = '".$_POST['username']."'
>   AND password = '".$_POST['password']."'";
>   $result = mysql_query($sql);
>   if(!$mysql_num_rows($result) > 0){
> $error = 'Error: Invalid password';
> include('login.php');
> exit;
>   }
>   //password ok
>   echo 'Welcome '.$_POST['username'].'';
> }else{
>  //first pass and $error is still empty
>  include('login.php');
> }
> -- 
> regards,
> Tom
>
>

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



[PHP] php session ID attached to URL

2004-03-04 Thread matthew oatham
Hi,

I have a quick question about PHP session. In my website I have included the command 
session_start(); at the top of every page. Firstly is this correct? Secondly when I 
visit the website the first link I click on has the php session ID appended to the url 
however this php session ID is not appended to subsequent links ! Is this correct 
behaviour? What is going on? Can anyone explain?

Thanks

Matt

Re: Re[4]: [PHP] setting request variables

2004-03-04 Thread matthew oatham
Sorry, I understand now! Thanks for your help and your patience !

It works!

Matt
- Original Message - 
From: "Tom Rogers" <[EMAIL PROTECTED]>
To: "matthew oatham" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, March 04, 2004 11:27 AM
Subject: Re[4]: [PHP] setting request variables


> Hi,
>
> Thursday, March 4, 2004, 8:11:16 PM, you wrote:
> mo> Thanks for your reply,
>
> mo> I am still a bit confused though as the var error is never set! i.e.
in your
> mo> code example below $error is never going to be set! Basically I have 2
pages
> mo> as follows:
>
> mo> page1.php - login form page
> mo> page2.php - validation page
>
> mo> page2.php checks the usernae and password against database and if all
is
> mo> well it sends to the members area. If there was an error then it sends
back
> mo> to the login page. When there is an error on page2.php I want to set a
> mo> request variabel called "$someError" with a value representing the
error
> mo> that occured i.e. "Please enter a username" or "Please enter a
password" or
> mo> "Invalid username" or "invalid password" etc.. Then on page1.php just
before
> mo> the login form I would do:
>
> mo> if (!empty($_POST('someError'))) {
> mo>   echo $_POST('someError');
> mo> }
> mo> //display login form.
>
> mo> So my question is how do I add the variable $someError to the request
with
> mo> the value "invalid usernam" and disaply this on page1.php
>
> mo>$error = ''; //assume no errors
> mo>if(isset($_PHP['password'] && !empty($_POST['username']){
> mo> $sql = "SELECT id FROM members WHERE
> mo> username = '".$_POST['username']."'
> mo> AND password = '".$_POST['password']."'";
> mo>  $result = mysql_query($sql);
> mo>  if(!$mysql_num_rows($result) > 0){
> mo>   $error = 'Error: Invalid
password';
> mo>   include('login.php');
> mo>   exit;
> mo> }
> mo>//password ok
> mo>echo 'Welcome '.$_POST['username'].'';
> mo>  }else{
> mo>   //first pass and $error is still empty
> mo>   include('login.php');
> mo>  }
> mo> - Original Message - 
> mo> From: "Tom Rogers" <[EMAIL PROTECTED]>
> mo> To: "matthew oatham" <[EMAIL PROTECTED]>
> mo> Cc: <[EMAIL PROTECTED]>
> mo> Sent: Thursday, March 04, 2004 2:02 AM
> mo> Subject: Re[2]: [PHP] setting request variables
>
> But you are not posting to the login page ...you are including it so
> all the variables are available. $error only gets filled if there is
> an error, thats why in login.php we do a check to see if it is
> !empty() which would indicate something has gone wrong.
>
> Try this simplified code to demonstrate the flow:
> (validate.php)
>  if(isset($_POST['submit'])){
> $error = '';
> if($_POST['username'] != 'Fred'){
> $error = 'Error: You did not
enter Fred';
> include('./login.php');
> exit;
> }else{
> ?>
> 
> 
> Success
> 
> 
>  Welcome Fred
> 
> 
>  }
> }else{
> include('./login.php');
> }
> ?>
>
> (login.php)
>
> 
> 
> Login
> 
> 
> 
> 
> 
> Login
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>
> Then go to validate.php or login.php it won't matter :)
>
> -- 
> regards,
> Tom
>
> -- 
> 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



[PHP] protecting directories and files inside them based on session variables

2004-03-04 Thread Matthew Oatham
Hi,

I have created a small website members area - this is protected using php session 
variables so to access it a variable user_id must exist in the session. However I have 
a directory on my webserver that holds documents that I want to make accessible only 
to users who have logged in however because this directory contains word documents 
nothing stops someone from finding the url i.e. 
http://www.mydomain.com/private/some_privat_file.doc and downloading this file! I need 
a way to make this file only accessible to users who have a user_id in there session - 
is this possible? Or is my only alternative to password protect this directory using 
the webserver and force users to re-authenticate in order to download there files?

Cheers


[PHP] protecting directories and files inside them based on session variables

2004-03-04 Thread matthew oatham
Hi,

I have created a small website members area - this is protected using php session 
variables so to access it a variable user_id must exist in the session. However I have 
a directory on my webserver that holds documents that I want to make accessible only 
to users who have logged in however because this directory contains word documents 
nothing stops someone from finding the url i.e. 
http://www.mydomain.com/private/some_privat_file.doc and downloading this file! I need 
a way to make this file only accessible to users who have a user_id in there session - 
is this possible? Or is my only alternative to password protect this directory using 
the webserver and force users to re-authenticate in order to download there files?

Cheers


[PHP] Any Ideas?

2004-03-22 Thread Matthew Oatham
Hi,

Sorry to ask this question, I am fairly new to PHP and wanted to ask for some help 
with the following.

I have a MySQL table which uses a auto_increment int as the primary key - when I do an 
insert I want to create another id based on the primary key and insert this into the 
same table i.e. if I do an insert and the primary key is 3 I want to generate the ID 
CR-003, if the primary key was 34 I would want to generate the id CR-034. So I guess I 
need to know the following. 

are there any functions that retrieve the last primary key created in the MySQL table?
are there any math functions that will turn 1 into 001 or 34 into 034 or keep 213 as 
213 etc...
what would be the best implementation i.e. do an insert, get the primary key then do 
an update or lock the table use a function to get the next availible primary key 
generate the additional key and then do 1 insert? Guess this implementation depends on 
how / if I can lock the MySQL table.

Sorry its a long one! 

Cheers

Matt


Re: [PHP] Any Ideas?

2004-03-22 Thread Matthew Oatham
The idea was that the user uploads a file and I insert details about the
file into the mysql table and rename the file using the generated id.

so if the next primary key is 4 I generate the file id CR-004 and rename the
uploaded file to CR-004 whilst also storing CR-004 in the table.

Thanks for your ideas so far - very useful! How do you get to know about all
these useful functions?

Cheers

Matt
- Original Message - 
From: "John W. Holmes" <[EMAIL PROTECTED]>
To: "Robert Cummings" <[EMAIL PROTECTED]>
Cc: "Matthew Oatham" <[EMAIL PROTECTED]>; "PHP-General"
<[EMAIL PROTECTED]>
Sent: Tuesday, March 23, 2004 12:25 AM
Subject: Re: [PHP] Any Ideas?


> Robert Cummings wrote:
>
> > On Mon, 2004-03-22 at 18:51, Matthew Oatham wrote:
> >
> >>Hi,
> >>
> >>are there any functions that retrieve the last primary key created in
> >>the MySQL table?
> >
> >
> > http://www.php.net/manual/en/function.mysql-insert-id.php
>
> If you read the whole question, though, the poster wanted to use the ID
> in the same query, just in another column. mysql_insert_id() or
> LAST_INSERT_ID() wouldn't help in this case.
>
> -- 
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com
>
> -- 
> 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] Any Ideas?

2004-03-22 Thread Matthew Oatham
Bit rough at the moment but I have come up with the following - it doesn't
rename the file using the new ID yet but I am more concerned about my method
for creating the new ID - can anyone see any potential problems such as
database problems, i.e duplicate keys, bad coding practices etc... cheers
matt

if(!empty($_FILES["cr"])) {
$uploaddir = "cr/"; // set this to wherever
//copy the file to some permanent location
if (move_uploaded_file($_FILES["cr"]["tmp_name"], $uploaddir .
$_FILES["cr"]["name"])) {
echo("file uploaded\n");
echo(generateCrId(insertChangeRequest()));
} else {
echo ("error!");
}
}

function insertChangeRequest() {

$sql = mysql_query("INSERT INTO dis_status(status, description)
VALUES('status1', 'status1 description')") or die (mysql_error());

return mysql_insert_id();
}

function generateCrId($key) {

$crId = sprintf("CR-%03d", $key);

return $crId;
}


----- Original Message - 
From: "John W. Holmes" <[EMAIL PROTECTED]>
To: "Robert Cummings" <[EMAIL PROTECTED]>
Cc: "Matthew Oatham" <[EMAIL PROTECTED]>; "PHP-General"
<[EMAIL PROTECTED]>
Sent: Tuesday, March 23, 2004 12:25 AM
Subject: Re: [PHP] Any Ideas?


> Robert Cummings wrote:
>
> > On Mon, 2004-03-22 at 18:51, Matthew Oatham wrote:
> >
> >>Hi,
> >>
> >>are there any functions that retrieve the last primary key created in
> >>the MySQL table?
> >
> >
> > http://www.php.net/manual/en/function.mysql-insert-id.php
>
> If you read the whole question, though, the poster wanted to use the ID
> in the same query, just in another column. mysql_insert_id() or
> LAST_INSERT_ID() wouldn't help in this case.
>
> -- 
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com
>
> -- 
> 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



[PHP] string concatination

2004-03-23 Thread Matthew Oatham
Hi, 

What is the correct way, using php to join to strings, vars or other wise.

i.e. how do I join

$string1 = "hello";
$string2 = "world";

do i do

$string1 . $string2;

and what about ..

$string2 = $string1 . "world";

Is that correct?



[PHP] time function

2004-03-25 Thread Matthew Oatham
Hi,

I have a TIME field type in mysql database I want to do a select and add all the times 
together to return a total time, can I do this using the select statement?

cheers

matt

[PHP] transactions

2004-03-29 Thread Matthew Oatham
Hi,

Is there an elegant way to recover from DB errors in MySQL using PHP, i.e. 
transactions and rolling back - basically I have an insert statement then an update 
statement. if the insert succeeds the update is run but if the update fails I want to 
undo the insert! 

Any suggestions, I guess I could get the last inserted row id and perform an sql 
delete but is there a more elegant way?

Cheers

Matt

[PHP] Code Review PLEASE !!!

2004-04-05 Thread Matthew Oatham
Hi,

I am a newbie PHP programmer, I have some code that works but I want some tips on how 
I an Improve my code, i.e. should I be doing my updates / deletes on same php page as 
the display page, am I using transactions correctly, am I capturing SQL errors 
correctly am I handling form data as efficient as possible?

My code displays some information from a database and gives users the chance to delete 
or edit any field and is as follows: 

 $value) {
$fleetCode = $_POST['fleet_code'][$key];
$historyUrl = $_POST['history_url'][$key];
$downloadUrl = $_POST['download_url'][$key];
mysql_query("UPDATE imp_fleet SET fleet_code = '$fleetCode', history_url = 
'$historyUrl', download_url = '$downloadUrl' WHERE fleet_id = $value") or die 
(mysql_error());
  }
  if ($deleteList) {
mysql_query("DELETE FROM imp_fleet WHERE fleet_id IN($deleteList)") or die 
(mysql_error());
  }
  if (mysql_error()) {
echo ("There has been an error with your edit / delete request. Please contact the 
webmaster");
mysql_query("rollback");
  } else {
mysql_query("commit");
  }
}

?>


  



Edit / Delete Fleet
  

  Fleet Code
  Download URL
  History URL
  Delete

 0) { 
while ($row = mysql_fetch_array($sql)) {
?>  
 
  
  
  
 
   


 
  

  

  
  

  

  




Thanks for your time and feedback.

Matt

Re: [PHP] Code Review PLEASE !!!

2004-04-05 Thread Matthew Oatham
Yes I agree I need some validation, dunno whether to do server or client
side validation. I don't think the fleet_id example will be a problem though
as this is retrieved from the database where the field is an int.

Thanks for your feedback

Matt
- Original Message - 
From: "Jordan S. Jones" <[EMAIL PROTECTED]>
To: "Matthew Oatham" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Monday, April 05, 2004 11:56 PM
Subject: Re: [PHP] Code Review PLEASE !!!


> Wells first of all, you are going to want better form input validation.
> For Example:
>
> foreach ($_POST['fleet_id'] as $key => $value) {
> $fleetCode = $_POST['fleet_code'][$key];
> $historyUrl = $_POST['history_url'][$key];
> $downloadUrl = $_POST['download_url'][$key];
> mysql_query("UPDATE imp_fleet SET fleet_code = '$fleetCode',
history_url = '$historyUrl', download_url = '$downloadUrl' WHERE fleet_id =
$value") or die (mysql_error());
>   }
>
>
> Are you sure that $_POST['fleet_id'] is valid? or even a number?
>
> What happens with $_POST['fleet_id'] == '1 = 1'??  Well, long story
> short, imp_fleet has no more records.
>
> Just a simple example of a huge problem.
>
> Jordan S. Jones
>
> Matthew Oatham wrote:
>
> >Hi,
> >
> >I am a newbie PHP programmer, I have some code that works but I want some
tips on how I an Improve my code, i.e. should I be doing my updates /
deletes on same php page as the display page, am I using transactions
correctly, am I capturing SQL errors correctly am I handling form data as
efficient as possible?
> >
> >My code displays some information from a database and gives users the
chance to delete or edit any field and is as follows:
> >
> > >
> >include ("../db.php");
> >
> >$acton = $_POST['action'];
> >
> >if ($action == "update") {
> >  if (isset($_POST['delete'])) {
> >$deleteList = join(', ', $_POST['delete']);
> >  }
> >
> >  //Enter info into the database
> >  mysql_query("begin");
> >  foreach ($_POST['fleet_id'] as $key => $value) {
> >$fleetCode = $_POST['fleet_code'][$key];
> >$historyUrl = $_POST['history_url'][$key];
> >$downloadUrl = $_POST['download_url'][$key];
> >mysql_query("UPDATE imp_fleet SET fleet_code = '$fleetCode',
history_url = '$historyUrl', download_url = '$downloadUrl' WHERE fleet_id =
$value") or die (mysql_error());
> >  }
> >  if ($deleteList) {
> >mysql_query("DELETE FROM imp_fleet WHERE fleet_id IN($deleteList)")
or die (mysql_error());
> >  }
> >  if (mysql_error()) {
> >echo ("There has been an error with your edit / delete request.
Please contact the webmaster");
> >mysql_query("rollback");
> >  } else {
> >mysql_query("commit");
> >  }
> >}
> >
> >?>
> >
> >
> >  
> >
> >
> >
> >Edit / Delete Fleet
> >  
> >
> >  Fleet Code
> >  Download URL
> >  History URL
> >  Delete
> >
> > >$sql = mysql_query("SELECT fleet_id, fleet_code, download_url,
history_url FROM
> >imp_fleet");
> >
> >if (mysql_num_rows($sql) > 0) {
> >while ($row = mysql_fetch_array($sql)) {
> >?>
> >
> >  
> >  
> >  
> >  
> >
> > >}
> >}
> >?>
> >
> >  
> >
> >  
> >
> >
> >  
> >
> >  
> >
> >  
> >
> >
> >
> >
> >Thanks for your time and feedback.
> >
> >Matt
> >
> >
>
> -- 
> 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