4 Replies - 326 Views - Last Post: 06 February 2013 - 04:16 AM Rate Topic: -----

#1 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

How to print the a statement using $_POST using the if statement

Posted 05 February 2013 - 02:14 AM

The instruction is like this:

There is a form, a text field in which the user will input his/her name.
if the name is input and the submit button is press then the value is pass to another document but when the user just clicks the submit button without filling up the text field with the name then it should say Error!

Example:
<td>Your name: </td>
<td><?php echo $_POST['FirstName'] ?></td>

that only processes to print the value of the user input but the instruction said that to print error if the user doesnt input something and has click the submit button..
i already used an if else statement but still it wont print the error!!

Any help will be appreciated..thank you.. :)
I am a beginner in php so hope you all consider my situation...

Is This A Good Question/Topic? 0
  • +

Replies To: How to print the a statement using $_POST using the if statement

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: How to print the a statement using $_POST using the if statement

Posted 05 February 2013 - 02:16 AM

It would be really helpful if you could post your entire code here so that we may be in a better position to help you out.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#3 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

Re: How to print the a statement using $_POST using the if statement

Posted 05 February 2013 - 03:59 AM

try this one
<?php
if($_POST['username'] == "")
{
?>
		<script type="text/javascript">
		alert("ERROR.");
		</script>
<?php
}
else 
{
echo $_POST['username'];
}
?>


Was This Post Helpful? 1
  • +
  • -

#4 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to print the a statement using $_POST using the if statement

Posted 05 February 2013 - 08:21 PM

View Postraghav.naganathan, on 05 February 2013 - 02:16 AM, said:

It would be really helpful if you could post your entire code here so that we may be in a better position to help you out.

regards,
Raghav


Im afraid that wont do because this is an assignment in school and i am afraid that my classmate will discover it in online and copy it... our instructor told us that she will deduct points to those who copy files.. hope you understand it..
i am a student and a beginner in it... :(

View PostKirstine, on 05 February 2013 - 03:59 AM, said:

try this one
<?php
if($_POST['username'] == "")
{
?>
		<script type="text/javascript">
		alert("ERROR.");
		</script>
<?php
}
else 
{
echo $_POST['username'];
}
?>




wow thank you that is a great idea but i am afraid that wont do since we havent discussed about javascript yet... however i appreciate your help.. thank you :)

you really do stop by and help me out of it.. i really appreciate it.. thank you so much!!
hope i will be like you someday.. :)
Was This Post Helpful? 0
  • +
  • -

#5 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

Re: How to print the a statement using $_POST using the if statement

Posted 06 February 2013 - 04:16 AM

try this one
<?php
if($_POST['username'] == "")
{
echo "Your Error Message Here";
}
else 
{
echo $_POST['username'];
}
?>



This one doesn't involve javascript.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1