www.webdeveloper.com
Results 1 to 9 of 9

Thread: Javascript and databases

  1. #1
    Join Date
    Oct 2011
    Location
    Durban
    Posts
    12

    Javascript and databases

    I have the following code to try and enter values into a database. The problem is I cant seem to find code for javascript itself to do this so am using the $.post to call myDb.php that has the coding therefor. This don't seem to work so need URGENT help please.
    I either need a direct JAVASCRIPT way to do this or (and I know this is not PHP forum but maybe something wrong in my code) to please check all my coding.
    I suspect that it might be because of it being inside the loop but not sure.
    PLEASE HELP ME.

    Code:
    for (counter = 0; counter < this.items.length; counter++) { 
    			tempItem = this.items[counter];
    			j = counter + 1;
    			totalCount2 ++;
    			
    			/*************************SETTING VARIABLES FOR THE DATABASE PHP *****************************/
    			var custType = document.getElementById("f0").value;
    			var custName = document.getElementById("f1").value;
    			var custDbEmail = document.getElementById("f2").value;
    			var custNumber = document.getElementById("f3").value;
    			var custPostal1 = document.getElementById("f4").value;
    			var custPostal2 = document.getElementById("f5").value;
    			var custProvince = document.getElementById("province").value;
    			var custCode = document.getElementById("f6").value;
    			var itemDescription = tempItem.getValue('name');
    			var itemQuantity = tempItem.getValue('quantity');
    			var itemPrice = tempItem.getValue('price');
    			/************* THIS CODING TO POST THE VARIABLES TO myDb.php ****************/
    			var postingDb = $.post('myDb.php', {Type: custType,Name: custName,Email: custDbEmail,Number: custNumber,Postal1: custPostal1,Postal2: custPostal2,Province: custProvince,Code: custCode,Descript: itemDescription,Quant: itemQuantity,Pricee: itemPrice});
    			
    			/************* THIS CODE HAS NOTHING TO DO WITH THE DB ****************/
    			eftStrn = "Item:\t " + tempItem.getValue('name') +
    		              "\n\rQuantity:\t" + tempItem.getValue('quantity') +
    		              "\n\rAmount:\tR" + tempItem.getValue('price') + " each"  + "\n\r--------------------------------" +
    					  "\n\rItem Sub:\tR" + (tempItem.getValue('price')) * (tempItem.getValue('quantity')) + "\n\r--------------------------------\n\r";
    		
    			body_start = body_start + "\n\r" + eftStrn;
    		}
    MyDb.php code:
    Code:
    <?php
     
    // This will display South African Time.
     date_default_timezone_set("Africa/Johannesburg");
     $tz = date_default_timezone_get();
     $date = date(DATE_RFC822);
      
      /****************************************DATABASE STUFF **********************************************/
      // I am setting all my variables to make it easier to change code at a later stage by just changing the variables
    	$_host = "localhost";
    	$_user = "hans";
    	$_pass = "swanniebraai";
    	$database = "cust_list";
    	var $myconn;
    
    	// Connect to the DB
    			$conn= mysql_connect($_host, $_user, $_pass);
    			if(!$conn) {
    				die ("<strong>Cannot connect to the database</strong>");
    			}
    			else {
    				$this->myconn = $conn;
    				echo ("Connection established!<br /><br />");
    			}
    
    	// Select the DB
    			mysql_select_db($this->database);
    			if(mysql_error()) {
    				die ("<strong>Cannot find the database " . $this->database . "</strong>");
    			}
    			else {
    				echo ("Database selected!<br /><br />");
    			}
    			return $this->myconn;
    			
    
    	// Setting form field variable apon submit
    			$type = $_POST['Type']; 
    			$dateDb = $date;  
    			$name = $_POST['Name'];
    			$email = $_POST['Email'];
    			$number = $_POST['Number'];
    			$postal1 = $_POST['Postal1'];
    			$postal2 = $_POST['Postal2'];
    			$province = $_POST['Province'];   
    			$code = $_POST['Code'];
    			$descript = $_POST['Descript'];
    			$quant = $_POST['Quante'];
    			$price = $_POST['Price'];
    	
    	// To protect MySQL injection
    	//		$gamename = stripslashes($gamename);
    	//		$manufact = stripslashes($manufact);
    	//		$price = stripslashes($price);
    	//		$gamename = mysql_real_escape_string($gamename);
    	//		$manufact = mysql_real_escape_string($manufact);
    	//		$price = mysql_real_escape_string($price);
    			
    			
    	// INSERT INTO THE DB
    	$insert = "INSERT INTO orders VALUES ('', '$type', '$dateDb', '$name', '$email', '$numbert', '$postal1', '$postal2', '$province', '$code', '$descript', '$quant', '$price')";
    	mysql_query($insert)
    	
    	mysql_close($this->myconn);
    ?>

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,656
    This don't seem to work is not a javascript or php error. did you try to debug it somehow? your php code doesn't check the result of insertion it just closes connection to the db. if you change it to return the result you can see it with the $.post callback function.

  3. #3
    Join Date
    Oct 2011
    Location
    Durban
    Posts
    12
    I debugged and the $.post does not seem to set the variables. Why would that be.

  4. #4
    Join Date
    Oct 2011
    Location
    Durban
    Posts
    12

    Angry

    Ok here my debugging code.
    The $.post opens the dialog window to confirm the posting of the variables but none of the debugging alert windows in the php code works not even the first one for testing. So my conclusion is or some reason the php code is not executing. PLEASE HELP I AM LOSING MY HAIR.
    JavaScript
    Code:
    for (counter = 0; counter < this.items.length; counter++) { 
    			tempItem = this.items[counter];
    			j = counter + 1;
    			totalCount2 ++;
    			
    			/*************************SETTING VARIABLES FOR THE DATABASE PHP *****************************/
    			var custType = document.getElementById("f0").value;
    			var custName = document.getElementById("f1").value;
    			var custDbEmail = document.getElementById("f2").value;
    			var custNumber = document.getElementById("f3").value;
    			var custPostal1 = document.getElementById("f4").value;
    			var custPostal2 = document.getElementById("f5").value;
    			var custProvince = document.getElementById("province").value;
    			var custCode = document.getElementById("f6").value;
    			var itemDescription = tempItem.getValue('name');
    			var itemQuantity = tempItem.getValue('quantity');
    			var itemPrice = tempItem.getValue('price');
    			
    			/************* THIS CODE HAS NOTHING TO DO WITH THE DB ****************/
    			eftStrn = "Item:\t " + tempItem.getValue('name') +
    		              "\n\rQuantity:\t" + tempItem.getValue('quantity') +
    		              "\n\rAmount:\tR" + tempItem.getValue('price') + " each"  + "\n\r--------------------------------" +
    					  "\n\rItem Sub:\tR" + (tempItem.getValue('price')) * (tempItem.getValue('quantity')) + "\n\r--------------------------------\n\r";
    		
    			body_start = body_start + "\n\r" + eftStrn;
    			
    			/************* THIS CODING TO POST THE VARIABLES TO myDb.php ****************/
    			var postingDb = $.post('myDb.php', {Type: custType,Name: custName,Email: custDbEmail,Number: custNumber,Postal1: custPostal1,Postal2: custPostal2,Province: custProvince,Code: custCode,Descript: itemDescription,Quant: itemQuantity,Price: itemPrice});
    			postingDb.done(function( data ) {
    				alert("Successfully loaded variables."); /******* This does show *******/
    			});
    		}
    php
    Code:
    <?php
      
    // Setting form field variable apon submit
    			$type = $_POST['Type']; 
    			$dateDb = $date;  
    			$name = $_POST['Name'];
    			$email = $_POST['Email'];
    			$number = $_POST['Number'];
    			$postal1 = $_POST['Postal1'];
    			$postal2 = $_POST['Postal2'];
    			$province = $_POST['Province'];   
    			$code = $_POST['Code'];
    			$descript = $_POST['Descript'];
    			$quant = $_POST['Quant'];
    			$price = $_POST['Price']; 
    			
    /****************** DOES NOT EVEN OPEN THIS ********************/
    echo ("<script type='text/javascript'>	
    				window.alert('Testing');          
    				</script>");
    				
    // This will display South African Time.
     date_default_timezone_set("Africa/Johannesburg");
     $tz = date_default_timezone_get();
     $date = date(DATE_RFC822);	
     
    /****************************************DATABASE STUFF **********************************************/
      // I am setting all my variables to make it easier to change code at a later stage by just changing the variables
    	$_host = "localhost";
    	$_user = "hans";
    	$_pass = "swanniebraai";
    	$database = "cust_list";
    	var $myconn;
    
    	// Connect to the DB
    			$conn= mysql_connect($_host, $_user, $_pass);
    			if(!$conn) {
    				echo ("<script type='text/javascript'>	
    				window.alert('Could not connect to Database');
    				</script>");
    			}
    			else {
    				$this->myconn = $conn;
    				echo ("<script type='text/javascript'>	
    				window.alert('Connection Established!');
    				</script>");
    			}
    
    	// Select the DB
    			mysql_select_db($this->database);
    			if(mysql_error()) {
    				die ("<strong>Cannot find the database " . $this->database . "</strong>");
    			}
    			else {
    				echo ("Database selected!<br /><br />");
    			}
    			return $this->myconn;
    			
    
    	
    	
    	// To protect MySQL injection
    	//		$gamename = stripslashes($gamename);
    	//		$manufact = stripslashes($manufact);
    	//		$price = stripslashes($price);
    	//		$gamename = mysql_real_escape_string($gamename);
    	//		$manufact = mysql_real_escape_string($manufact);
    	//		$price = mysql_real_escape_string($price);
    			
    			
    	// INSERT INTO THE DB
    	$insert = "INSERT INTO orders VALUES ('', '$type', '$dateDb', '$name', '$email', '$numbert', '$postal1', '$postal2', '$province', '$code', '$descript', '$quant', '$price')";
    	//mysql_query($insert);
    	$result = mysql_query($insert) or die(mysql_error());
    	
    	mysql_close($this->myconn);
    ?>

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,656
    it's not clear what does your js loop do, what is the html-part and what js-errors you are getting (did you check for errors?). anyway, here is the simplified version of your scripts and html which works good for me:

    html + javascript

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Insert</title>
    <style>
    body{color:#000;background-color:#fff;font-family:'Bookman Old Style',Georgia,Verdana;font-size:14px;text-align:center;padding-top:100px;}
    #result{text-align:center;padding:50px;}
    input[type=reset],input[type=button]{cursor:pointer;}
    input[type=text]{text-align:center;}
    </style>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
    $(document).ready(function(){
    $('#btn').click(function(){
    $('#result').html('<h2>Processing...</h2>');
    var custType=$("#f0").val(),
    custName=$("#f1").val(),
    custDbEmail=$("#f2").val(),
    custNumber=$("#f3").val(),
    custPostal1=$("#f4").val(),
    custPostal2=$("#f5").val(),
    custProvince=$("#province").val(),
    custCode=$("#f6").val(),
    itemDescription=$('#name').val(),
    itemQuantity=$('#quantity').val(),
    itemPrice=$('#price').val();
    $.post(
    'myDb.php',
    {Type:custType,
    Name:custName,
    Email:custDbEmail,
    Number:custNumber,
    Postal1:custPostal1,
    Postal2:custPostal2,
    Province:custProvince,
    Code:custCode,
    Descript:itemDescription,
    Quant:itemQuantity,
    Price:itemPrice},
    function(data){$('#result').html(data);});
    });
    });
    </script>
    </head>
    <body>
    <form id="mf" method="post">
    <input type="text" id="f0" /><br />
    <input type="text" id="f1" /><br />
    <input type="text" id="f2" /><br />
    <input type="text" id="f3" /><br />
    <input type="text" id="f4" /><br />
    <input type="text" id="f5" /><br />
    <input type="text" id="f6" /><br />
    <input type="text" id="province" /><br />
    <input type="text" id="name" /><br />
    <input type="text" id="quantity" /><br />
    <input type="text" id="price" /><br /><br />
    <input type="reset" value="Reset" />&nbsp;&nbsp;&nbsp;<input type="button" id="btn" value="Send" />
    </form>
    <div id="result">result goes here</div>
    </body>
    </html>
    php

    Code:
    <?php
    // This will display South African Time.
    date_default_timezone_set("Africa/Johannesburg");
    $tz = date_default_timezone_get();
    $date = date(DATE_RFC822);
    /**********/
    $type=$_POST['Type'];
    $dateDb=$date;
    $name=$_POST['Name'];
    $email=$_POST['Email'];
    $number=$_POST['Number'];
    $postal1=$_POST['Postal1'];
    $postal2=$_POST['Postal2'];
    $province=$_POST['Province'];
    $code=$_POST['Code'];
    $descript=$_POST['Descript'];
    $quant=$_POST['Quant'];
    $price=$_POST['Price'];
    /**********/
    include('dbcon.php');
    /**********/
    $output='';			
    $sql="INSERT INTO `orders` VALUES ('','$type','$date','$name','$email','$numbert','$postal1','$postal2','$province','$code','$descript','$quant','$price')";
    $output.='$sql = <span style="color:Crimson;font-weight:bold">'.$sql.'</span><br />';
    $result=mysql_query($sql);
    $output.=(mysql_affected_rows()>0)?'Success!<br />'.mysql_affected_rows().' row(s) affected':'Error!<br /><b>'.mysql_error().'</b>';
    echo $output;
    mysql_close($link);
    ?>
    browser window screenshot

    phpMyAdmin db table `orders` screenshot

  6. #6
    Join Date
    Oct 2011
    Location
    Durban
    Posts
    12
    Thanks for response, this almost confirms my suspicion that the loop is the problem but I need it.
    The reason for the loop is if more than one item was added to the cart it loops through and adds it. Attached the whole code for that specific submit button.
    Code:
    /***********************************************************************************************************************************************
    	********************** EFT SE CHECKOUT GOEDJIES  ***********************************************************************************************
    	***********************************************************************************************************************************************/
    	// send user to eft email checkout with all the items in the cart
    	
    		this.eftCheckOut = function() { 
    		subject="Swanniebraai EFT Order";
    		/**************Code to check that cart is not empty**************/
    		if( this.totalItems == 0 ){
    			alert("Oh no! Your shopping cart is currently empty, and it's a little sad... So please... make your shopping cart happy and give its life purpose!");
    			return false;
    		}
    		/**************Code to check that postage option was selected**********************/
    		else if( !document.getElementById("p1").checked & !document.getElementById("p2").checked & !document.getElementById("p3").checked){
    			alert("You have not selected a postage option!");
    			return false;
    		}
    		/**************Code to check that Fastway color area selected**********************/
    		else if( document.getElementById("p2").checked & document.getElementById("fw").value == "select" ){
    			alert("You have not selected a colour region for Fastway Couriers!");
    			return false;
    		}
    		/**************Code to check that if International postage selected here to go to PAYPAL**********************/
    		else if( document.getElementById("p3").checked ){
    			alert("You can not select EFT payments for International Postage, Please make use of the PAYPAL check out button!");
    			return false;
    		}
    		/**************Code to check that all the information fields has been filled.**********************/
    		else if( document.getElementById("f1").value == "Enter Name and Surname" || document.getElementById("f2").value == "Enter Email Address" 
    		|| document.getElementById("f3").value == "Enter Contact number" || document.getElementById("f4").value == "Address line 1" 
    		|| document.getElementById("f5").value == "Address line 2" || document.getElementById("f6").value == "Postal code" ){
    			alert("Please complete all the fields in Your Information as they are all required!");
    			return false;
    		}
    		
    		/****************** THIS WILL ADD THE CUSTOMER INFORMATION TO THE EMAIL BODY *********************/
    		var custInformation = "";
    		custInformation = "Name:\t" + document.getElementById("f1").value + "\n" +
    						  "Email:\t" + document.getElementById("f2").value + "\n" +
    						  "Tel:\t\t" + document.getElementById("f3").value + "\n\n" +
    						  "Postal Address:\n" + 
    						  document.getElementById("f4").value + "\n" +
    						  document.getElementById("f5").value + "\n" +
    						  document.getElementById("province").value + "\n" +
    						  document.getElementById("f6").value + "\n";
    						  
    		body_start = body_start + "\n" + custInformation +"\n";
    		
    		
    		var totalCount2 = 0;
    		var i,j=0,des,counter;
    		
    		var eftStrn  = "";
    		counter = 0;
    		
    		for (counter = 0; counter < this.items.length; counter++) { 
    			tempItem = this.items[counter];
    			j = counter + 1;
    			totalCount2 ++;
    			
    			/*************************SETTING VARIABLES FOR THE DATABASE PHP *****************************/
    			var custType = document.getElementById("f0").value;
    			var custName = document.getElementById("f1").value;
    			var custDbEmail = document.getElementById("f2").value;
    			var custNumber = document.getElementById("f3").value;
    			var custPostal1 = document.getElementById("f4").value;
    			var custPostal2 = document.getElementById("f5").value;
    			var custProvince = document.getElementById("province").value;
    			var custCode = document.getElementById("f6").value;
    			var itemDescription = tempItem.getValue('name');
    			var itemQuantity = tempItem.getValue('quantity');
    			var itemPrice = tempItem.getValue('price');
    			
    			/************* THIS CODE HAS NOTHING TO DO WITH THE DB ****************/
    			eftStrn = "Item:\t " + tempItem.getValue('name') +
    		              "\n\rQuantity:\t" + tempItem.getValue('quantity') +
    		              "\n\rAmount:\tR" + tempItem.getValue('price') + " each"  + "\n\r--------------------------------" +
    					  "\n\rItem Sub:\tR" + (tempItem.getValue('price')) * (tempItem.getValue('quantity')) + "\n\r--------------------------------\n\r";
    		
    			body_start = body_start + "\n\r" + eftStrn;
    			
    			/************* THIS CODING TO POST THE VARIABLES TO myDb.php ****************/
    			var postingDb = $.post('../Swanniebraai/myDb.php', {Type: custType,Name: custName,Email: custDbEmail,Number: custNumber,Postal1: custPostal1,Postal2: custPostal2,Province: custProvince,Code: custCode,Descript: itemDescription,Quant: itemQuantity,Price: itemPrice});
    			postingDb.done(function( data ) {
    				alert("Successfully loaded variables."); /******* This does show *******/
    			});
    		}
    /******************************************************************************************************
    					This code outside the for loop to add the shipping charges		*********************************LEKKER SUKKEL*************************************
    ******************************************************************************************************/
    
    		var totalCost = 0.00;
    		if( document.getElementById("p1").checked ) {
    			if (this.totalPrice <596) {
    				totalCost = 50.00; }
    			else if (this.totalPrice > 595 & this.totalPrice < 1191) {
    				totalCost = 75.00;}
    			else if (this.totalPrice > 1190 & this.totalPrice < 1786) {
    				totalCost = 100.00;}
    			else if (this.totalPrice > 1785 & this.totalPrice < 2381) {
    				totalCost = 125.00;}
    			else if (this.totalPrice > 2380 & this.totalPrice < 2976) {
    				totalCost = 150.00;}
    			else if (this.totalPrice > 2975) {
    				totalCost = 0.00;}
    		}
    		/**************** FOR FASTWAY WHITE AREA DELIVERY OPTIONS ****************************/
    		else if( document.getElementById("p2").checked & document.getElementById("fw").value == "white" ) {
    			if (this.totalPrice <1786) {
    				totalCost = 95.00; }
    			else if (this.totalPrice > 1785 & this.totalPrice < 3571) {
    				totalCost = 120.00;}
    			else if (this.totalPrice > 3570 & this.totalPrice < 5356) {
    				totalCost = 210.00;}
    			else if (this.totalPrice > 5355 & this.totalPrice < 7141) {
    				totalCost = 300.00;}
    			else if (this.totalPrice > 7140) {
    				totalCost = 0.00;}
    		}
    		/**************** FOR FASTWAY GREY AREA DELIVERY OPTIONS ******************************/
    		if( document.getElementById("p2").checked & document.getElementById("fw").value == "grey" ) {
    			if (this.totalPrice <596) {
    				totalCost = 170.00; }
    			else if (this.totalPrice > 595 & this.totalPrice < 1191) {
    				totalCost = 340.00;}
    			else if (this.totalPrice > 1190 & this.totalPrice < 1786) {
    				totalCost = 510.00;}
    			else if (this.totalPrice > 1785 & this.totalPrice < 2381) {
    				totalCost = 680.00;}
    			else if (this.totalPrice > 2380 & this.totalPrice < 2976) {
    				totalCost = 850.00;}
    			else if (this.totalPrice > 2975) {
    				totalCost = 1020.00;}
    		}
    		
    		custEmail = document.getElementById("f2").value;
    		
    		body_start = body_start + "\n\r****************************\n\rSub Total:\tR" + parseFloat(this.totalPrice) + "\n\rShipping:\t R" + 
    		totalCost + "\n\rTotal Due:\tR" + (parseFloat(this.totalPrice) + parseFloat(totalCost)) + "\n\r****************************";
    		//var mailto_me='mailto:'+toEmail+'?subject='+subject+'&body='+escape(body_start) + 'method="post" enctype="text/plain"';
    		//window.open(mailto_me,'emailWin');
    		
    		var posting = $.post('../Swanniebraai/myEmailServer.php', {body: body_start,subject1: subject,cust: custEmail});
    		posting.done(function( data ) {
    		alert("Successfully sent emails.");
    		//window.open ("http://www.seatstick.co.za/Swanniebraai/thankyou1.html", '_self');
    		});
    		//window.location.href = "myEmailServer.php";
    		simpleCart.empty();
    		//window.open ("http://www.seatstick.co.za/Swanniebraai/thankyou1.html", '_self');
    		return true;
    		
    	};

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,415
    Have you considered that the problem may be with using Jquery? Its all fine and dandy using frameworks but your putting faith in to a system that is not javascript but uses javascript itself and the programming could just as easily have a bug itself and you are trouble shooting a problem that you are not going to fix.

    Maybe if you were to try making an AJAX object, search for a nice X-browser safe version, plenty of them about and try a simpler approach in native javascript.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #8
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,656
    hans_cellc, if you change your php to make it show the sql query string (like it does in my code) you will see which var is not set as it expected to be and it can give you a hint about javascript bugs location. you have never told us what is in your js error console or Firebug or what else you are using for debugging. you must understand that your scripts seem clear and plain only for you because you work with these scripts every day. from the other hand, if you are going to write complicated scripts, the first thing you have to master is debugging. the second chapter of "Secrets of the JavaScript Ninja" by John Resig is named Testing and Debugging and this is the first thing discussed after Introduction (chapter 1). looking at your code i can't presume that you don't know how to debug a loop or how to alert every variable (or all them together) before sending the $.post query. and, of course, \\.\ is right about trying native javascript.

    by all this i don't mean that we don't want to help you. i just want to say that you are the main your helper and we can only assist

  9. #9
    Join Date
    Oct 2011
    Location
    Durban
    Posts
    12

    Smile Eureka

    I found it and attached my code:
    What I found was simple problems with the php having to connect to the database with the "$this->myconn;" and unbelievably typos in the variable names and had variables declared in wrong places.

    My code:
    Code:
    for (counter = 0; counter < this.items.length; counter++) { 
    			tempItem = this.items[counter];
    			j = counter + 1;
    			totalCount2 ++;
    			
    			var itemDescription = tempItem.getValue('name');
    			var itemQuantity = tempItem.getValue('quantity');
    			var itemPrice = tempItem.getValue('price');
    			
    			/************* THIS CODE HAS NOTHING TO DO WITH THE DB ****************/
    			eftStrn = "Item:\t " + tempItem.getValue('name') +
    		              "\n\rQuantity:\t" + tempItem.getValue('quantity') +
    		              "\n\rAmount:\tR" + tempItem.getValue('price') + " each"  + "\n\r--------------------------------" +
    					  "\n\rItem Sub:\tR" + (tempItem.getValue('price')) * (tempItem.getValue('quantity')) + "\n\r--------------------------------\n\r";
    		
    			body_start = body_start + "\n\r" + eftStrn;
    			
    			var postingDb = $.post('myDb.php', {cust1: custEmail,Type: paymentType,From: custFrom,Name: custName,Number: custNumber,Postal1: custPostal1,Postal2: custPostal2,Province: custProvince,Code: custCode,Descript: itemDescription,Quant: itemQuantity,dbPrice: itemPrice,Delivery: deliveryOption});
    			postingDb.done(function( data ) {
    			alert("Successfully Updated DB.");
    			});
    		}
    PHP code:
    Code:
    <?php
      
    // This will display South African Time.
    	date_default_timezone_set("Africa/Johannesburg");
    	$tz = date_default_timezone_get();
    	$date = date("D, j M Y, G:i"); 
    	
    // Setting form field variable apon submit
    	$type = $_POST['Type']; 
    	//$from = $_POST['From'];  
    	$name = $_POST['Name'];
    	$email = $_POST['cust1'];
    	$number = $_POST['Number'];
    	$postal1 = $_POST['Postal1'];
    	$postal2 = $_POST['Postal2'];
    	$province = $_POST['Province'];   
    	$code = $_POST['Code'];
    	$descript = $_POST['Descript'];
    	$quant = $_POST['Quant'];
    	$price = $_POST['dbPrice']; 
     
    /****************************************DATABASE STUFF **********************************************/
      // I am setting all my variables to make it easier to change code at a later stage by just changing the variables
    	$_host = "localhost";
    	$_user = "hans";
    	$_pass = "swanniebraai";
    	$database = "cust_list";
    	//var $myconn;
    
    	// Connect to the DB
    	$conn = mysql_connect($_host, $_user, $_pass);
    	
    	// Sellect the Database
    	mysql_select_db($database);
    	
    	// INSERT INTO THE DB
    	$insert = "INSERT INTO orders VALUES ('', '$type', '$date', '$name', '$email', '$number', '$postal1', '$postal2', '$province', '$code', '$descript', '$quant', '$price', '', '', '')";
    	mysql_query($insert);
    
    	// CLOSE THE CONNECTION
    	mysql_close($conn);
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles