[PHP] newbie: problem with $_Post[]

2009-07-27 Thread A.a.k

Hello
I have a very simple test form named "pass.php"  :


username : 
password :  





getting "Notice: Undefined index: user" and "Notice: Undefined index: pass".
changing form action to another page will solve the problem but i want to be 
able to use $_POST array on the same page, how can i do it?

thanks in advance

/Arash


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



Re: Fwd: [PHP] newbie: problem with $_Post[]

2009-07-27 Thread A.a.k

Hello
Richard, that is exactly what I was looking for. thanks alot
Paul, I didn't know its possible to use error_reporting(), that's a good 
hint thanks.
btw if you guys know any simple php application that I can study and learn 
faster than going through books please let me know. I tried Wordpress but 
its too complicated for a beginner like me.



"Paul M Foster"  wrote in message 
news:20090728043523.gs14...@quillandmouse.com...

On Mon, Jul 27, 2009 at 09:01:16PM -0700, Richard S. Crawford wrote:


>> 
>> username : 
>> password :  
>> 
>> 
>>
>> > $user=$_POST['user'];
>> $pass=$_POST['pass'];
>> if(($user=="myname")&&($pass="mypass"))
>> echo "access granted";
>> else
>> echo "access denied";
>> ?>
>>
>> getting "Notice: Undefined index: user" and "Notice: Undefined index: 
>> pass".
>> changing form action to another page will solve the problem but i want 
>> to be

>> able to use $_POST array on the same page, how can i do it?
>> thanks in advance
>>
>> /Arash

Arash,

It's hard to respond when it's unclear exactly what you want to do.
I'm guessing that you want to simply have the same page show both the
form, and also process the form, so that you can cut down on the
number of pages you have to create.

The way I do this is by first checking to see if the $_POST array has
been set; if it has not been set, then I know that the form wasn't
filled out, and so the script needs to print out the form. If the
array has been set, on the other hand, then the script can process the
form data. Here's a real quick example of what I mean:

if (!isset($_POST)) { ?> // The $_POST array is not set, so display the 
form


username : 
password :  




Hope that helps.


Richard's right. This is the best way to do this.

Your original code had two problems. First, you're getting the error
message because you're allowing E_NOTICE level error messages. You can
turn these off with the error_reporting() function.

Second, as written, your page paints the form and then directly tests
the status of the variables before the user can respond; the whole page
of PHP code executes and then waits for user response. It's only when
the user responds and the page is revisited that the variables can
legitimately be tested. That's why Richard's method works. The
variables are only tested when the page is re-entered after the user
responds.

Paul

--
Paul M. Foster 



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



[PHP] clean url problem .htaccess

2009-07-31 Thread A.a.k

Hi
I'm trying to use clean urls in my application:
lets say convert http://mysite/article.php?id=3   to 
http://mysite/article/3/

my problem is to use /article act as it was /article.php
here is mt .htacess :

ForceType application/x-httpd-php

on php code parsing string from $_SERVER['PHP_SELF'] to get id out.

this one works if i use article.php (http://mysite/article.php/3/ works)
but i want to use /article without php extention. is there a way around? 



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



Re: [PHP] clean url problem .htaccess

2009-08-01 Thread A.a.k
what if I don't have access to server to enable mod_rewrite like a hosting, 
is there anyway to work around?
just don't want to build entire website and finally can't get a hosting to 
enable mod_rewrite for me.



"Andrew Ballard"  wrote in message 
news:b6023aa40907312352j405778fevd0c38315c3983...@mail.gmail.com...

On Sat, Aug 1, 2009 at 2:11 AM, A.a.k wrote:

Hi
I'm trying to use clean urls in my application:
lets say convert http://mysite/article.php?id=3 to
http://mysite/article/3/
my problem is to use /article act as it was /article.php
here is mt .htacess :

ForceType application/x-httpd-php

on php code parsing string from $_SERVER['PHP_SELF'] to get id out.

this one works if i use article.php (http://mysite/article.php/3/ works)
but i want to use /article without php extention. is there a way around?



Look up mod_rewrite.

Andrew 



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



[PHP] how to check function's execution?

2009-09-07 Thread A.a.k

hello
I have a problem to check whether a function successfully inject to database 
or not, here is the code :

  if($object->dbupdate())
  echo 'done';
else
   echo 'damn!';
inside the 'if' statement $obj->dbupdate() doesn't execute , how can I 
execute and check if it was a successful inject within this function? is it 
even possible or should I check within class or something? 



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



[PHP] header problem

2009-09-09 Thread A.a.k

hello
I recentrly uploaded my project from localhost to a hosting and found many 
errors and warnings which didnt have in local. one of the most annoying one 
is header('Location xxx').
I have used header to redirect users from pages, and kinda used it alot. i 
know about the whitespace causing warning, but most of the pages i'm sending 
users got html and php mixed so i'm confused about how to remove whitespace 
in a html/php file. the error is :

Warning: Cannot modify header information - headers already sent by 
here is a simple example, user update page :
if($valid)
   {
   $msg='111';
   $user->dbupdate();
header("Location: /admin/index.php?msg=$msg");

   }
   else
   {
foreach($errors as $val)
   echo ''.$val.'';
   }

and on admin index i get $msg and display it.

..
//lots of stuff
   ';
   break;
 case '421':...
   }
?>
//  more html and php

how can i fix this? 



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



Re: [PHP] header problem

2009-09-09 Thread A.a.k

is there any alternative to header() for redirect users?

"George Langley"  wrote in message 
news:b1b897d4-7448-4b71-bffc-3addc27ce...@shaw.ca...
Hi Blueman. As soon as ANYTHING has been drawn to the browser, you  cannot 
use a header command. So you need to work through all of your  code, and 
ensure that all of your logic that could result in a header  call is run 
BEFORE you send any html code. Is going to be tricky if  mixing html and 
php calls.


George


On 10-Sep-09, at 12:27 AM, A.a.k wrote:


hello
I recentrly uploaded my project from localhost to a hosting and  found 
many errors and warnings which didnt have in local. one of the  most 
annoying one is header('Location xxx').
I have used header to redirect users from pages, and kinda used it  alot. 
i know about the whitespace causing warning, but most of the  pages i'm 
sending users got html and php mixed so i'm confused about  how to remove 
whitespace in a html/php file. the error is :

Warning: Cannot modify header information - headers already sent  by 
here is a simple example, user update page :
   if($valid)
  {
  $msg='111';
  $user->dbupdate();
   header("Location: /admin/index.php?msg=$msg");

  }
  else
  {
   foreach($errors as $val)
  echo ''.$val.'';
  }

and on admin index i get $msg and display it.

..
//lots of stuff
  ';
  break;
case '421':...
  }
?>
//  more html and php

how can i fix 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