Niccaman Posted April 3, 2009 Share Posted April 3, 2009 I have some php code which javascript connects to in order to return to a table to a div with ajax. Then i insert some code ive been using as i always have with other pages, and nothing gets inserted to the div. No tables ...nada. Just as if there's a syntax error. however if i access this php page seperately, i can see the page fine with no syntax error. The code that makes the ajax stop working is this: " // ** Connect to Database ** $con = (mysql_connect("localhost", "xxx", "xxx")); if (!$con) { die('Could not connect: ' . mysql_error()); } // ** Select MySQL table "agents" ** mysql_select_db("xxx",$con); " I know this code works. How can inserting this code prevent inserting anything in the div???? Quote Link to comment https://forums.phpfreaks.com/topic/152402-solved-wtf/ Share on other sites More sharing options...
Niccaman Posted April 3, 2009 Author Share Posted April 3, 2009 Also, when using IE, the javascript never works, and there is a yellow triangle with "error on page" at bottom left hand corner of screen. So it must be the javascript? Here is my javascript: <script type="application/javascript" language="javascript"> var xmlHttp; function manageFlights(str) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="/business/airline.php"; url=url+"?b="+str+"&i=1"; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function buyPlane(bus) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="/business/airline.php"; var num = document.form.abc; for (i=0; i<num.length; i++) { if (num.checked == true) num = num.value; } url=url+"?b="+bus+"&n="+num+"&i=1"; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("manage").innerHTML=xmlHttp.responseText; } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } </script> Quote Link to comment https://forums.phpfreaks.com/topic/152402-solved-wtf/#findComment-800406 Share on other sites More sharing options...
Niccaman Posted April 3, 2009 Author Share Posted April 3, 2009 The IE error on page provides "Expected Object" error when double clicking it. (didn't know you could double click). It referes to a line where i call the function. Here is that specific line: <tr class="foundation"><td align="center">Rogue Airways</td><td align="center">Airline</td><td align="center">2009-03-25 17:22:45</td><td align="center"><a href="#" onclick="manageFlights(1);">Manage</a></td></tr></table> Please can someone work out what isnt syntactically correct? Quote Link to comment https://forums.phpfreaks.com/topic/152402-solved-wtf/#findComment-800531 Share on other sites More sharing options...
Niccaman Posted April 3, 2009 Author Share Posted April 3, 2009 lol, i didn't realise these forums were blogs. People much quicker at anwering topics on php help than this. Anyway i realised that my problems were because i have type="application:javascript" rather than text.javascript or something or other. STILL PROBLEMS WITH: executing these lines of code prevents ajax, unless i place in a function and dont call it. Therefore no syntax error but why happening. Here code: function connect() { // ** Connect to Database ** $con = (mysql_connect("localhost", "niccaman_bond", "007")); if (!$con) { die('Could not connect: ' . mysql_error()); } // ** Select MySQL table "agents" ** mysql_select_db("niccaman_agents",$con); } Cmon guys tell me! Why does it prevent php page returning a table? Quote Link to comment https://forums.phpfreaks.com/topic/152402-solved-wtf/#findComment-800621 Share on other sites More sharing options...
Zane Posted April 3, 2009 Share Posted April 3, 2009 function connect() { // ** Connect to Database ** $con = (mysql_connect("localhost", "niccaman_bond", "007")); if (!$con) { die('Could not connect: ' . mysql_error()); } // ** Select MySQL table "agents" ** mysql_select_db("niccaman_agents",$con); } There is nothing wrong with the above code...it is actually the most generic of scripts there are. Like you mentioned earlier...you forgot text/javascript it most definitely is an external problem....show your full code..with code tags... Quote Link to comment https://forums.phpfreaks.com/topic/152402-solved-wtf/#findComment-800626 Share on other sites More sharing options...
Zane Posted April 3, 2009 Share Posted April 3, 2009 Actuall you should shorten that function to 2 lines function connect($dbServer, $user, $pass, $dbName) { $c = mysql_connect($dbServer, $user, $pass) or die(mysql_error()); mysql_select_db($dbName); } mysql_select_db("niccaman_agents",$con); You only need to provide the connection link if you are using more than one MySQL server...so nix that second argument next time you go about that Quote Link to comment https://forums.phpfreaks.com/topic/152402-solved-wtf/#findComment-800627 Share on other sites More sharing options...
Niccaman Posted April 3, 2009 Author Share Posted April 3, 2009 Ok, Thanks for the advice Zanus. I found my problem in the php page. Did some old fashioned trial and error. pasted 'die("!");' after every x amount of code till i found where the code failed. I eventually narrowed it down to a while ($row = mysql_fetch_array($res)) {...} situation. Within that loop i called upon a function which i had removed. Thats why it only failed when i connected to a server. It was the only time the while loop condition was met! How SILLY! Thanks anyway for help (even though i solved it myself) Quote Link to comment https://forums.phpfreaks.com/topic/152402-solved-wtf/#findComment-800650 Share on other sites More sharing options...
corbin Posted April 4, 2009 Share Posted April 4, 2009 Niccaman, if you turned on displaying errors, you would have seen a "Call to undefined function" error. Zanus, what if he wanted to add a second link later? Also, to be really picky, I would imagine it is a tiny bit faster to pass the second parameter since then the mysql_select_db function (or what ever it's called on the PHP core level) does not have to look for the last opened connection. Quote Link to comment https://forums.phpfreaks.com/topic/152402-solved-wtf/#findComment-800874 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.