10 Replies - 2565 Views - Last Post: 24 September 2009 - 07:31 AM Rate Topic: -----

#1 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

$_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 05:28 AM

Hi,

I am having a weird problem here, my $_POST doesn't seem to be working. Here is a simplified script on the code I am running:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Add your email address to the list</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<form action="addemail.php" method="POST">
<label for="firstname">First name</label>
<input type="text" id="firstname" name="firstname" /><br />
<label for="secondname">Second name</label>
<input type="text" id="secondname" name="secondname" /><br />
<label for="emailaddress">Email</label>
<input type="input" name="email" id="email" /><br />
<input type="submit" value="Add me!" name="submit" />
</form>
</body>
</html>


And the addemail.php to process the data:

<?php

$firstname = $_POST['firstname'];
$secondname = $_POST["secondname"];
$email = $_POST["email"];

//just a check to see if we have the variables set...

echo "firstname:".$firstname."<br />"; #its not echoing the value of firstname here...its just blank

$connect = mysqli_connect("localhost","$username","$password","$db")
or die("Could not connect to the database");

$query = "INSERT INTO email_list SET first_name=\"$firstname\",last_name=\"$secondname\",email=\"$email\"";

$result = mysqli_query($connect,$query)
or die("COULD NOT QUERY DATABASE!<br />".mysqli_error($connect));

echo "Email successfully added!";

mysqli_close($connect);

?>



strange enough if I use GET everything is executing well...what could be problem?

Thanks

This post has been edited by coolmac112: 24 September 2009 - 05:31 AM


Is This A Good Question/Topic? 0
  • +

Replies To: $_POST is not working but $_GET Is...help!

#2 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 230
  • Joined: 29-December 08

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 05:32 AM

That is indeed odd, by any chance, have you tried rewriting 'POST' in your HTML as 'post' (all lower case), I do know that XHTML doesn't allow all capital attributes.... don't know if it's that that is causing the problem though.
Was This Post Helpful? 0
  • +
  • -

#3 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 05:38 AM

Alright i just did a little edit:

removed the <!DOCTYPE at the beginning of the file and replaced with this:
<!DOCTYPE HTML PUBLIC

				 "-//W3C//DTD HTML 4.01 Transitional//EN"

				 "http://www.w3.org/TR/html401/loose.dtd">

<html>
everything worked well....what is wrong with this?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


and i also wish to know how it influence $_POST and how the problem can be resolved.

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 230
  • Joined: 29-December 08

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 05:39 AM

You didn't have to change the Doctype, my suggestion was just to replace
<form action="addemail.php" method="POST">


with
<form action="addemail.php" method="post">


This post has been edited by Christopher Elison: 24 September 2009 - 05:40 AM

Was This Post Helpful? 0
  • +
  • -

#5 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 06:03 AM

I had indeed tried that a couple times but it still wasn't working.

I then changed the doctype and now its working but it baffles me why POST is not working when the other doctype is there..

could it be something to do with the "xhtml1-transitional.dtd"" or "<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">"?

My head is spinning!
Was This Post Helpful? 0
  • +
  • -

#6 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 230
  • Joined: 29-December 08

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 06:07 AM

Try this as your doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">



It's the one I usually use for anything I do in HTML.
Was This Post Helpful? 0
  • +
  • -

#7 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 06:19 AM

There must be something wrong with the other one i was using that was causing that error because yours works too!!

Thanks for the help mate!

i like your site...but there's not much content on it...but you've motivated me to start my own too!

This post has been edited by coolmac112: 24 September 2009 - 06:25 AM

Was This Post Helpful? 0
  • +
  • -

#8 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 06:20 AM

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



using this doctype ( which is what i always use ) i have tested using post or POST and it works fine ... now validating the code i get a error because capital attributes is not allowed bla bla bla ...

Additionally i tested your code and it is working accordingly ... are you using any type of framework in your work? Sometimes frameworks have a built in functionality of forcing doctypes ... just thought i would throw that in :)
Was This Post Helpful? 0
  • +
  • -

#9 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 06:29 AM

Thanks rpgonzo but i'm a newbie...so let's keep to english...frameworks?

I don't think i'm using any...

btw you seem not to have copied all of it...here you go:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


!!
Was This Post Helpful? 0
  • +
  • -

#10 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 230
  • Joined: 29-December 08

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 06:35 AM

View Postcoolmac112, on 24 Sep, 2009 - 12:19 PM, said:

i like your site...but there's not much content on it...but you've motivated me to start my own too!


If you mean mine, you're right, I stopped working on it ages ago, I got a freelance project, then I started working on other sites so haven't given it much time, and this was before I discovered using CSS frameworks such as Blueprint and the joy of using jQuery, think I'm going to start again from scratch on it soon, this time using Blueprint and jQuery.

I'm glad I motivated you though, be sure to post it in the 'site review' forum once you've made it :)
Was This Post Helpful? 0
  • +
  • -

#11 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: $_POST is not working but $_GET Is...help!

Posted 24 September 2009 - 07:31 AM

i was expressly focused on the doctype not the html tag as well ...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">



thats a copy of my exact one ... if you don't know what a framework is than you , more than likely, are not using one ... if you look up in the php programmers form there is a thread about frameworks ... but if your just starting learn the basics than go there ... :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1