473,467 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP in Javascript

15 New Member
I used the php code in javascript function.When i click a button the javascript function is called and in that function i wrote the php code for insert values in database.With out submit the button the values are inserted into database.How can i prevent the inserting values without submitting the button?
Here is my script :
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function insfun()
  3. {
  4. <?php
  5. $query=mysql_query("select * from tbl_products");
  6. while($row=mysql_fetch_array($query))
  7. {
  8. $queryins=mysql_query("insert into tbl_rateit(email,uid,action,item) values ('$_SESSION[email]','$_SESSION[uid]','buy','$row[itemid]')");
  9. }
  10. ?>
  11. }
  12. </script>
  13. <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  14. <input type="image" src="../x-click-but01.gif" name="submit" onclick="return insfun();">
  15. </form>
Apr 3 '09 #1
1 1312
Dormilich
8,658 Recognized Expert Moderator Expert
PHP code is executed at the server before the page is sent to the browser, thus your javascript function will be empty (check HTML source code). to run PHP code through JavaScript either submit the form (and let the server do the PHP) and wait for the results or use AJAX.
Apr 3 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.