I have this server script for ajax and it is not returning response! I have tried commenting out database operations and just putting a simple -echo "Test"- and I still get no response text!? <?php $conn = mysql_connect("xxx","xxx","xxx"); mysql_select_db("xxx",$conn); $Title = $_GET["Title"]; $SQL = "Insert Into Categories Values (NULL,'".$Title."','Enabled')"; mysql_query($SQL); $SQL = "Select * From Categories"; $result = mysql_query($SQL); while($row = mysql_fetch_array($result)) { echo " <tr>"; echo " <td><div class = 'style8' align = 'left'>".$row['Title']."</div></td>"; echo " <td><div class = 'style8' align = 'right'>".$row['Enable']."</div></td>"; echo " </tr>"; } ?>
try using . mysql_error(), to see whats going wrong, also try echo " <td><div class = 'style8' align = 'left'>{$row['Title']}</div></td>"; echo " <td><div class = 'style8' align = 'right'>{$row['Enable']}</div></td>";
Yeah. If you aren't getting a response chances are that the while is immediately breaking so its not outputting anything
its a minor thing but on the following line: $SQL = "Insert Into Categories Values (NULL,'".$Title."','Enabled')"; you dont need to concatenate $title because the string is within double quotes which will convert all vars to thier values, so write it like this: $SQL = "Insert Into Categories Values (NULL,'$Title','Enabled')";
I am new to php, not concatenating is simpler. However that does not explain why this... <?php $conn = mysql_connect("xxx","xxx","xxx"); mysql_select_db("xxx",$conn); $Title = $_GET["Title"]; $SQL = "Insert Into Categories (Title,Enabled) Values ('$Title','Enabled')"; mysql_query($SQL); $SQL = "Select * From Categories"; $result = mysql_query($SQL); while($row = mysql_fetch_array($result)) { echo " <tr>"; echo " <td><div class = 'style8' align = 'left'>{$row['Title']}</div></td>"; echo " <td><div class = 'style8' align = 'right'>{$row['Enable']}</div></td>"; echo " </tr>"; } ?> Code (markup): Returns "" to client. In fact this... <?php echo "hello" ?> returns "" to client Am I missing something about php and ajax?
If you run your script with just your browser does it show then? Also, you should edit out your password from the above code
Go into firefox or w/e and type in the addressbar www.yourdomain.com/scriptname.php?Title=TitleHere and see if it gives an output
you need a web server that has the php extension installed..... if you dont know about htis then I seggest you google for XAMP or uniserver.
Hi, Post the ajax function here. Problem is there, not in php script. Are you sure the javascript is parssing correctly? Also, If you are using Internet Explorer, it won't allow ajax to work with cross domains. Like: if your domain is: something.com and the php script is on something_else.com then ajax will not respond. (If this is the case, then To get this working you need to turn on "allow cross browser scriptting" in IE settings) By default this turned off, so most people visiting your site will not see a response. To overcome this, use another php script in between. Ex: put some_script.php on something.com (where ajax is), get the contents of actual sql script like this: <?php echo file_get_contents('http://something_else.com/script.php'); ?> The ajax function should point to something_script.php, not something_else.com/script.php Post the ajax function here, then this will be clear. regards