We help IT Professionals succeed at work.
Get Started

AJAX submit

runnerjp
runnerjp asked
on
706 Views
Last Modified: 2013-12-12
at the moment im using  AJAX tabs , but im using classic nonAJAX form actions. i have been told that for my script to work properly so that forms an be processed under each tab that i need to have it  completely AJAX.  so how can i chnage the code below so that it carries out the submittion to the db via ajax
<?php error_reporting(E_ALL);
session_start();
require_once '../../../settings.php';
include "../../../info.php"; // sets username/id ect
 
$getuser = mysql_fetch_assoc(mysql_query("SELECT * from users where Username='$username'"));
$getuserprofile = mysql_fetch_assoc(mysql_query("SELECT * from profile where ID='" .
				$getuser['ID'] . "'"));
 
?>
 
<html>
<head>
    <title></title>
   </head>
 
<body>
  <?  
       if(isset($_POST['submitted']))
{
 
 
	   
	  foreach($_POST as $field => $value) {
   if (($field != 'submit') && ((!$value) || (trim($value) == ''))) {
      $err .= "$field cannot be empty. <br>";
      $warnings[$field] ="required";
   }
}   
 
if (!$_POST["about_me"] || !preg_match("/^[a-zA-Z ]+$/", $_POST["about_me"])) {
   $warnings["about_me"] = " <label for=\"uname\" class=\"error\"><em>*</em>please only user words</label>";
   }
 
 
           $count  = count($warnings);
           }
if($count === 0)
{
   
if(array_key_exists('submit', $_POST))
{
 
 
 
$about_me = mysql_real_escape_string($_POST['about_me']);
$update = "UPDATE profile SET  about_me = '$about_me' WHERE ID='$id' ";
echo $update;
 
$result = mysql_query($update);
 
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $er  = 'Invalid query: ' . mysql_error() . "\n";
    $er .= 'Whole query: ' . $query;
    die($er);
       }}
  echo '			<p class="error">' . $message . '</p>' . "\n";
}
 
 
 
            if ($err){?>
      <div class="errors">
		<p align="center"><em>Oops... the following errors were encountered:</em></p>
 
		<div align="center"><?php echo $err; ?>	      </div>
		<p align="center">&nbsp;</p>
		<p align="center">Data has <strong>not</strong> been saved.</p>
      </div>
      <p>
       <?php } ?>
    <fieldset>
        <legend>About me</legend> 
 
        <div class="c1">
          <p>&nbsp;</p>
 
                <form  action='members/include/profiletab/hobbies.php' method="post" name="submit">
              <p><em><strong>Tell everybody a little bit about yourself...</strong></em></p>
              <p>
                <textarea <? if (count($warnings) > 0){ if ($warnings['about_me']) echo "class=\"inputerror\""; }?> onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')" name="about_me" rows="7" wrap="physical" cols="60">
<?php echo $getuserprofile['about_me']; ?><?php if (count($warnings) > 0){ echo $warnings["about_me"];} ?>
              </textarea>
                <br />
                <br />
                You have <b><span id="myCounter">1000</span></b> characters remaining</p>
                <input type="hidden" name="submitted" value="1" />
              <input name="submit"  type="submit"  value="Submit" />
 
                      </form>
    </div>
    </fieldset>
</body>
</html>

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 39 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE