Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 16th, 2014, 09:33 PM
Authorized User
Join Date: Apr 2013
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
Default JS not passing to php?

Hi, I'm baffled here; the two following statements from my JS
file displays the correct values but the code to enter them
into a table enters zeroes. I tried document.write(s) and the
correct values were displayed.what am I missing? Thanks in advance.

var expression = value1 + op +value2 +'='+ total;
PHP Code:
$servername "localhost";
$username "root";table
$dbname "homedb";
// Create connection
$conn = new mysqli($servername$username$password$dbname);
// Check connection
if ($conn->connect_error)
 { die(
"Connection failed: " $conn->connect_error); } 

$sql "INSERT INTO calculator (purpose, value1, op, value2, total)
$purpose', '$value1', '$op', '$value2', '$total')";
if (
$conn->query($sql) === TRUE)
 { echo 
"New record created successfully"; }
 { echo 
"Error: " $sql "<br>" $conn->error; }
Old December 8th, 2014, 11:41 AM
Registered User
Join Date: Dec 2014
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post

You can not use javascript in this way. You need to call Ajax and then you can save the values to variables php
The Following User Says Thank You to jan127 For This Useful Post:
ataloss (December 9th, 2014)
Old December 9th, 2014, 04:55 PM
Authorized User
Join Date: Apr 2013
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts

thanks jan, I surmised that. I'm trying to understand the ajax tutorials.
over 40 yeqrs ago I did well programming in several languages converting
canned IBM systems to site specific systems. Now retired, I'm finding that
simple code that required a dozen statements to add, delete and edit have me
learning HTML, Javascript, java, PHP, Server setup, mysql (now mysqli), ajax, etc..I have yet to encounter a relative example.
I wanted a challenge and I got it! Again, thanks - back to the books.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling PHP, VC, default.js nattsurf123 C++ Programming 0 March 23rd, 2010 12:10 PM
passing empty parameters to a js function crmpicco Javascript How-To 0 September 20th, 2005 10:16 AM
passing js var to asp sql okl Javascript 1 March 11th, 2005 05:40 AM
passing js var to asp sql okl Classic ASP Databases 1 March 11th, 2005 05:01 AM
passing parameter from js to another jsp page. Regornil JSP Basics 1 August 31st, 2004 08:23 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.