PHP form not updating database

A multipurpose module, plugin and component

PHP form not updating database

New postby [email protected] » Wed Sep 07, 2011 5:06 pm

Hi
a PHP file for a form (one PHP file including the HTML) is working when I place it in a server (without Joomla) as a single file
but when I place it (in a server with Joomla 1.5) in JUMI article "{jumi [xxx.php]}" it's only showing the form but not updating the database
see below my code
Code: Select all
<?php
   if($_POST['formSubmit'] == "Submit")
    {
      $errorMessage = "";
      
      if(empty($_POST['formFirst']))
        {
         $errorMessage .= "<li>You forgot to enter your first name!</li>";
      }
      if(empty($_POST['formLast']))
        {
         $errorMessage .= "<li>You forgot to enter your last name!</li>";
      }
      if(empty($_POST['formAge']))
        {
         $errorMessage .= "<li>You forgot to enter your age!</li>";
      }

        $varFirst = $_POST['formFirst'];
      $varLast = $_POST['formLast'];
      $varAge = $_POST['formAge'];

      if(empty($errorMessage))
        {
         $db = mysql_connect("localhost","usr","password");
         if(!$db) die("Error connecting to MySQL database.");
         mysql_select_db("database" ,$db);

         $sql = "INSERT INTO Persons (Firstname, LastName, Age) VALUES (".
                     PrepSQL($varFirst) . ", " .
                     PrepSQL($varLast) . ", " .
                     PrepSQL($varAge) . ")";
         mysql_query($sql);
         
         header("Location: components/com_jumi/files/thankyou.html");
         exit();
      }
   }
           
    // function: PrepSQL()
    // use stripslashes and mysql_real_escape_string PHP functions
    // to sanitize a string for use in an SQL query
    //
    // also puts single quotes around the string
    //
    function PrepSQL($value)
    {
        // Stripslashes
        if(get_magic_quotes_gpc())
        {
            $value = stripslashes($value);
        }

        // Quote
        $value = "'" . mysql_real_escape_string($value) . "'";

        return($value);
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>PHP Form processing example</title>
<!-- define some style elements-->
<style>
label,a
{
   font-family : Arial, Helvetica, sans-serif;
   font-size : 12px;
}

</style>   
</head>

<body>

       <?php
          if(!empty($errorMessage))
          {
             echo("<p>There was an error with your form:</p>\n");
             echo("<ul>" . $errorMessage . "</ul>\n");
            }
        ?>

      <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
         <p>
            <label for='formFirst'>What is your First Name?</label><br/>
            <input type="text" name="formFirst" maxlength="50" value="<?=$varFirst;?>" />
         </p>
         <p>
            <label for='formLast'>What is your last name?</label><br/>
            <input type="text" name="formLast" maxlength="50" value="<?=$varLast;?>" />
         </p>
         <p>
            <label for='formAge'>What is your Age?</label><br/>
            <input type="text" name="formAge" maxlength="50" value="<?=$varAge;?>" />
         </p>
         <input type="submit" name="formSubmit" value="Submit" />
      </form>
      
<p>
<a href='http://www.html-form-guide.com/php-form/php-form-processing.html'
>'PHP form processing' article page</a>
</p>

</body>
</html>


Arie
[email protected]
 
Posts: 1
Joined: Thu Aug 11, 2011 12:11 am

Return to Jumi

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron