1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Having Problems with mysql error

Discussion in 'Programming' started by macstux, Aug 21, 2014.

  1. #1
    macstux, Aug 21, 2014 IP
  2. ajayr

    ajayr Active Member

    Messages:
    322
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #2
    It appears that your mysql_query() is failing. Try to debug by printing mysql_error()
     
    ajayr, Aug 22, 2014 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    First, get rid of mysql_ - it's a deprecated DB-handler, you should be using mysqli_ or PDO instead.
    Second, why are you pasting links to images of the code? Just put the code in CODE-tags and post it here, in the thread. Or use something like pastebin or jsfiddle or whatever, so we can edit the code, copy it etc.
     
    PoPSiCLe, Aug 22, 2014 IP
  4. hangbowl

    hangbowl Well-Known Member

    Messages:
    228
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    143
    Digital Goods:
    2
    #4
    as ajayr said, add mysql_error() at the line.

    $query = mysql_query(...) or die(mysql_error());
    PHP:
    and let us know how does the error. so we can find the solutions.
     
    hangbowl, Aug 22, 2014 IP
    ThePHPMaster likes this.
  5. macstux

    macstux Well-Known Member

    Messages:
    336
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    155
    #5
    macstux, Aug 24, 2014 IP
  6. macstux

    macstux Well-Known Member

    Messages:
    336
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    155
    #6
    I tried and replaced it with
    $query = mysql_query("SELECT * FROM code ORDER BY id DESC LIMIT 8");
    PHP:
    but i got another error.
     
    macstux, Aug 25, 2014 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Try replacing mysql_fetch_array with mysql_fetch, and add a return for eventual mysql_errors - and, as stated earlier, stop using mysql_ - it's deprecated and horrid, and you should be using mysqli_ or PDO and proper, prepared queries
     
    PoPSiCLe, Aug 25, 2014 IP
  8. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #8
    Listen to @PoPSiCLe about not using mysql_query but first lets get the basics of your sql organised.

    You're a newbie to all this, right? You have access to phpMyAdmin hopefully. If you run the query in phpMyAdmin what happens?

    You seemed to totally ignore the advice given about mysql_error(). If I have a query that I'm debugging, maybe I'm not sure if I'm building the sql right, or if the values are looking as I expect I'll have code that looks something like this (not that I send queries straight to the database anymore, thank you cakePHP and WP for handling all that for me)

    $where = array();
    if ($rule1) $where[] = " `field1` = '{$val1}' ";
    if ($rule2) $where[] = " `field2` = '{$val2}' ";
    
    $sql = "SELECT `name`, `field3`, `field4` from table1 where status = '1' " .implode(' AND ', $where)." order by `name` limit 8";
    $result = mysql_query($sql) or die('Error: '.mysql_error().'<br />'.$sql);
    PHP:
    that way I can see what my query looks like, I can see why the query failed. I can even copy my query into phpMyAdmin and test it there.

    If you get heavily into all of this I recommend getting a decent mysql gui - I like sqlyog but there are free versions around that are probably just as good.
     
    sarahk, Aug 25, 2014 IP
  9. hangbowl

    hangbowl Well-Known Member

    Messages:
    228
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    143
    Digital Goods:
    2
    #9
    please add the command
    or die(mysql_error());
    Code (markup):
    and show us the error message.

    the or die is a php function. it's not an options.
     
    hangbowl, Aug 25, 2014 IP
  10. macstux

    macstux Well-Known Member

    Messages:
    336
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    155
    #10
    Yes I am a noob to all of this so its a little confusing at first. Hopefully i am not ripping your guys hair off, just trying to get this site back and running properly.
    Now I added die (mysql_error()); like this
    
    <?php
    $query = mysql_query(...) or die(mysql_error());
    while($r = mysql_fetch_array($query)) {
    $id = $r['id'];
    $user = format($r['user']);
    $posted = timeDiff($r['added']);
    echo '<p><a href="'.$id.'">'.$user.'</a><br /><span class="posted">'.$posted.'</span></p>';
    }
    ?>
    
    PHP:
    Is this how you were trying to tell me to add or die(mysql_error());

    if so i got a white screen shows up and this is written on it.
    Parse error: syntax error, unexpected '.', expecting ')' in /hermes/bosweb26a/b1807/ipg.stmcevoy/Yourcss/pastecode.php on line 7

    Sorry if im making this more confusing then it has to be. I am a noob here trying to learn as i go.
     
    macstux, Aug 25, 2014 IP
  11. hangbowl

    hangbowl Well-Known Member

    Messages:
    228
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    143
    Digital Goods:
    2
    #11
    use this.

    <?php
    $query = mysql_query("SELECT * FROM `code` ORDER BY `id` DESC LIMIT 8") or die(mysql_error());
    while($r = mysql_fetch_array($query)) {
    $id = $r['id'];
    $user = format($r['user']);
    $posted = timeDiff($r['added']);
    echo '<p><a href="'.$id.'">'.$user.'</a><br /><span class="posted">'.$posted.'</span></p>';
    }
    ?>
    PHP:
     
    hangbowl, Aug 25, 2014 IP
  12. macstux

    macstux Well-Known Member

    Messages:
    336
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    155
    #12
    hmm now i get an error saying "Table 'yourcss.code' doesn't exist" Is a file or something missing?
     
    macstux, Aug 26, 2014 IP
  13. Helge Sverre

    Helge Sverre Prominent Member Affiliate Manager

    Messages:
    840
    Likes Received:
    99
    Best Answers:
    2
    Trophy Points:
    305
    Digital Goods:
    2
    #13
    That tells you that the table "code" in the database "yourcss"(If im not mistaken...) does not exist.
     
    Helge Sverre, Aug 26, 2014 IP
  14. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #14
    Good gravy there's some terrifyingly bad code here... most of it reeking of pre-2006 and a significant portion having the air of "welcome to 1997" hanging about it. Those pictures tell the story of having learned how NOT to build a website; from the presence of CENTER and ALIGN, to the use of H4 when I REALLY doubt you have H2 or H3 preceeding them (given the layout screencap), paragraphs around obviously non-paragraph content -- and of course what you've been told several times to stop doing, the stupid malfing mysql_ functions despite our being told to stop using them since PHP 5 dropped (good for a laugh since 5.3 is now EoL) and their having added giant red warning boxes to the manual two or three years ago waving us off.

    I would suggest tossing this entire mess and taking the time to learn to use HTML and PHP properly before tackling anything like this; as I would be throwing it all away and starting over just to try and fix your bugs as there's little if anything there in terms of markup or back-end code I'd even try to salvage from this.

    Sorry if that sounds harsh, but the truth often is.
     
    deathshadow, Aug 27, 2014 IP
  15. macstux

    macstux Well-Known Member

    Messages:
    336
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    155
    #15
    Well I didn't code, it I bought it and was trying to learn off of it but I guess I'm in another whole... Thanks for the help guys and I guess il just trash this and start over...
     
    macstux, Aug 27, 2014 IP