开发者

PHP form not submitting until all the info entered

I am submitting an HTML form using php and I have these fields in my form:

  • Name:(varchar)
  • Address:(varchar)
  • FAX:(int)
  • PHONE:(int)
  • EMAIL:(varchar)
  • plus a primary ID that gets added on its own.

Now my form doesn't get submitted until I enter the fax field? Does anyone know why is it happening?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "h开发者_开发问答ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<body>

<?php

require_once('../../public_html/input.php');

require_once('../../public_html/nauth.php');

require_once('../../public_html/mysql.php');



if (isset($_GET['more']))

{ 

    $more = $_GET['more'];

    $new = 8;

}

if (isset($_POST['submit']))

{

    $more = 4;

    $new = 8;

    $name = $_SESSION['username'];

    $dbc = mysqli_connect(cname, chost, cpwd, cdb);

    $com_name = mysqli_real_escape_string($dbc, trim($_POST['com_name']));

    $com_address = mysqli_real_escape_string($dbc, trim($_POST['com_address']));

    $com_phone = mysqli_real_escape_string($dbc, trim($_POST['com_phone']));

    $com_fax = mysqli_real_escape_string($dbc, trim($_POST['com_fax']));

    $source_id = $_POST['source'];



    $com_email = mysqli_real_escape_string($dbc, trim($_POST['com_email']));

    $entered_by = $name;

    $query = "select * from company_customers where name='$com_name'";

    $data = mysqli_query($dbc, $query);



    if (mysqli_num_rows($data) == 0) //to check if the name already exists

    {

        $query="insert into  company_customers(name,address,phone,fax,email,entered_by,source_id) values('$com_name','$com_address','$com_phone','$com_fax','$com_email','$entered_by','$source_id')";

        mysqli_query($dbc, $query);

        $query = "select * from company_customers where name='$com_name'";

        $data = mysqli_query($dbc, $query);

        $row = mysqli_fetch_array($data);

        $id = $row['id']; //to add the company id in the contacts table

        $i = 0;

        while (!empty($_POST['name' . $i]))

        {   

            $name = $_POST['name' . $i];

            $designation = $_POST['desig' . $i];

            $phone = $_POST['phone' . $i];

            $query = "insert into contacts(name,designation,id,phone) values('$name','$designation','$id','$phone')";

            mysqli_query($dbc, $query);

            $i++;

        }

        mysqli_close($dbc);

        echo 'Added';

        require_once('option.php');

        exit();

    }

    else echo 'company already entered';

}

else if (isset($_POST['more']))

{

    $more = $_POST['count'];

    $new = $more + 4;

}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

<fieldset><legend>Company Profile</legend>

<label for="com_name">Company Name:</label><input type="text" name="com_name" value="<?php if(isset($_POST['more'])) echo $_POST['com_name']; ?>"/><br />

<label for="com_address">Company Address:</label><input type="text" name="com_address"     value="<?php if(isset($_POST['more'])) echo $_POST['com_address']; ?>" /><br />

<label for="com_phone">Company Phone:</label><input type="text" name="com_phone" value="<?php if(isset($_POST['more'])) echo $_POST['com_phone']; ?>" /><br />

<label for="com_fax">Company Fax:</label><input type="text" name="com_fax" value="<?php if(isset($_POST['more'])) echo $_POST['com_fax']; ?>" /><br />

<label for="com_email">Company Email:</label><input type="text" name="com_email" value="<?php if(isset($_POST['more'])) echo $_POST['email']; ?>" /><br />

<?php

$dbc = mysqli_connect(cname, chost, cpwd, cdb);

$query = "select * from source";

$data = mysqli_query($dbc, $query);

$number_row = mysqli_num_rows($data);

$source[0] = '';

$source_id[0] = ''; 

$i = 1;

while ($row = mysqli_fetch_array($data))

{ 

    $source[$i] = $row['src'];

    $source_id[$i] = $row['source_id'];

    $i++;

}

echo '<label for="source">Source</label><select name="source">';

for ($i = 0; $i <= $number_row; $i++)

    echo '<option value="' . $source_id[$i] . '">' . $source[$i] . '</option>';

echo '</select>';

?>

</fieldset>

<fieldset><legend>Company Contact</legend>

<?php

for ($i = 0; $i < $more; $i++)

{ 

?>

<label for="<?php echo 'name' . $i; ?>">Name:</label><input type="text" name="<?php echo  'name' . $i; ?>" value="<?php if (isset($_POST['more'])) echo $_POST['name' . $i]; ?>" />

<label for="<?php echo 'desig' . $i; ?>">Designation:</label><input type="text" name="<?php echo 'desig' . $i; ?>" value="<?php if (isset($_POST['more'])) echo   $_POST['desig' . $i];?>" />

<label for="<?php echo 'phone' . $i;?>">Phone:</label><input type="text" name="<?php  echo 'phone' . $i;?>" value="<?php if (isset($_POST['more'])) echo $_POST['phone' . $i]; ?>" /><br />

<?php

}

?>

<input type="hidden" name="count" value="<?php echo $new; ?>" />

<input type="submit" name="more" value="more" />

</fieldset>

<input type="submit" name="submit" value="ADD" />

</form>

</body>

</html>


Try setting the column to allow null values in mysql. E.g.

ALTER TABLE company_customers CHANGE fax fax INT(11) NULL
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜