I am missing something stupid,

Discussion in 'PHP' started by Sleeping Troll, Sep 1, 2008.

  1. #1
    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>";
    }
    ?>
     
    Sleeping Troll, Sep 1, 2008 IP
  2. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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>";
     
    dean5000v, Sep 1, 2008 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah. If you aren't getting a response chances are that the while is immediately breaking so its not outputting anything
     
    JAY6390, Sep 1, 2008 IP
  4. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sounds good guys, thx.
     
    Sleeping Troll, Sep 1, 2008 IP
  5. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #5
    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')";
     
    lanmonkey, Sep 1, 2008 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    True, but depending on how your syntax hilighter works, it's clearer to see the var in the SQL query
     
    JAY6390, Sep 1, 2008 IP
  7. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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?
     
    Sleeping Troll, Sep 1, 2008 IP
  8. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If you run your script with just your browser does it show then? Also, you should edit out your password from the above code
     
    JAY6390, Sep 1, 2008 IP
  9. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    OOPS! THX.
    ? not sure what you mean by "just my browser".
     
    Sleeping Troll, Sep 1, 2008 IP
  10. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #10
    JAY6390, Sep 1, 2008 IP
  11. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    My browser can't run php.
     
    Sleeping Troll, Sep 2, 2008 IP
  12. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #12
    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.
     
    lanmonkey, Sep 2, 2008 IP
  13. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #13
    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 :)
     
    JEET, Sep 2, 2008 IP