Topic: empty content?

hi! I am studying php and I found this site very helpful. I copied the codes and tried to do it on my own, changing the data and variables. It was properly working but the only problem that i have is when i added a new record, a new line will be added while having an empty content.

i checked the codes you've provided but its totally the same. what may be the problem?
thanks for the help

here's the code.

<?php
    function renderForm($bno, $street, $area, $city, $postcode, $telno, $faxno, $error)
    {
        ?>
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
        <html>
        <head>
            <title>New BRANCH Record</title>
        </head>
        <body>
            <?php
                // if there are any errors, display them
                if ($error != '')
                {
                    echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
                }
            ?>               
       
            <form action="" method="post">
            <div>
                <strong>Branch No.: *</strong> <input type="text" name="firstname" value="<?php echo $bno; ?>" /><br/>
                <strong>Street: *</strong> <input type="text" name="lastname" value="<?php echo $street; ?>" /><br/>
                <strong>Area: *</strong> <input type="text" name="firstname" value="<?php echo $area; ?>" /><br/>
                <strong>City: *</strong> <input type="text" name="lastname" value="<?php echo $city; ?>" /><br/>
                <strong>Post Code: *</strong> <input type="text" name="firstname" value="<?php echo $postcode; ?>" /><br/>
                <strong>Tel. No.: *</strong> <input type="text" name="lastname" value="<?php echo $telno; ?>" /><br/>
                <strong>Fax No.: *</strong> <input type="text" name="firstname" value="<?php echo $faxno; ?>" /><br/>               
                <p>* required</p>
                <input type="submit" name="submit" value="Submit">
            </div>
            </form>   
        </body>
        </html>
        <?php   
    }
 
    include('connect-db.php');
   
    if (isset($_POST['submit']))
    {   
        $bno = mysql_real_escape_string(htmlspecialchars($_POST['bno']));
        $street = mysql_real_escape_string($_POST[$street]);
        $area = mysql_real_escape_string(htmlspecialchars($_POST['area']));
    $city = mysql_real_escape_string(htmlspecialchars($_POST['city']));
        $postcode = mysql_real_escape_string(htmlspecialchars($_POST['postcode']));
    $telno = mysql_real_escape_string(htmlspecialchars($_POST['telno']));
        $faxno = mysql_real_escape_string(htmlspecialchars($_POST['faxno']));
       
        if ($bno = '' || $street = '' || $area = '' || $city = '' || $postcode = '' || $telno = '' || $faxno = '')
        {
            $error = 'ERROR: Please fill in all required fields!';
            renderForm($bno, $street, $area, $city, $postcode, $telno, $faxno, $error);
        }
        else
        {
            mysql_query("INSERT branch SET bno='$bno', street='$street', area='$area', city='$city', postcode='$postcode', telno='$telno', faxno='$faxno'")
                or die(mysql_error());

            header("Location: branch.php");       
        }
    }
    else
    {
        renderForm('','','','','','','','');
    }
?>

Vote up Vote down

Re: empty content?

<DIV align="ceneter"> not working.

Can anyone tell what's the problem?

--Scott

Vote up Vote down

Re: empty content?

24hourapartments wrote:

<DIV align="ceneter"> not working.

Can anyone tell what's the problem?

--Scott

Hello,

Try this one:
<div align="center">Your text will show here</div>

Quyen,

Vote up Vote down

Re: empty content?

Hello Taksi10,

I think the problem comes from the form. Check your function renderForm() again, and also give the input fields different names.

I hope that will help!
Quyen,

Last edited by quyen (February 4, 2010 8:19 am)

Vote up Vote down

Re: empty content?

quyen wrote:

Hello Taksi10,

I think the problem comes from the form. Check your function renderForm() again, and also give the input fields different names.

I hope that will help!
Quyen,


thanks miss quyen smile

i changed already the name of the fields. but the output is just the same.
does my function renderForm() code correct?

Vote up Vote down

Re: empty content?

Hi again,

Could you please send me the php file, and I will try to edit it for you. Or you can try this:

$bno = mysql_real_escape_string(htmlspecialchars($_POST['branch_id']));
$street = mysql_real_escape_string($_POST['street']);
$area = mysql_real_escape_string(htmlspecialchars($_POST['area']));
$city = mysql_real_escape_string(htmlspecialchars($_POST['city']));
$postcode = mysql_real_escape_string(htmlspecialchars($_POST['postcode']));
$telno = mysql_real_escape_string(htmlspecialchars($_POST['tel']));
$faxno = mysql_real_escape_string(htmlspecialchars($_POST['fax']));

Note:
branch_id, street,  area, city, postcode, tel, fax have to be exacly the same with form_component_name (I am not sure what do they look like now after you edit).
In the code above, for example your input text is :
        <input type='text' name='branch_id' value='anything' />
        <input type='text' name='street' value='anything' />
        <input type='text' name='area' value='anything' />
        ....do the same to other components.
Or you can try to read this page, very basic and simple, also easy to understand : http://w3schools.com/php/php_post.asp

Goodluck!

Quyen,

Last edited by quyen (February 4, 2010 11:27 pm)

Vote up Vote down

Re: empty content?

quyen wrote:

Hi again,

Could you please send me the php file, and I will try to edit it for you. Or you can try this:

$bno = mysql_real_escape_string(htmlspecialchars($_POST['branch_id']));
$street = mysql_real_escape_string($_POST['street']);
$area = mysql_real_escape_string(htmlspecialchars($_POST['area']));
$city = mysql_real_escape_string(htmlspecialchars($_POST['city']));
$postcode = mysql_real_escape_string(htmlspecialchars($_POST['postcode']));
$telno = mysql_real_escape_string(htmlspecialchars($_POST['tel']));
$faxno = mysql_real_escape_string(htmlspecialchars($_POST['fax']));

Note:
branch_id, street,  area, city, postcode, tel, fax have to be exacly the same with form_component_name (I am not sure what do they look like now after you edit).
In the code above, for example your input text is :
        <input type='text' name='branch_id' value='anything' />
        <input type='text' name='street' value='anything' />
        <input type='text' name='area' value='anything' />
        ....do the same to other components.
Or you can try to read this page, very basic and simple, also easy to understand : http://w3schools.com/php/php_post.asp

Goodluck!

Quyen,

hi again ms. quyen smile
thanks very much for making me realize that the names of the fields are all the same. i changed it, and tried to make a new page. and now its working already! thanks so much.

its really true that sometimes with your excitement to do the program you forgot the small important things smile
thanks for the help again.

Vote up Vote down

Re: empty content?

You are welcome!

Vote up Vote down