SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why is my mySQL database doing this?

    I have this website where people are signing a petition. Anyways, I have over 3500 records on my table but the page, you'll realize once you visit it, loads in a weird way. It never finishes loading, it looks like it keeps on and on loading. Some people have sent me an email saying that it crashes their browsers, and its killing my bandwidth too. So do you know what it could be? Many thanks.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    looks like it's stuck in some kinda loop

    wish we could help, but we can't see any code
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    looks like it's stuck in some kinda loop

    wish we could help, but we can't see any code
    Thanks as usual Rudy, here's the code:

    PHP Code:
    <?php
    // Just a function to escape quotes if magic_quotes is disabled
            
    function post_addslashes($name)
            {
                    if (
    get_magic_quotes_gpc())
                    {
                            return(
    $_POST[$name]);
                    }
                    else
                    {
                            return(
    addslashes($_POST[$name]));
                    }
            }
     
    // Database connection, replace username and password with your own, as well as the database name
            
    $conn mysql_connect("localhost""username""password") or die(mysql_error());
            
    mysql_select_db("tablename"$conn) or die(mysql_error());
            if(isset(
    $_POST['submit']))
            {
                    if(empty(
    $_POST['first']) || empty($_POST['last']))
                    {
                            echo 
    "Ad ve soyad girilmesi zorunludur.";
                    }
                    else
                    {
    // Sets Post_vars, so you can insert into your database using variables instead of their full name
                            
    $first   post_addslashes('first');
                            
    $last     post_addslashes('last');
                            
    $email   post_addslashes('email');
                            
    $relation       post_addslashes('relation');
    // If the submit button is pressed, insert the values into the database
                            
    $query0                 "INSERT INTO people (first, last, email, relation) VALUES ('$first', '$last', '$email', '$relation')";
                            
    mysql_query($query0);
                    }
    }
    ?>
    <!-- Just a form to submit these new name entries -->
                    <form action="" name="new_entry" method="post">
                            <p align="center">
                                    <b><font color="red" size="10" face="Verdana">Bilal Erdoğan Askere!</font></b>
                            </p>
                            <p>
                            </p>
                            <p align="center">
                                    <b><font size="2" face="Verdana">Biz, asagida imzasi bulunanlar, Lubnan'a gidecek askeri birlikte bu karara onculuk eden Basbakan Recep Tayyip Erdogan'in oglu Bilal Erdogan'in da yer almasini talep ederiz.</font></b>
                            </p>
                            <p></p>
                            <p align="center">
                                    <b><font size="2" face="Verdana">Turkiye Cumhuriyeti Halki</font></b>
                            </p>
                            <table width="17%" border="0" align="center">
                                    <tr>
                                            <td width="20%">
                                                    <div align="left">
                                                            <strong>Ad:<font color="red">*</font></strong>
                                                    </div>
                                            </td>
                                            <td width="80%">
                                                    <div align="center">
                                                            <strong><input name="first" type="text" size="30" maxlength="30" /></strong>
                                                    </div>
                                            </td>
                                    </tr>
                                    <tr>
                                            <td>
                                                    <div align="left">
                                                            <strong>Soyad:<font color="red">*</font></strong>
                                                    </div>
                                            </td>
                                            <td>
                                                    <div align="center"><strong><input name="last" type="text" size="30" maxlength="30" /></strong></div>
                                            </td>
                                    </tr>
                                    <tr>
                                            <td>
                                                    <div align="left">
                                                            <strong>Email:</strong>
                                                    </div>
                                            </td>
                                            <td>
                                                    <div align="center">
                                                            <strong><input name="email" type="text" size="30" maxlength="30" /></strong>
                                                    </div>
                                            </td>
                                    </tr>
                                    <tr>
                                            <td>
                                                    <div align="left">
                                                            <strong>Şehir:</strong>
                                                    </div>
                                            </td>
                                            <td>
                                                    <div align="center">
                                                            <strong><input name="relation" type="text" size="30" maxlength="30" /></strong>
                                                    </div>
                                            </td>
                                    </tr>
                                            <td>
                                            </td>
                                            <td>
                                                    <div align="center">
                                                            <input type="submit" name="submit" value="Imzala" />
                                                    </div>
                                                    <p>
                                                            <b>*</b><font size="1" face="Verdana">Ad ve soyad girilmesi zorunludur.</font>
                                                    </p>
                                                    <p align="center"><a href="mailto:beacom1@gmail.com">Organizator</a>
                                                    </p>
                                            </td>
                                    </tr>
                            </table>
                    </form>
                    <p></p>
                    <p></p>
                    <div align="center" style="width: 23%; float:left;"><u><b>Ad</b></u></div>
                    <div align="center" style="width: 23%; float:left;"><u><b>Soyad</b></u></div>
                    <div align="center" style="width: 23%; float:left;"><u><b>Email</b></u></div>
                    <div align="center" style="width: 23%; float:left;"><u><b>Şehir</b></u></div><br />
    <?php
                    $query1 
    mysql_query("SELECT * FROM people");
                    while((
    $oNames mysql_fetch_assoc($query1)) !== false)
                    {
    ?>
    <!-- Display the information -->
                            <p>
                                    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['first'];?></div>
                                    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['last'];?></div>
                                    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['email'];?></div>
                                    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['relation'];?></div><br />
                            </p>
    <?php
                    
    }
    ?>

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    moving to php forum
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I wasn't sure whether the problem was mySQL or PHP related.

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing jumped out of the code at me (quick look only), but could it be that 3500 paragraphs of user data is just taking too long, and browsers are timing out?
    There would be over 1mb of HTML rendered.

    Why not implement some simple pagination using the MySQL LIMIT clause:
    page1 - LIMIT 0,100
    page2 - LIMIT 100,100
    page3 - LIMIT 200,100
    etc.

    Also, I highly recommend you use a little CSS on your DIVs.
    Code:
     /* CSS */
     .sig {text-align: center; width: 23%; float: left;}
     
     /* HTML Output */
     <div class='sig'><?php echo $oNames['first'];?></div>
    That'll reduce the size of your HTML output by 478.5kb when the full 3500 signatures are displayed!

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah i agree with cranial-bore. i think its just too much data, limit how much you will output per page.

    personally, i would use an html table to mark this up as well. afterall, it is tabular data

  8. #8
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cranial-bore
    Nothing jumped out of the code at me (quick look only), but could it be that 3500 paragraphs of user data is just taking too long, and browsers are timing out?
    There would be over 1mb of HTML rendered.

    Why not implement some simple pagination using the MySQL LIMIT clause:
    page1 - LIMIT 0,100
    page2 - LIMIT 100,100
    page3 - LIMIT 200,100
    etc.

    Also, I highly recommend you use a little CSS on your DIVs.
    Code:
    /* CSS */
    .sig {text-align: center; width: 23%; float: left;}
     
    /* HTML Output */
    <div class='sig'><?php echo $oNames['first'];?></div>
    That'll reduce the size of your HTML output by 478.5kb when the full 3500 signatures are displayed!
    Hmmm... too new to PHP/mySQL to do anything like that... maybe I can get the CSS thing working to reduce the size of the page but I am pretty new on HTML too. I had someone do it for me in 10 minutes but he is gone on vacation now... What does the ".sig" mean in the CSS line you posted above? will i need to change anything on it for each of the columns? thanks

  9. #9
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by clamcrusher
    yeah i agree with cranial-bore. i think its just too much data, limit how much you will output per page.

    personally, i would use an html table to mark this up as well. afterall, it is tabular data
    I am a little confused, is my table not HTML?

  10. #10
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Here's a simple paging system for your script:
    PHP Code:
    <?php
    $start
    =(int)$_GET['start'];
    $r=mysql_query("SELECT COUNT(*) AS c FROM people");
    $count=mysql_result($r,0,"c");
    $query1 mysql_query("SELECT * FROM people LIMIT ".($start*100).", 100");
    while(
    $oNames mysql_fetch_assoc($query1))
    {
    ?>
    <!-- Display the information -->
                            <p>
                                    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['first'];?></div>
                                    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['last'];?></div>
                                    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['email'];?></div>
                                    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['relation'];?></div><br />
                            </p>
    <?php
    }

    $n=ceil($count/100);
    for(
    $i=0$i<$n$i++) {
      if(
    $i!=$start)echo "<a href=\"".$_SERVER['PHP_SELF']."?start=$i\">page ".($i+1)."</a> ";
      else echo 
    "<b>page ".($i+1)."</b> ";
    }
    ?>
    Saul

  11. #11
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon
    Here's a simple paging system for your script:
    PHP Code:
    <?php
    $start
    =(int)$_GET['start'];
    $r=mysql_query("SELECT COUNT(*) AS c FROM people");
    $count=mysql_result($r,0,"c");
    $query1 mysql_query("SELECT * FROM people LIMIT ".($start*100).", 100");
    while(
    $oNames mysql_fetch_assoc($query1))
    {
    ?>
    <!-- Display the information -->
    <p>
    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['first'];?></div>
    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['last'];?></div>
    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['email'];?></div>
    <div align="center" style="width: 23%; float:left;"><?php echo $oNames['relation'];?></div><br />
    </p>
    <?php
    }
     
    $n=ceil($count/100);
    for(
    $i=0$i<$n$i++) {
    if(
    $i!=$start)echo "<a href=\"".$_SERVER['PHP_SELF']."?start=$i\">page ".($i+1)."</a> ";
    else echo 
    "<b>page ".($i+1)."</b> ";
    }
    ?>
    Thanks so much, I tested it and its great. I appreciate this.

    http://www.bilalerdoganaskere.com/test/index.php

    2 questions though:

    1. When I fill the form and submit it, and go to the last page, its not on there?

    2. Is there a way to make it so at the bottom it will say "Page: 1 2 3 4 5 6 7 ..." instead of "Page 1 Page 2 Page 3 Page 4..." ?


  12. #12
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    1. Hm, it really doesn't add. Did the original script add new records?
    2. Yes,
      PHP Code:
      echo "Pages: ";
      if(
      $i!=$start)echo "<a href=\"".$_SERVER['PHP_SELF']."?start=$i\">".($i+1)."</a> ";
      else echo 
      "<b>".($i+1)."</b> "
    Saul

  13. #13
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon
    1. Hm, it really doesn't add. Did the original script add new records?
    2. Yes,
      PHP Code:
      echo "Pages: ";
      if(
      $i!=$start)echo "<a href=\"".$_SERVER['PHP_SELF']."?start=$i\">".($i+1)."</a> ";
      else echo 
      "<b>".($i+1)."</b> "
    1. Yeah, I didn't add 3000+ records myself manually :P
    2. Thanks, where do i put "<center></center>" so it aligns at the center of the page?

  14. #14
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can you check in phpmyadmin if it adds it? It may be that it just doesn't show.
    Saul

  15. #15
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured out how to center it! YAY!


  16. #16
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon
    Can you check in phpmyadmin if it adds it? It may be that it just doesn't show.
    Checked in PHPmyadmin and apparently it adds them to the table, but for some reason it doesn't add it as the last row on the table, it just gets added somewhere in the middle I guess? Didn't have this problem with the original page... odd?

  17. #17
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And there is something wrong with page 35? :confused;

  18. #18
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Could be. Sort the rows by id if there's one.

    What's wrong with page 35?
    Saul

  19. #19
    SitePoint Enthusiast Basar's Avatar
    Join Date
    Sep 2004
    Location
    Washington DC
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon
    Could be. Sort the rows by id if there's one.

    What's wrong with page 35?
    If you go to page 35: http://www.bilalerdoganaskere.com/te...x.php?start=34

    It lists only 3 entries even though its not the last page and it doesn't list the pages underneath..

  20. #20
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Works on FF. But I can see the problem. Here's the fourth record output:
    HTML Code:
    <p> 
    <div align="center" style="width: 23%; float:left;"><script>alert("aq")<</div> 
    <div align="center" style="width: 23%; float:left;"><script>alert("aq")<</div> 
    <div align="center" style="width: 23%; float:left;"></div> 
    <div align="center" style="width: 23%; float:left;"></div><br /> 
    </p> 
    You should disable html code in user input:
    PHP Code:
    $first post_addslashes(html_spacial_chars('first'));
    $last post_addslashes(html_spacial_chars('last'));
    $email post_addslashes(html_spacial_chars('email'));
    $relation post_addslashes(html_spacial_chars('relation')); 
    Saul


Bookmarks

Posting Permissions

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