Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 04-01-2008, 03:23 AM
Phoubers's Avatar
Sergeant
 
Join Date: Oct 2007
Location: :D
Posts: 34
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 04-01-2008, 03:33 AM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 04-01-2008, 03:39 AM
Phoubers's Avatar
Sergeant
 
Join Date: Oct 2007
Location: :D
Posts: 34
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 04-01-2008, 03:44 AM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 04-01-2008, 03:47 AM
Phoubers's Avatar
Sergeant
 
Join Date: Oct 2007
Location: :D
Posts: 34
Default Re: Javascript to php/mysql

alright thanks much flip I appreciate your help
__________________
No its not Fowbers its foobers :D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 04-01-2008, 09:02 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,125
Default 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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 04-01-2008, 03:43 PM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 04-11-2008, 04:10 AM
Phoubers's Avatar
Sergeant
 
Join Date: Oct 2007
Location: :D
Posts: 34
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 10:25 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2007 VodaHost.com - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55