473,395 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

PHP $_POST with invalid data?

I've been busy coding a signup system with PHP.
There are 2 forms , form1 and form2.

form1 contains:
Name , Age ,
form 2 contains
Username , Password , Repeat Pass , Email

I use POST method to submit the form.
Here , name and age is sent from form1 to form2 and form2 gets it through $_POST vars. The next step is submitform.php , once form2 gets form1 data with $_POST , it submits its data (Username,Pass..) with form1 data as a
<input type="hidden"> field.
Ex.
Form2 :[php]
<form method="POST" action="submitform.php">
<input type="text" name="username"/>
<input type="password" name="password"/>
<input type="pass2" name="repeatpass"/>
<input type="email" name="email"/>
<input type="hidden" name="name" value="<? echo $_POST['name'];?>"/>
<input type="hidden" name="age" value="<? echo $_POST['age'];?>"/>
<input type="submit" name="sub" value="submit">
</form>[/php]Everything works fine but the prob am facing is , invalid data.
Everything that was submitted gets sent correctly.
But many times , I get name=ssss and age=32 in the submitform.php even though I had my name as "gamer" and age as "20" , once I go back and resubmit , it comes fine but again at times , I get the data "ssss" and "32" even when it wasnt submitted. I use Opera 9.26.
Why does this happen ? How do I avoid it?

Please help me.
Thanks.
Mar 20 '08 #1
7 2619
ronverdonk
4,258 Expert 4TB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 20 '08 #2
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Oh am really sorry , wont do that in future. LoL

Anyway guys please help.
Mar 20 '08 #3
ronverdonk
4,258 Expert 4TB
Only way to establish that is to also show the code of form1 and form2 scripts. That is the only way to be able to follow the data (POST) stream.

And don't forget the code tags!

Ronald
Mar 20 '08 #4
Only way to establish that is to also show the code of form1 and form2 scripts. That is the only way to be able to follow the data (POST) stream.

And don't forget the code tags!

Ronald
okay here is the flow

form 1
[PHP]
<form method="POST" action="form2.php">
<input type="text" name="name"/>
<input type="age" name="age"/>
<input type="submit" name="subone" value="submit"/>
</form>
[/PHP]
This submits to form 2:
form2
[PHP]
<form method="POST" action="submitform.php">
<input type="text" name="username"/>
<input type="password" name="password"/>
<input type="pass2" name="repeatpass"/>
<input type="email" name="email"/>
<input type="hidden" name="name" value="<? echo $_POST['name'];?>"/>
<input type="hidden" name="age" value="<? echo $_POST['age'];?>"/>
<input type="submit" name="sub" value="submit">
</form>
[/PHP]
This submits to submitform.php
submitform.php
[PHP]
<?
$user=$_POST['username'];
$pass=$_POST['password'];
$rpass=$_POST['repeatpass'];
$email=$_POST['email'];
$name=$_POST['name'];
$age=$_POST['age'];

$echo "Username:$user<br/>Password:$pass<br/>Repeat:$rpass<br/>
Email:$email<br/>Name:$name<br/>Age:$age<br/>";
?>
[/PHP]

Now as you see everything gets submitted to and displays the results but the prob is at times I get "Name=ssss Age=32" even when the name and age werent ssss and 32. I dont know why this happens , I use Opera , please help me.

Its just the invalid data thats get posted.
Mar 21 '08 #5
dlite922
1,584 Expert 1GB
okay here is the flow

form 1
[PHP]
<form method="POST" action="form2.php">
<input type="text" name="name"/>
<input type="age" name="age"/>
<input type="submit" name="subone" value="submit"/>
</form>
[/PHP]
This submits to form 2:
form2
[PHP]
<form method="POST" action="submitform.php">
<input type="text" name="username"/>
<input type="password" name="password"/>
<input type="pass2" name="repeatpass"/>
<input type="email" name="email"/>
<input type="hidden" name="name" value="<? echo $_POST['name'];?>"/>
<input type="hidden" name="age" value="<? echo $_POST['age'];?>"/>
<input type="submit" name="sub" value="submit">
</form>
[/PHP]
This submits to submitform.php
submitform.php
[PHP]
<?
$user=$_POST['username'];
$pass=$_POST['password'];
$rpass=$_POST['repeatpass'];
$email=$_POST['email'];
$name=$_POST['name'];
$age=$_POST['age'];

$echo "Username:$user<br/>Password:$pass<br/>Repeat:$rpass<br/>
Email:$email<br/>Name:$name<br/>Age:$age<br/>";
?>
[/PHP]

Now as you see everything gets submitted to and displays the results but the prob is at times I get "Name=ssss Age=32" even when the name and age werent ssss and 32. I dont know why this happens , I use Opera , please help me.

Its just the invalid data thats get posted.
that is weird, but you have a little error:

<input type="age" name="age"/>

should be

<input type="text" name="age"/>

there's no type="age" ^_^

that might cause the problem.

Also, follow the trail, where does the values happen, the first submit or second submit?

View source form2 and look at the values in the hidden field and see what they are.

With weird problems like this you have to STEP it (ie check the values with a end function like die() which will end the program at the point, printing variable values then will give you better tracing ability that will lead you to pin pointing your problem.

Good luck and happy coding,

And first day of spring!! :)

DM
Mar 21 '08 #6
that is weird, but you have a little error:

<input type="age" name="age"/>

should be

<input type="text" name="age"/>

there's no type="age" ^_^

that might cause the problem.

Also, follow the trail, where does the values happen, the first submit or second submit?

View source form2 and look at the values in the hidden field and see what they are.

With weird problems like this you have to STEP it (ie check the values with a end function like die() which will end the program at the point, printing variable values then will give you better tracing ability that will lead you to pin pointing your problem.

Good luck and happy coding,

And first day of spring!! :)

DM
LoL sorry for the invalid type error , didnt check it though.
Anyway I fixed the bug looking at the chain.
Thanks.
Mar 22 '08 #7
Markus
6,050 Expert 4TB
LoL sorry for the invalid type error , didnt check it though.
Anyway I fixed the bug looking at the chain.
Thanks.
And the bug was?

Regards
Mar 22 '08 #8

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

Similar topics

12
by: AJ Z | last post by:
I am using in_array() to search for a value ("other"), in order to validate a form. If I pass $_POST as the array to search PHP says that it is an invalid datatype. It is an array and if I copy...
14
by: billy.becker | last post by:
I need to save a wav file that is HTTP POSTed to a php page. What does PHP5 do automatically to a POSTed variable when it puts it in the $_POST superglobal array? I haven't been able to find any...
2
by: will.lai | last post by:
Hi: Just learning PHP and couldn't get access to the $_POST variables from a form. Here are my code sniplets below. For the life of me I can't figure out why the POST variables aren't being...
5
by: Mark Woodward | last post by:
Hi all, I'm trying to set up a 'control panel' consisting of a table of icons. The early stages: http://www.deepinit.com/controlcentre.php Each of these is set up like: <td> <input...
6
by: comp.lang.php | last post by:
I have no idea why this is happening and I need someone to explain this to me at the simplest level absolutely possible (pretend I'm a 10-year old and explain it that way, please!) This class...
12
by: Todd Michels | last post by:
Hi all, I am trying to send data from a form and insert it into a MSSQL DB. When I submit the data I get: Warning: mssql_query() : message: The name "Todd" is not permitted in this context....
7
by: amygdala | last post by:
Hi all, I'm starting this new project in which I'ld like to implement sort of a design pattern I have seen being used in the CodeIgniter framework. Basically, the site will examine the URI and...
4
by: Puzzled | last post by:
PHP 4.4 and PHP 5.2.3 on ubuntu. I am running Moodle 1.5.3 and have recently had a problem when updating a course. The $_POST variable is empty but only if a lot of text was entered into the...
4
anfetienne
by: anfetienne | last post by:
hi i've got this code that writes data to a text file. When i test it with a standard array eg array(1,2,3) it works perfectly fine but when i try it with $_POST i get the error message Warning:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.