Jump to content

index not recognized


Lord Cupid

Recommended Posts

Hey!I'm using AJAX and as far as I can tell, the program is fully debugged.Only, when control is transferred to 'mysql_db.php', an error message is returned: stating that the index variables are not defined.They are defined in the form element, only the system won't recognize them.mysql_db.php file:

...// Collect User Inputted Data!$rec[$tbl['DB_USER']]=$_POST['Username'];	 // Selected name of User$rec[$tbl['DB_CHANNEL']]=$_POST['UserChannel'];  // User selected channel #$rec[$tbl['DB_CHATLINE']]=$_POST['UserResponse'];   // User's response...

...  <form action="" method="post" onsubmit="writetomysql()">  // action & method were added while debugging the issue  Username:  <input type="text" id="Username" name="Username" value="Lord Cupid" />  Channel:  <input type="text" id="UserChannel" name="UserChannel" value="1" />  Communique:  <input type="text" id="UserResponse" name="UserResponse" value="Hello World!" />  <input type="submit" value="Send" />  <input type="reset" value="Clear" />  </form>...<script type="text/javascript">function writetomysql(){var xmlHttp;try  {    // Firefox, Opera 8.0+, Safari    xmlHttp=new XMLHttpRequest();    }catch (e)  {  // Internet Explorer    try	{		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");		}  catch (e)	{		try	  {	  	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	  	  }	catch (e)	  {	  	  alert("Your browser does not support AJAX!");	  	  return false;	  	  }		}    }  xmlHttp.onreadystatechange=function()	{	if(xmlHttp.readyState==4)	  {	  alert("the response came back: \n" + xmlHttp.responseText);   // This is where the index error messages show	  }	}	data="";	data+=escape(document.getElementById("Username").value);		// These indexes are recognized here!	data+=escape(document.getElementById("UserChannel").value);	data+=escape(document.getElementById("UserResponse").value);  xmlHttp.open("POST","mysql_db.php",true);  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  xmlHttp.setRequestHeader("Content-length", data.length);  xmlHttp.send(data);}</script>

Link to comment
Share on other sites

Try outputting the data var (e.g. in an alert box), see what it says.
I did and data filled up just fine, including %20 for spaces inside the data variable.Really, I can't find anything wrong.You can go to http://cupidscrystals.com and try it out yourself. Just type something in the bottom frame and it will display in the frame just above it. And that's as far as I got since December 2007. Of course, a lot of that time has to do with the Tutorials at http://W3Schools.comPeace, Grace & Love;Lord Cupid
Link to comment
Share on other sites

Here's the significant code:

<?php?><html>  <head>  <title>Chatters version 1.0.1</title>    <script src="errorhandler.js"></script>  </head>  <body>  <form action="" method="post" onsubmit="sendCommunique(UserResponse.value)">  Username:  <input type="text" id="Username" name="Username" value="Billy Bob" />  Channel:  <input type="text" id="UserChannel" name="UserChannel" value="1" />  Communique:  <input type="text" id="UserResponse" name="UserResponse" value="Hello World!" />  <input type="submit" value="Transmit!" />  <input type="reset" value="Clear" />  </form>Chatters version 1.0.1Developer:  Lord CupidCupid@CupidsCryatals.comCopyright © 2007-2008 Cupid's Crystals<script type="text/javascript">function sendCommunique(str){  if (str.length==0) {return;}  var w = parent.frames[4].document.getElementById('UserChannel');  var x = parent.frames[4].document.getElementById('Username');  var y = parent.frames[4].document.getElementById('UserResponse');  var z = parent.frames[3].document.getElementById('topText');  var UserRecord = "Channel: "+ w.value +" ["+Date()+"] ";  UserRecord+= x.value +":  "+ y.value;  var movedivision = '<div id="topText" name="topText"></div>';  z.document.write(UserRecord + movedivision);  // The above Coding Credit goes to:  Deirdre's Dad  // Transmit the data to MySql database & dispatch through the data Channel  if (datatransmitter()==false)  {  alert("runtime failure:  no execution");   // never executes!  return;  }}function datatransmitter(){var xmlHttp;try  {    // Firefox, Opera 8.0+, Safari    xmlHttp=new XMLHttpRequest();    }catch (e)  {  // Internet Explorer    try	{		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");		}  catch (e)	{		try	  {	  	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	  	  }	catch (e)	  {	  	  alert("Your browser does not support AJAX!");	  	  return false;	  	  }		}    }  xmlHttp.onreadystatechange=function()	{	if(xmlHttp.readyState==4)	  {	  alert("the response came back: \n" + xmlHttp.responseText);  // This alerted me to the indicies being undefined	  }	}	data="";	data+=escape(document.getElementById("Username").value); // The indices work here!  Spaces are %20	data+=escape(document.getElementById("UserChannel").value); // when data is displayed in a js alert() message.	data+=escape(document.getElementById("UserResponse").value);  xmlHttp.open("POST","mysql_db.php",true); // Are we talking a 'conf' problem?  Like php4 is   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // being used as default instead of  xmlHttp.setRequestHeader("Content-length", data.length); // php5?  I've updated php.ini for 5, and assumed that  xmlHttp.send(data);	// php4 works with Global_Vars by default.}	// Of course, I could be mistaken.	 // Nobody is perfect!	// Well, I'm open for comments if somebody can figure   // this thing out.  Infact, I'll send the winning 'debugger'  // Person a Hershey's Chocolate Bar! // mailing address required!// Grace, Peace & Love;</script>	// Lord Cupid   </body></html>

Link to comment
Share on other sites

Those aren't AJAX or Javascript errors, those are PHP errors. Here they are:the response came back:Notice: Undefined index: Username in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 6Notice: Undefined index: UserChannel in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 8Notice: Undefined index: UserResponse in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 10Notice: Undefined index: UserChannel in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 12Notice: Undefined index: Username in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 13Notice: Undefined index: UserResponse in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 14They are all in the mysql_db.php file on the indicated line numbers. It means that there is no data where you are looking. If you are trying to save something in $_POST['Username'], for example, the message says there is not a Username index in $_POST. Make sure spelling and capitalization match. You can use the isset function if you want to check if the variable is set before you access it, that will stop the error message from appearing.Before you send the data variable using AJAX, alert data. You'll notice that you aren't giving anything names, you're only sending the values. You need to send a normal URL-encoded key/value string, like what goes on the end of a URL for data in $_GET.

Link to comment
Share on other sites

Before you send the data variable using AJAX, alert data. You'll notice that you aren't giving anything names, you're only sending the values. You need to send a normal URL-encoded key/value string, like what goes on the end of a URL for data in $_GET.
Okay, I'll try that.I'm still just a baby at learning thse languages, though eventually I'll get the hang of it.Like the time I was programming in RPG II. That was not a linear programming language where you write code and setup routines and stuff that goes bump in the night. Rather, it looks like circular coding where one routine links to the next until you've complete a circle in routines and you're right back where you started from. An example would be client billing where after going through a sequence of events, you wind up at the starting routine for the next cycle.Well, that was my experience with RPG II - Report Programming Language.Peace, Grace & Love;Lord CupidBTW: RPG II has nothing to do with this programming experience, I was simply reminising!
Link to comment
Share on other sites

Those aren't AJAX or Javascript errors, those are PHP errors. Here they are:the response came back:Notice: Undefined index: Username in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 6Notice: Undefined index: UserChannel in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 8Notice: Undefined index: UserResponse in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 10Notice: Undefined index: UserChannel in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 12Notice: Undefined index: Username in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 13Notice: Undefined index: UserResponse in /hermes/bosweb/web295/b2957/sl.cupidscr/public_html/Apps/CyberMall/chatters/mysql_db.php on line 14They are all in the mysql_db.php file on the indicated line numbers. It means that there is no data where you are looking. If you are trying to save something in $_POST['Username'], for example, the message says there is not a Username index in $_POST. Make sure spelling and capitalization match. You can use the isset function if you want to check if the variable is set before you access it, that will stop the error message from appearing.Before you send the data variable using AJAX, alert data. You'll notice that you aren't giving anything names, you're only sending the values. You need to send a normal URL-encoded key/value string, like what goes on the end of a URL for data in $_GET.
Could possibly expain why my $_POST or $_REQUEST variables are Not Defined as I thought this to be automaticly done when I defined them in the <form> element in HTML???None of these errors make any sense to me just yet. I'm sure they will become abundantly clear to me in the future as I continue my programming endeavours in HTML, XML, PHP, JavaScript and so on down the line.Right now, I'm grasping at straws and searching this forum for a proper explaination, and the code I tried out, someone else said it worked for them just fine. So, please reduce the technical jargon to something simple that I can understand and actually use to finish this program that was originally scheduled to take a few lines of code that would only take up a couple of hours of my time, and not the several months it's been of a living nightmare!!!Grace, Peace & Love,Lord CupidBTW: My forum got knoced off the air - probably by the FBI. And I can't really blame them as my board appeared dead as a doornail and yet there are over 900 members signed up in only 2 months time. I started checking member's websites - and you talk about loaded with PORN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!My next programming endeauvor is to build a robot to examine each and everyone of those sites for 2 things:Porn & virus dispatching routineswith the later being reported to the FBI as malicious software being downloaded onto innocent people's computers. I hate that sort of thing and people who do that will burn in ###### for all eternity!!!!!!!!!!!!!!!!!Also, God is putting out of business anyweb site that dumps spyware/adware onto my computer - so beware! Okay, how do I define $_REQUEST variables that get sent to 'mysql_db.com' ?????????????LC
Link to comment
Share on other sites

How do you people dig these things up?

	data='';	data+='Username='+escape(document.getElementById("Username").value);	data+='&UserChannel='+escape(document.getElementById("UserChannel").value);	data+='&UserResponse='+escape(document.getElementById("UserResponse").value)

Note the delimiting '&' on the 2nd & 3rd variable name definitions embedded in the string above.Took me from 7:30 am to 9am to see this. Now, how exactly am I - 'am I' is God's name backwards! - supposed to know these things? And how exactly how do you do - 'how do you do' is a greeting! - a search on these things, or even know that they exist? When the data string was all strung together under a single name, I instinctively knew there had to be a delimiter involved and stringed commas didn't do the trick. Going back to the original example I found, that's when I saw the '&' delimiter and then knew what it was.Having flashbacks from the Past:When I learned Microsoft, Macro Assembler back in 1980 or so, I read the book cover to cover, then about halfway to 3 quarters through it on my initial read experience, the language began to sink into my mind. Even so, one of the first things that I read was:Every number has a maximum value of 256, represented as 0 - 255 decimal, or 0 - FF hexidecimal.Then I began to wonder, what if my number is 257? Well, the answer was combining data bytes to produce a printable number. Then it really got funky when I wrote my division routine and floating point decimal routine. I think I even wrote a routine for divide by zero, even though the computer had a routine all it's own for that and crashed the system, from time to time. The IBM PC, at a whopping cost of $4,000 - Dad funded me! :) - I bought the printer though at only $100 - ran at only a mere 4.77 MHz. When 3rd party Turbo mother boards came out, they ran at 8.77 MHz. Some had a toggle switch on the computer case and other were triggered by hitting alt dash or alt plus.Ah, yes! The Good 'Ole Days!Ok, I'm finally getting somewhere in my program endeavours of HTML, JavaScript, AJAX, & PHP.Is there anyway to convert PHP $variables to JavaScript variables???Love all!Lord CupidToday is The LORD's Sabbath for the United States of Love, Sunday - the day that Good Christians go to Church for the Worship of God - to declare our Love for God; get edified through the Sermon's of the Priest or Pastor; and to gladly give our tithes to the Church for our own blessings from The LORD & Jesus Christ & Xanadu.Friday is my Day Off for The LORD because I work on Sundays, preaching The Word of God whenever and wherever. Same for Lord Saint Dennis and also, Billy Bob.I put this in here because of the hardness of people's hearts who would accuse me of working on The LORD's Sabbath. Jesus Christ is also the Lord of the Sabbath.

Link to comment
Share on other sites

How do you people dig these things up?
Get a book that describes the language.
Is there anyway to convert PHP $variables to JavaScript variables???
Not natively. You can print the values from PHP into Javascript code for scalar values, or for complex data structures something like JSON would work. Go to json.org for information about that.And please only include relevant information in your posts, they are difficult to read otherwise. That is a lot of text to read through to get the two questions you were asking. You will find that more people will be willing to respond to your posts if they don't have to read through a lot of non-sequitor text to get to your question.
Link to comment
Share on other sites

  • 1 month later...
Get a book that describes the language.Not natively. You can print the values from PHP into Javascript code for scalar values, or for complex data structures something like JSON would work. Go to json.org for information about that.And please only include relevant information in your posts, they are difficult to read otherwise. That is a lot of text to read through to get the two questions you were asking. You will find that more people will be willing to respond to your posts if they don't have to read through a lot of non-sequitor text to get to your question.
Hey!Let's see, 2nd part first: Telling me not to ramble is like telling 'Ole Faithful not to erupt! That just ain't a 'gonna happen.Over the past month, I've learned a heck of a lot and I can print HTML code via PHP then intercept with JavaScript to load PHP $variables into JavaScript var variables. Real easy, eh mate?Of course, not as simple as 'push dx, pop ax' as in Assembly Language.Though, if the Geniuses that came up with HTML (oh, one of them was me! :) ) were to add a stack for variable & constant passing from one system to another, that would be real nifty.If 'They' did add a stack, it would be something else to blow! Get it? Blow your Stack? Right!Grace, Peace & Love;Lord Cupid
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...