Announcement

Collapse
No announcement yet.

Javascript to php/mysql

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript to php/mysql

    I have not yet written the code but I have it planned....so unfortunately I can't show you a code yet. This should be a simple question and there should be no need for my end of the code. Now with all that said.......
    Of course this is done though a form. I don't want a sumbit button to submit the form, instead I want javascript to handle the entire form. Now of course, I know how to do this this is not the issue. Once the form is submitted I want javascript to validate the page and alert the user of their errors. Once the user has submitted the form error free I want javascript to somehow use php and mysql to insert date into my database.
    Now, my issue is getting javascript to insert the data into the database.
    Would this javascript code work?
    Code:
    document.write('<?php //My Code ?>')
    No its not Fowbers its foobers :D

  • #2
    Re: Javascript to php/mysql

    No, that would just write the php code to the browser, it won't be executed. The only way for the javascript to add form data to the database would be to use a php file and access it using AJAX. Theres no way to directly execute a query with javascript it requires using some sort of server scripting (javascript is client side scripting)

    EDIT: not to mention javascipt would be an extremely insecure way to interact with a database IF it could execute queries

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment


    • #3
      Re: Javascript to php/mysql

      " EDIT: not to mention javascipt would be an extremely insecure way to interact with a database IF it could execute queries"
      Yea, I've thought about that.
      Using ajax..... I should of known better. Thanks flip. And your sure that is a safe way to send and receive data?
      No its not Fowbers its foobers :D

      Comment


      • #4
        Re: Javascript to php/mysql

        You have to sanitize the i/o like you would if you were to submit a form directly to the php file, but whether you submit to a php file or use AJAX to do it, it is basically the same thing, just going about it differently.

        Register/Login Script
        Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

        Comment


        • #5
          Re: Javascript to php/mysql

          alright thanks much flip I appreciate your help
          No its not Fowbers its foobers :D

          Comment


          • #6
            Re: Javascript to php/mysql

            However, it is extremely hard to understand your motivations. I mean, Ajax can perform realtime submitting to the database, but WHY ?

            You should use Javascript for in page validation (so it is much faster) AND php validation in the script itself. If the submission passes the Javascript validation, the php code finds everything ok and does whatever it has to do, if the Javascript fails for any reason, the php script will validate and report errors if any are found.

            Please also note that using Ajax (which is mostly Javascript) will fail for those visitors that have Javascript disabled. So you will never be able to recieve their submissions.
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment


            • #7
              Re: Javascript to php/mysql

              On small sites there isn't much point as on larger sites, but it will minimize the bandwidth usage as it doesn't require resending all of the unchanged html code as it would if you reload the page. AJAX is a lot of effort in my opinion, its much simpler to submit the form, but if you want to take the time to do things with AJAX its not that much more work to check if the user has javascript enabled or disable, and handle the form submissions accordingly

              Register/Login Script
              Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

              Comment


              • #8
                Re: Javascript to php/mysql

                thnx for all the help guys, i think i know what to do with this information ;)
                No its not Fowbers its foobers :D

                Comment

                Working...
                X