By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

how to abstract $_POST?

P: 3
I've been trying to solve this same problem that the user has http://bytes.com/topic/php/answers/2068-form-post-doesnt-work . However, I don't know how he managed to fix it, he says "He just abstracted the $_POST as Request() and it worked.." Any idea how to do it? Thanks in advance!
Dec 6 '11 #1

✓ answered by johny10151981

you are using short tag, make sure your php.ini allowed short tag

Share this Question
Share on Google+
5 Replies


100+
P: 1,059
Whats wrong with $_POST??

If you use function like Request, you will face a different problem, say if you send data in GET and POST method in the same request and somehow you have the same variable in uri and in post value with different value, your application will lost one value

$_POST and $_GET is global. From anywhere it can be used.
Dec 6 '11 #2

100+
P: 1,059
One Solution is:
Expand|Select|Wrap|Line Numbers
  1. function Request($var)
  2. {
  3.  if(isset($_GET[$var])==true)
  4.   return $_GET[$var];
  5.  if(isset($_POST[$var])==true)
  6.   return $_POST[$var];
  7.  return "";
  8. }
  9.  

Creating another class or array is pointless because whether you want or not $_GET and $_POST is there
Dec 6 '11 #3

P: 3
Thank you for an immediate reply.. :D
umm.. still I can't get it to work.. here's a simple code that simply won't run :( .. It use to work when I'm using php4 but when I upgraded to php5.3, I can't get it to work.. Am I missing something?

# home.php

<form action = "logfilter.php" method = "POST">
Username: <input type = "text" name = "t1"/>
Password: <input type = "password" name = "t2"/>
<input type = "submit" name = "submit" value = "Log In" style="width:60"/>
<input type = "submit" name = "submit" value = "Sign Up" style="width:60"/>
</form>

# logfilter.php

<?php
include 'conn.php';

$user = $_POST['t1'];
$pass = $_POST['t2'];
$status = "Activated";

$query=mysql_query("Select * from tbluser where username = '".$user."' and password = '".$pass."' and status = '".$status."'");
$result=mysql_fetch_array($query);

if($_POST['submit']=="Sign Up")
{
header('location:signupform.php');
}
else if($_POST['submit']=="Log In")
{

if($user=="" or $pass=="")
{
?>
<script type = "text/javascript">
alert("Your Login Detail is Invalid");
window.location="index.php"
</script>
<?
}
else if($user==$result['username'] and $pass==$result['password'] and $status==$result['status'])
{
session_start();
$_SESSION['code']="User";
$_SESSION['id']=$result['id'];
header('location:myaccount.php');
}
else
{
?>

<script type = "text/javascript">
alert("Your Login Detail is Invalid");
window.location="index.php"
</script>
<?
}
}

?>

It says "Parse error: syntax error, unexpected $end in C:\xampp\htdocs\fb\logfilter.php on line 46"
Dec 7 '11 #4

100+
P: 1,059
you are using short tag, make sure your php.ini allowed short tag
Dec 7 '11 #5

P: 3
Oh.. great.. thanks!
Dec 7 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.