Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

ARRANGING OUTPUT PHP CODE NEWBIE HERE

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

ARRANGING OUTPUT PHP CODE NEWBIE HERE

Postby drenyl » Thu Mar 14, 2013 6:54 am

I'm new in php, i created 2 textfields " FIRSTNAME" and "LASTNAME". and in php i put
if(empty) in each textfields to display when a textfields is not filled or empty after submitting.
so there it is, i fill up the FIRSTNAME and i didn't put anything in the LASTNAME. and when I submit.
it displays both in my screen. and its messy. how can i make it more organize.

here is the code:

asd.html
Code: Select all
<html>

<form action="log.php" method="post">
First name:
    <input type="text" name="first">
Last name:
    <input type="text" name="last"><br>
   
    <input type="submit value="submit">
   </form>
   
   </html>


qwe.php
Code: Select all
<?php

$firstn=$_POST['first'];
$lastn=$_POST['last'];

if(empty($firstn))
{
$nofirst = "Please Enter your First name!";
}
else
{
$nofirst= " ";
}

if(empty($lastn))
{
$nolast = "Please Enter your LAST name!";
}
else
{
$nolast= " ";
}


echo "your first name is $firstn and last name is $lastn";


echo "<blockquote>
      $nofirst
      $nolast
      </blockquote>

?>



example output.
your first name is alex and last name is (blank because its empty)
Please enter your last name!


can someone help me?. its my first post hope you can help me guys.
I try to use
include statements, but i don't know how to insert it in if else statement.
drenyl
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Mar 14, 2013 6:05 am

Re: ARRANGING OUTPUT PHP CODE NEWBIE HERE

Postby johnj » Thu Mar 14, 2013 7:57 pm

You can use the die() function in php to stop processing if one of the fields is empty.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron