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

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #209570
    Great Scott
    Participant

    created a webpage that must post to a table on a remote server (using mysql via xampp and phpmyadmin); gave the following notice error:

    Undefined index: typeOfPet in C:\xampp\htdocs\pet-shop\includes\CustomerForm.php on line 34

    when I try to submit the form any way, it tells gives the following message:

    Object not found!

    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

    If you think this is a server error, please contact the webmaster.
    Error 404
    localhost
    Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15

    there’s a lot of code here so please let me know what would be a good place to post this. Thanks.

    #209614
    vindicateme
    Participant

    can you just post the code that processes the form?

    #209627
    Great Scott
    Participant

    here’s ProcessCustomer.php

    <?php
    $dbEntries = $_POST;
    foreach ($dbEntries as &$entry)
    {
    $entry = dbString($entry);
    }

    `if (!checkLength($_POST[‘FirstName’]))
    {
    $errors[‘FirstName’] = ‘First name omitted.’;
    }
    else
    {
    $browserEntries[‘FirstName’] = browserString($_POST[‘FirstName’]);
    }

    if (!checkLength($_POST[‘LastName’]))
    {
    $errors[‘LastName’] = ‘Last name omitted.’;
    }
    else
    {
    $browserEntries[‘LastName’] = browserString($_POST[‘LastName’]);
    }

    if (!checkLength($_POST[‘Address’],5,200))
    {
    $errors[‘Address’] = ‘Address omitted.’;
    }
    else
    {
    $browserEntries[‘Address’] = browserString($_POST[‘Address’]);
    }

    if (!checkLength($_POST[‘City’],1,100))
    {
    $errors[‘City’] = ‘City omitted.’;
    }
    else
    {
    $browserEntries[‘City’] = browserString($_POST[‘City’]);
    }

    if (!checkLength($_POST[‘State’],1,100))
    {
    $errors[‘State’] = ‘State omitted.’;
    }
    else
    {
    $browserEntries[‘State’] = browserString($_POST[‘State’]);
    }

    if (!checkLength($_POST[‘Zip’]))
    {
    $errors[‘Zip’] = ‘Zip code omitted.’;
    }
    else
    {
    $browserEntries[‘Zip’] = browserString($_POST[‘Zip’]);
    }

    if (!checkLength($_POST[‘PhoneNumber’],10,15))
    {
    $errors[‘PhoneNumber’] = ‘Home phone must be between 10 and 15 characters.’;
    }
    else
    {
    $browserEntries[‘PhoneNumber’] = browserString($_POST[‘PhoneNumber’]);
    }
    `

    if ( !checkEmail($_POST[‘Email’]) )
    {
    $errors[‘Email’] = ‘Email is invalid.’;
    }
    else
    {
    $browserEntries[‘Email’] = browserString($_POST[‘Email’]);
    }

    `if ($_POST[‘PetType’] == 0)
    {
    $errors[‘PetType’] = ‘PetType not selected.’;
    }
    else
    {
    $browserEntries[‘PetType’] = $_POST[‘PetType’];
    }

    if ($_POST[‘NeuteredOrSpayed’] == “”)
    {
    $errors[‘NeuteredOrSpayed’] = ‘Neutered or Spayed not selected.’;
    }
    else
    {
    $browserEntries[‘NeuteredOrSpayed’] = $_POST[‘NeuteredOrSpayed’];
    }

    if (!checkLength($_POST[‘PetAge’]))
    {
    $errors[‘PetAge’] = ‘Pet Age omitted.’;
    }
    else
    {
    $browserEntries[‘Zip’] = browserString($_POST[‘PetAge’]);
    }
    `

    ?>
    <?php
    if (!count($errors) && array_key_exists(‘ID’,$_POST))
    {
    $employeeID = $_POST[‘GroomingID’];
    $query = “UPDATE grooming
    SET FirstName='” . $dbEntries[‘FirstName’] . “‘,
    LastName='” . $dbEntries[‘LastName’] . “‘,
    Address='” . $dbEntries[‘Address’] . “‘,
    City='” . $dbEntries[‘City’] . “‘,
    Region='” . $dbEntries[‘Region’] . “‘,
    PostalCode='” . $dbEntries[‘PostalCode’] . “‘,
    HomePhone='” . $dbEntries[‘HomePhone’] . “‘,
    Email='” . $dbEntries[‘Email’] . “‘,
    PetType=” . $dbEntries[‘PetType’] . “‘,
    PetName='” . $dbEntries[‘PetName’] . “‘,
    NeuteredOrSpayed='” . $dbEntries[‘NeuteredOrSpayed’] . “‘,
    PetAge='” . $dbEntries[‘PetAge’];

    if ($db-&gt;query($query))
    {
    echo '&lt;div&gt;Record Updated&lt;/div&gt;';
    }
    else
    {
    echo '&lt;div&gt;Update Failed&lt;/div&gt;';
    }
    }
    elseif (!count($errors))
    {
    $showForm = false;

    ?>

    `<form method=”post” action=”../grooming.php”>
    <input type=”hidden” name=”Confirmed” value=”true”>
    <?php
    echo ‘<h2>Confirm Entries</h2>’;
    echo ‘<ol>’;
    foreach ($browserEntries as $key=>$entry)
    {
    if ($key==”PetType”)
    {
    echo “<li><b>Breed:</b> $breedEntries[$entry]</li>”;
    }
    else
    {
    echo “<li><b>$key:</b> $entry</li>”;
    }
    }
    echo ‘</ol>’;

    foreach ($dbEntries as $key=&gt;$entry)
    {
    

    ?>
    <input type=”hidden” name=”<?php echo $key ?>”
    value=”<?php echo $entry ?>”>
    <?php
    }
    ?>
    <input type=”submit” value=”Confirm”>
    </form>
    `

    <?php
    }
    else
    {
    $dbEntries = $_POST;
    }
    ?>

    #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>

    #209629
    Great Scott
    Participant

    Here’s the 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>

    #209630
    Great Scott
    Participant

    the init.php file:

    <?php
    $showForm = true;

    $petTypeEntries = array();
    $petTypeEntries['Cat']='Cat';
    $petTypeEntries['Dog']='Dog';   
    $petTypeEntries['Lab']='Lab';
    $petTypeEntries['Chow']='Chow';
    $petTypeEntries['Terrier']='Terrier';
    $petTypeEntries['Bulldog']='Bulldog';
    $petTypeEntries['Cocker Spaniel']='Cocker Spaniel';
    $petTypeEntries['Great Dane']='Great Dane';
    $petTypeEntries['Alaskan Huskey']='Alaskan Huskey';
    
    $errors = array();
    $dbEntries = array( 'FirstName'=&gt;'',
                        'LastName'=&gt;'',
                        'Address'=&gt;'',
                        'City'=&gt;'',
                        'State'=&gt;'',
                        'Zip'=&gt;'',
                        'PhoneNumber'=&gt;'',
                        'Email'=&gt;'',
                        'PetType'=&gt;'',
                        'Breed'=&gt;'',
                        'PetName'=&gt;'',
                        'NeuteredOrSpayed'=&gt;'',
                        'PetAge'=&gt;'');   
    $browserEntries = array();
    

    ?>

    #209631
    Great Scott
    Participant

    And the fnFormPresentation.php file:

    <?php
    /********* FORM PRESENTATION FUNCTIONS *********/

    /*
    Function Name: textEntry
    Arguments: $display,$name,$entries,$errors,$size?
    Returns:
    one table row as string
    */
    function textEntry($display,$name,$entries,$errors,$size=15)
    {
    $returnVal = ”
    <tr>
    <td>$display:</td>
    <td>
    <input type=’text’ name=’$name’ size=’$size’
    value='” . browserString($entries[$name]) . “‘>”;

    if (array_key_exists($name,$errors))
    {
        $returnVal .= '<span>* ' .
                $errors[$name] .
            '</span>';
    }
    
    $returnVal .= '&lt;/td&gt;&lt;/tr&gt;';
    
    return $returnVal;
    

    }

    /*
    Function Name: pwEntry
    Arguments: $pw1,$pw2,$errors,$size?
    Returns:
    table rows as string
    */
    function pwEntry($pw1,$pw2,$errors,$size=10)
    {
    $returnVal = ”
    <tr>
    <td>Password:</td>
    <td>
    <input type=’password’ name=’$pw1′ size=’$size’>
    </td>
    </tr>
    <tr>
    <td>Repeat Password:</td>
    <td>
    <input type=’password’ name=’$pw2′ size=’$size’>
    </td>
    </tr>”;

    if (array_key_exists('Password',$errors))
    {
        $returnVal .= addErrorRow('Password',$errors);
    }
    return $returnVal;
    

    }

    /*
    Function Name: textAreaEntry
    Arguments: $display,$name,$entries,$errors,$cols?,$rows?
    Returns:
    table rows as string
    */
    function textAreaEntry($display,$name,$entries,$errors,$cols=45,$rows=5)
    {
    $returnVal = ”
    <tr>
    <td colspan=’2′>$display:</td>
    </tr>
    <tr>
    <td colspan=’2′>
    <textarea name=’$name’ cols=’$cols’ rows=’$rows’>”;
    $returnVal .= $entries[$name];
    $returnVal .= “</textarea>
    </td>
    </tr>”;

    if (array_key_exists($name,$errors))
    {
        $returnVal .= addErrorRow($name,$errors);
    }
    return $returnVal;
    

    }

    /*
    Function Name: radioEntry
    Arguments: $display,$name,$entries,$errors,$values
    Returns:
    table rows as string
    */
    function checkboxEntry($display,$name,$entries,$errors,$values)
    {
    $returnVal = ”
    <tr>
    <td>$display:</td>
    <td>”;
    foreach ($values as $value)
    {
    if (array_key_exists($name,$entries) &&
    $entries[$name]==$value)
    {
    $returnVal .= “<input type=’checkbox’ name=’$name’
    value=’$value’ checked> $value “;
    }
    else
    {
    $returnVal .= “<input type=’checkbox’ name=’$name’
    value=’$value’> $value “;
    }
    }
    $returnVal .= “</td>
    </tr>”;

    if (array_key_exists($name,$errors))
    {
        $returnVal .= addErrorRow($name,$errors);
    }
    return $returnVal;
    

    }

    /*
    Function Name: selectEntry
    Arguments: $display,$name,$entries,$errors,$selected?
    Returns:
    table rows as string
    */
    function selectEntry($display,$name,$options,$errors,$selected=0)
    {
    $returnVal = “<tr>
    <td>$display:</td>
    <td>
    <select name=’$name’>
    <option value=’0′>Choose one…</option>”;
    foreach ($options as $key=>$option)
    {
    if ($key == $selected)
    {
    $returnVal .= “<option value=’$key’ selected>
    $option</option>”;
    }
    else
    {
    $returnVal .= “<option value=’$key’>
    $option</option>”;
    }
    }
    $returnVal .= “</select>
    </td>
    </tr>”;

        if (array_key_exists($name,$errors))
        {
            $returnVal .= addErrorRow($name,$errors);
        }
    return $returnVal;
    

    }

    /*
    Function Name: selectDateEntry
    Arguments: $display,$namePre,$month,$day,$year
    Returns:
    table rows as string
    */
    function selectDateEntry($display,$namePre,$month,$day,$year,$errors)
    {
    $returnVal = “<tr>
    <td>$display:</td>
    <td>
    <select name=’$namePre” . “Month’>”;
    for ($i=1; $i<=12; $i++)
    {
    if ($i == $month)
    {
    $returnVal .= “<option value=’$i’ selected>”;
    }
    else
    {
    $returnVal .= “<option value=’$i’>”;
    }
    $returnVal .= monthAsString($i) . “</option>”;
    }
    $returnVal .= “</select>
    <select name=’$namePre” . “Day’>”;
    for ($i=1; $i<=31; $i++)
    {
    if ($i == $day)
    {
    $returnVal .= “<option value=’$i’ selected>”;
    }
    else
    {
    $returnVal .= “<option value=’$i’>$i</option>”;
    }
    $returnVal .= “$i</option>”;
    }
    $returnVal .= “</select>
    <select name=’$namePre” . “Year’>”;
    for ($i=date(‘Y’); $i>=1900; $i=$i-1)
    {
    if ($i == $year)
    {
    $returnVal .= “<option value=’$i’ selected>”;
    }
    else
    {
    $returnVal .= “<option value=’$i’>$i</option>”;
    }
    $returnVal .= “$i</option>”;
    }
    $returnVal .= “</select>
    </td>
    </tr>”;

    if (array_key_exists($namePre . 'Date',$errors))
    {
        $returnVal .= addErrorRow($namePre . 'Date',$errors);
    }
    return $returnVal;
    

    }

    /*
    Function Name: addErrorRow
    Arguments: $name
    Returns:
    table row as string
    /
    function addErrorRow($name,$errors)
    {
    $errorRow = “<tr>
    <td colspan=’2′ class=’Error’>
    ” .
    $errors[$name] .
    “</td>
    </tr>”;
    return $errorRow;
    }
    ?>

    #209632
    Great Scott
    Participant

    and finally, the fnStrings.php file:

    <?php
    /********** STRING FUNCTIONS *********/
    /*
    Function Name: browserString
    Arguments: $string
    Returns:
    trimmed and escaped string for browser output
    */
    function browserString($string)
    {
    return nl2br(trim(htmlentities($string)));
    }

    /*
    Function Name: dbString
    Arguments: $string
    Returns:
    trimmed and escaped string for database entry
    */
    function dbString($string)
    {
    $string=trim($string);
    if (get_magic_quotes_gpc())
    {
    return $string;
    }
    else
    {
    return addslashes($string);
    }
    }
    ?>

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Back End’ is closed to new topics and replies.