Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6666649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:51:02+00:00 2026-05-26T02:51:02+00:00

add.php – html markup. dbadd.php – serverside script, addpg.js – clientside including AJAX RSV

  • 0

add.php – html markup.

dbadd.php – serverside script,

addpg.js – clientside including AJAX

RSV– form validator

I’m trying to do following: First validate the form (with RSV), if all things right, Then ajax submit (That’s why i’m using myOnComplete). Inform user about submission. If user pressed for the first time save button then insert into db. Else update db.

The problems are:

  1. It inserts data into db table but doesn’t inform about succes or error
  2. I can’t figure out how to insert data into db If user pressed for
    the first time save button or update data.

Tried all possible ways. There is no error. Please anyone help me to fix that.

addpg.js

 function myOnComplete() {
    return true;
}


$(document).ready(function () {

    $("#add_form").RSV({
        onCompleteHandler: myOnComplete,
        rules: [
            "required,name,Name field required.",
            "required,title,Title field required.",
            "required,menu, Menu field required",
            "required,parentcheck,Parentcheck required",
            "if:parentcheck=1,required,parent,Parent required",
            "required,content,Page content field required"
            ]
    });

});


$("#submit_btn").click(function () {
    CKEDITOR.instances.content.updateElement();
    $("#add_form").submit(function (e) {
        e.preventDefault();
        dataString = $("#add_form").serialize();
        $.ajax({
            type: "POST",
            url: "processor/dbadd.php",
            data: dataString,
            dataType: "json",
            success: function (result, status, xResponse) {
                //do something if ajax call is success
                var message = xResponse.getResponseHeader("msg");
                var err = xResponse.getResponseHeader("err");
                if (message != null) {
                    //do what you like with the message
                }
                if (err != null) {
                    //do what you like with the erro
                }
            },
            error: function (e) {
                //ajax call failed
                alert(e);
            }
        });
    });
});

dbadd.php

<?php
require '../../core/includes/common.php';

$name=filter($_POST['name'], $db);
$title=filter($_POST['title'], $db);
$parentcheck=filter($_POST['parentcheck'],$db);
if(isset ($_POST['parent'])) $parent=filter($_POST['parent'],$db);
else $parent=$parentcheck;  
$menu=filter($_POST['menu'], $db);
$content = $db->escape_string($_POST['content']);

$result=$db->query("INSERT INTO menu (parent, name, showinmenu) VALUES ('$parent', '$name', '$menu')") or die($db->error);
$new_id = $db->insert_id;
$result2=$db->query("INSERT INTO pages (id, title, content) VALUES ('$new_id', '$title', '$content')") or die($db->error);  

if ($new_id>0){  
echo "{";  
echo '"msg": "All right" ';
echo "}";  
}else{ 
echo "{"; 
echo
'"err": "error"';  
echo "}";  
}

?>  

add.php

<div id="add">
<form id="add_form" method="" action=""> 
<input type="text" name="name" id="name" size="40"  value="" class="text-input" />  
<input type="text" name="title" id="title" size="40"  value="" class="text-input" />  
<select name="menu" id="menu">
<option value="" selected="selected">sample</option>
<option value="1">sample 1</option>
<option value="2">sample 2</option>
<option value="0">sample 3</option>
</select>
<input type="radio" class="parentcheck" name="parentcheck" value="0"/>
<input type="radio" class="parentcheck" name="parentcheck" value="1"/>
<select name="parent" id="parent"></select>

<textarea id="content" style="width:100%" name="content"></textarea>
<input type="submit" name="submit" class="button" id="submit_btn" value="Save" />
</form>
</div>
<script type="text/javascript" src="../../core/includes/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="../../core/scripts/admin/addpg.js"></script>
<script type="text/javascript" src="../../core/scripts/admin/rsv.js"></script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:51:03+00:00Added an answer on May 26, 2026 at 2:51 am

    For the first problem:

    Without actually running the code or seeing a live example, I can’t say for sure, but it looks like you have the right idea and it’s just a syntax/usage error. For example:

    var message = xResponse.getResponseHeader("msg");
    var err = xResponse.getResponseHeader("err");
    

    Someone please scold me if I’m wrong, but aren’t “msg” and “err” found in the JSON (result) rather than in xResponse? result.msg (or result[“msg”]) and result.err (or result[“err”])

    If so, also be aware that I -believe- you will get an ‘undefined’ error when trying to declare both of those variables since only one of them will be present. You might want to wrap them in try/catch blocks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a PHP script to add items to a shopping basket. My
is there a way to add a php script (file) in cron for running
I have simple form: <form action=add.php method=post > <input name=name maxlength=30/><br/> <textarea cols=80 name=description
Is it possible to add php to a jquery function? On ajax success I'm
When I try using include to add php code to a sendmail script called
I am very new to PHP; ADD.PHP - I have a form that collects
I am running this function below: $('.cancelbutton').click( function() { $('#gform2').attr('action','/ajax/add.php'); $('input[name=aid]').val('0'); $('.cancelbutton').hide(); var reset_formdate
If i have input text in form like this <form action=add.php method=post> <input type=text
I am trying to do multiple product add with a form using php and
Currently, my .htaccess file looks like htis: IndexIgnore */* RewriteEngine on RewriteRule ^add /add.php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.