Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts

    Question mysql error no data displayed

    Hey guys, Ok.. either i dont know how to code or there is a problem with the mysql server but its probably me.. anyway this script will not display the output by the echo command that i stated, can someone please help me solve this.ITS DRVIN ME CRAZY.haha than for any help.
    PHP Code:
    <?php include("Connections/mysql.php"); ?>
    <?
    mysql_select_db
    ('rubygir_slappyjaw'$mysql);
    $myid $_SESSION['kt_login_id'];
    $result mysql_query("SELECT * FROM friendreqs WHERE foridus2=$myid;");

    while(
    $row mysql_fetch_array($result))
      {
    $userfrom $row['userfrom'];
    $usertime $row['time'];
      }

    mysql_close($mysql);

    $title "Friend request";
    //INCLUDE THE HEADER!
    include("user_header.php");
    ?>
    <html>
    <body>
    <table width="200" border="1">
      <tr>
        <td><? echo $userfrom;?> </td>
        <td><? echo $usertime;?></td>
      </tr>
    </table>
    </body>
    </html>

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    1st off:
    CHange

    $result = mysql_query("SELECT * FROM friendreqs WHERE foridus2=$myid;");

    to

    $result = mysql_query("SELECT * FROM friendreqs WHERE foridus2=$myid;") or die(mysql_error());

    Secondly, what is the semicolon for at the end of the query?

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Its likely a scope issue. I believe anything declared within the loop won't be available to the rest of the page however I don't think a loop is necessary here.
    PHP Code:
    <?php
    include("Connections/mysql.php");
    mysql_select_db('rubygir_slappyjaw'$mysql);
    $myid $_SESSION['kt_login_id'];
    $result mysql_query("SELECT * FROM friendreqs WHERE foridus2=$myid") or die(mysql_error());
    $row mysql_fetch_array($result);
    $userfrom $row['userfrom'];
    $usertime $row['time'];

    mysql_close($mysql);

    $title "Friend request";
    //INCLUDE THE HEADER!
    include("user_header.php");
    ?>
    <html>
    <body>
    <table width="200" border="1">
      <tr>
        <td><?php echo $userfrom;?> </td>
        <td><?php echo $usertime;?></td>
      </tr>
    </table>
    </body>
    </html>
    Also STOP using short open e.g. <? as to <?php. They only cause problems. When PHP6 is released your code won't work.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    slappyjaw (08-29-2009)

  • #4
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    yea idk why i put that there i removed it but it throws the error
    Code:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    Also even if i try to create something like this with dreamweaver it will not show the results.

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Where is $myid coming from? Can you echo it out to see if it is set?

    Edit: I realize its a session var but i mean where is it being set


    Odd though, usually the mysql error prints out some context so you can see where the error is.

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #6
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    hmmmm dan i see what you mean the myid is not set for some reasion. it is set when you log in. will a session variable stay registered through out the site when you are logged in?

  • #7
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    oh, duh lol.

    You need session_start() at the top of every page. I swear I make that mistake at least twice every time i work on a site

    Edit: To answer your question, yes a SESSION var will stay set as long as the SESSION hasn't expired. I believe there can also be some issues across subdomains as well.


    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • Users who have thanked whizard for this post:

    slappyjaw (08-29-2009)

  • #8
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    oh ok hahaha ill try that now. thanks

  • #9
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    oh yea now its working wow i am going to add that to all my headers, thanks a lot dan!

  • #10
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    no problem!
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #11
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts

    so heres another mysql thing

    PHP Code:
    <?php require_once('../../Connections/mysql.php'); ?>
    <?php
    $userid1 
    $_POST['userid15'];
    $userid2 $_POST['userid25'];
    $username1 $_POST['username15'];
    $username2 $_POST['username25'];
    $idremove $_POST['idremove5'];
    mysql_select_db('rubygir_slappyjaw'$mysql);
    mysql_query("INSERT INTO friends (userid1, userid2, username1, username2) VALUES ($userid1, $userid2, $username1, $username2)") or die(mysql_error());
    mysql_query("DELETE FROM friendreqs WHERE id = $idremove") or die(mysql_error());
    ?>
    I used some of the same rules but i think that there is something wrong in the mysql query part. the error says
    Code:
    Unknown column 'slappyjaw' in 'field list'
    and slappyjaw is the $username1 submitted data.
    Is it ok that i am trying to insert and delete something in the file. Its for my friend request system.
    Last edited by slappyjaw; 08-29-2009 at 05:32 AM.

  • #12
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Are you sure that's the exact and total code...it doesn't seem like that error is possible from that code. The error is saying that you are trying to put something into a column named 'slappyjaw', which you are not trying to do in that code.....

    This error could happen easily if you accidentally put a dollar sign in front of the username1 column name...
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #13
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    yes thats what i said because it makes no scene.

  • #14
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    OK, do this.

    <?php require_once('../../Connections/mysql.php'); ?>
    <?php
    $userid1 = $_POST['userid15'];
    $userid2 = $_POST['userid25'];
    $username1 = $_POST['username15'];
    $username2 = $_POST['username25'];
    $idremove = $_POST['idremove5'];
    mysql_select_db('rubygir_slappyjaw', $mysql);

    $query = "INSERT INTO friends (userid1, userid2, username1, username2) VALUES ($userid1, $userid2, $username1, $username2)";
    mysql_query($query) or die(mysql_error());

    print $query;

    mysql_query("DELETE FROM friendreqs WHERE id = $idremove") or die(mysql_error());
    ?>

    That way it will print out the query, and we can at least see what its sending
    Last edited by whizard; 08-29-2009 at 05:48 AM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #15
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    mm its still displays that error. could it be the server


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •