Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End can't get form on webpage to post to table/database on remote server Reply To: can't get form on webpage to post to table/database on remote server

#209628
Great Scott
Participant

Here’s InsertCustomer.php
<?php
$dbEntries = $_POST;
foreach ($dbEntries as &$entry)
{
$entry = dbString($entry);
}

@$db = new mysqli('localhost','root','pwdpwd','pet_shop');
if (mysqli_connect_errno())
{
    echo 'Cannot connect to database: ' . mysqli_connect_error();
}
$query = "INSERT INTO grooming
    (FirstName, LastName, Address, City, State, Zip, PhoneNumber, Email, PetType, PetName, NeuteredOrSpayed, PetAge)
    VALUES ('" .    $dbEntries['FirstName'] . "','" .
                    $dbEntries['LastName'] . "','" .
                    $dbEntries['Address'] . "','" .
                    $dbEntries['City'] . "','" .
                    $dbEntries['State'] . "','" .
                    $dbEntries['Zip'] . "','" .
                    $dbEntries['PhoneNumber'] . "','" .
                    $dbEntries['Email'] . "','" .
                    $dbEntries['PetType'] . "-" .
                    $dbEntries['PetName'] . "','" .
                    $dbEntries['NeuteredOrSpayed'] . "-" .
                        $dbEntries['Spayed'] . "-" .
                        $dbEntries['Neutered'] . "-" .
                    $dbEntries['PetAge'] . "')";

if ($db-&gt;query($query))
{
    echo '<div>Customer Added</div>
        <a href="CustomerReport.php">Customer Report</a>';
    $showForm = false;
}
else
{
    echo '<div>Insert failed</div>';
}

?>

Here’s CustomerForm.php

<?php
if (array_key_exists(‘GroomingID’,$_POST))
{
$action = ‘Edit’;
$formFlag = ‘Updating’;
}
else
{
$action = ‘Add’;
$formFlag = ‘Submitted’;
}
?>

<form method=”post” action=”groomingservices2.php”>
<input type=”hidden” name=”<?php echo $formFlag ?>” value=”true”>
<?php
if (array_key_exists(‘GroomingID’,$_POST))
{
echo “<input type=’hidden’ name=’GroomingID’ value=’$groomingID’>”;
}
?>
<table align=”center” border=”1″ width=”500″>
<?php
echo textEntry(‘First name’,’FirstName’,$dbEntries,$errors,15);
echo textEntry(‘Last name’,’LastName’,$dbEntries,$errors,15);
echo textEntry(‘Address’,’Address’,$dbEntries,$errors,50);
echo textEntry(‘City’,’City’,$dbEntries,$errors,30);
echo textEntry(‘State’,’State’,$dbEntries,$errors,5);
echo textEntry(‘Zip’,’Zip’,$dbEntries,$errors,10);
echo textEntry(‘Phone Number’,’PhoneNumber’,$dbEntries,$errors,15);
echo textEntry(‘Email’,’Email’,$dbEntries,$errors,25);
echo selectEntry(‘Pet Type’,’PetType’,$petTypeEntries,$errors,$dbEntries[‘PetType’]);
echo textEntry(‘Pet Name’,’PetName’,$dbEntries,$errors,30);

    echo checkboxEntry('Neutered or Spayed','NeuteredOrSpayed',
        $dbEntries,$errors,
        array('Neutered','Spayed'));
    echo textEntry('Pet Age','PetAge',$dbEntries,$errors,10);
?&gt;
&lt;tr&gt;
    &lt;td colspan="2"&gt;&lt;input type="submit" value="&lt;?php echo $action ?&gt; Customer"&gt;&lt;/td&gt;
&lt;/tr&gt;

</table>
</form>