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

  • SEARCH
  • Home
  • 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 9071689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:58:28+00:00 2026-06-16T17:58:28+00:00

i have this code which ask user to input value and submit. html <form

  • 0

i have this code which ask user to input value and submit.

html

 <form id="myForm" method="post" action="saving.php">
            <p><label for="input1">Input 1:</label>
                <input type="text" size="10" name="input1" id="input1" />
            </p>
            <input id="save" name="save" type="submit" value="save" />
    </form>
    <p><span id="thevalue"></span><span id="existornot"></span></p> 

js

$("#myForm").submit(function(event) {    
    event.preventDefault();      
    $("#myForm").validate(
      {     rules: {input1: "required",},
            messages: {input1: "message error input"},
            });
    if( $("#myForm").valid()){ 
        var $form = $("#myForm" ),
        url = $form.attr( "action" ), 
        insertedVal=$("#input1").val(); 

        $.post(url,{input1:insertedVal},  
          function(){

          //displaying value condition
          $("#thevalue").html(insertedVal);
          // ... msg from php to be inserted to #existornot 

          });  
       }
}); 

saving.php

<?php
  if(!empty($_POST['input1']))
  {
    $inputone= mysql_real_escape_string(trim($_POST['input1']));
    $result = mysql_query("SELECT COUNT(*) FROM `test_table` WHERE `name` = '$inputone' ");
      if (mysql_result($result, 0, 0) > 0) 
      {
        echo "is duplicate data" ;
      } 
      else 
      {      
        mysql_query("INSERT INTO `test_table`(name)  VALUES ('$inputone')") ;
         echo "is updated to db" ;
      }
  }
  else
  {
    echo "could not be empty"  ;
  }

?>

How to pass those message of ‘is duplicate data’ or ‘ is updated to db’ from the php to the javasript, to tell user that the submit process is fail or success ?

Thanks in advance for any advice.

  • 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-06-16T17:58:29+00:00Added an answer on June 16, 2026 at 5:58 pm

    Change the function call after the jQuery post to accept the data variable and process the results:

        $.post(url,{input1:insertedVal},  
          function(data){
    
          //displaying value condition
          $("#thevalue").html(insertedVal);
          // ... msg from php to be inserted to #existornot 
    
          if (data != 'is updated to db') {
              alert(data);
          }
    
          });  
       }
    

    (Data will contain what has been echoed in your save function)

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

Sidebar

Related Questions

I have this code which can display drop down in div tag of html.
I have a form in which I ask the user how many file inputs
I have the following code which I'm using to get the user to input
I have a page where I ask the user to input a value into
I have this code which adds a x number of views to a Multiview
I have this code which does the trick: #include <stdio.h> int main() { int
I have this code which is called at an onChange event of an function
I have this code which gets WP posts, but it gets all the posts
I have this code (which is way simplified from the real code): public interface
I have this code which compiles and works as expected: class Right {}; class

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.