2 Replies - 1153 Views - Last Post: 20 February 2011 - 12:50 PM

#1 rpjd   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 08-March 07

Form data not submitted

Posted 19 February 2011 - 04:51 PM

I'm trying to submit form data to mysql database. The POST form action calls a javacript/ajax httpRequest. My php script has a redirect at the end of it on completion of data submission. My problem is after submitting the form, the redirection works, but no data is entered into database. I'm wondering if there is a problem with my httpRequest. Any help appreciated.
function submitPrefs(){
var URL = './PHP/submitPrefs.php';
var xmlhttp=false;
        xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
    catch (e){
	     xmlhttp = false;
            xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
       catch (E)
            xmlhttp = false;
       if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	 	xmlhttp = new XMLHttpRequest();
       	    catch (e)
      if (!xmlhttp && window.createRequest)
               xmlhttp = window.createRequest();
           catch (e)
var I = document.getElementById['I'];
var C = document.getElementById['C'];
var F = document.getElementById['F'];
var SS = document.getElementById['SS'];
var MS = document.getElementById['MS'];
var B = document.getElementById['B'];
var SSA = document.getElementById['SSA'];
var MSA = document.getElementById['MSA'];
var S = document.getElementById['S'];
var D = document.getElementById['D'];
var L = document.getElementById['L'];
var SR = document.getElementById['SR'];
var DR = document.getElementById['DR'];
var FG = document.getElementById['FG'];
var BG = document.getElementById['BG'];
var O = document.getElementById['O'];
var G = document.getElementById['G'];
var BY = document.getElementById['B'];
var M = document.getElementById['M'];
var MX = document.getElementById['MX'];
var FR = document.getElementById['FR'];
var VR = document.getElementById['VR'];
var ML = document.getElementById['ML'];
var CL = document.getElementById['CL'];
var DL = document.getElementById['DL'];
var params = 'I='+I+'&C='+C+'&F='+F+'&SS='+SS+'&MS='+MS+'&B='+B+'&SSA='+SSA+'&S='+S+'&D='+D+'&L='+L+'&SR='+SR+
xmlhttp.open('POST', URL, true);
      if (xmlhttp.readyState == 4 && http.status == 200)

Is This A Good Question/Topic? 0
  • +

Replies To: Form data not submitted

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5227
  • View blog
  • Posts: 14,010
  • Joined: 18-April 07

Re: Form data not submitted

Posted 20 February 2011 - 11:12 AM

And are you sure that your PHP code is correct? Did you test it separately from the javascript code? If it is not inserting into the database, and PHP is in charge of that, then perhaps it could be an error there.

Secondly, are you sure that the params string is coming out with all the correct values? Put params in an alert() call and see if the string at the end of all the additions is correct before you send it.

My guess is that either the params string has some invalid parameters or your PHP script has an error where it is not inserting into the database. You can show your PHP script code too and perhaps someone can help further.

Was This Post Helpful? 0
  • +
  • -

#3 Guest_Richard Dunne*


Re: Form data not submitted

Posted 20 February 2011 - 12:50 PM

This is my php script:
$host = 'localhost';
$user = 'user';
$pass = 'pass';
    $Con = mysql_connect($host, $user, $pass);
        die('There was an error connecting to the server, please try again later.' . mysql_error());
    	$db = mysql_select_db("database", $Con);
	$I = (int)!empty($_POST['I']);
        $C = (int)!empty($_POST['C']);
        $F = (int)!empty($_POST['F']);
        $SS = (int)!empty($_POST['SS']);
        $MS = (int)!empty($_POST['MS']);
        $B = (int)!empty($_POST['B']);
        $SSA = (int)!empty($_POST['SSA']);
        $MSA = (int)!empty($_POST['MSA']);
        $S = (int)!empty($_POST['S']);
        $D = (int)!empty($_POST['D']);
        $L = (int)!empty($_POST['L']);
        $SR = (int)$_POST['SR'];
        $DR = (int)$_POST['DR'];
        $FG = (int)!empty($_POST['FG']);
        $BG = (int)!empty($_POST['BG']);
        $O = (int)!empty($_POST['O']);
        $G = (int)!empty($_POST['G']);
        $AI = (int)$_POST['AI'];
        $MX = (int)$_POST['MX'];
        $BY = (int)!empty($_POST['BY']);
        $M = (int)!empty($_POST['M']);
        $FR = (int)!empty($_POST['FR']);
        $VR = (int)!empty($_POST['VR']);
        $ML = (int)$_POST['ML'];
        $CL = mysql_real_escape_string($_POST['CL']);
        $DL = mysql_real_escape_string($_POST['DL']);
        echo "$I, $C, $F, $SS, $MS, $B, $SSA, $MSA, $S, $D, $L, $SR, $DR, $FG, $BG, $O, $G, $AI, $MX, $BY, $FR,   $VR, ML, $CL, $DL";
	//if(!mysql_query("insert into preferences (I, C, F, SS, MS, B, SSA, MSA, SR, DR, S, D, L, FG, BG, G, O, AI, MX, BY, M, FR, VR, ML, CL, DL) values ('$I', '$C', '$F', '$SS', '$MS', '$B', '$SSA', '$MSA', '$SR', '$DR', '$S', '$D', '$L', '$FG', '$BG', '$G', '$O', '$AI', '$MX', '$BY', '$M', '$FR', '$VR', '$ML', '$CL', '$DL')"); )
	//echo "No data entered" . mysql_error();

I was getting a parse error on the mysql_query line. So I did an echo to see if there was a problem with any of the data being inserted and found 1 problem. ML is a text field into which the user enters a integer. For some reason
$ML = (int)$_POST['ML'];
is not picking up the value of the text field, its taking the actual id ML instead. Every other field is returning a value. Very strange!
Was This Post Helpful? 0

Page 1 of 1