spliting my hair out on this weird php problem

Discussion in 'PHP' started by technojuice, Dec 11, 2008.

  1. #1
    All i want to do is create something like a phpmyadmin in which the table can be edited.

    
    $q = mysql_query("SELECT * FROM `".$db_table_site."`") or mysql_error();
    
    $n = 0;
    while($row = mysql_fetch_assoc($q)){
      $key = $row['key'];
      $site = trim($row['site']);
      $delkey = $row['key'];
    echo '<tr>';
      echo'<td width="10%" valign="bottom" align="center"><form name="frmdel" method="POST" action="'.$_SERVER['PHP_SELF'].'?page=site"><input name="delkey" type="hidden" value="'.$row['key'].'"><input name="delsite" type="hidden" value="'.$row['site'].'"><input type="image" src="admin/del.png" align="middle"></form></td>';
      echo'<td width="90%">'.$n.'<form name="edit" method="POST" action="'.$_SERVER['PHP_SELF'].'?page=site"><input name="editkey" type="hidden" value="'.$row['key'].'"><input type="text" name="site" value="'.$row['site'].'" size="40"> <input name="edit" type="submit" value="Edit"></form></td>';
      echo'</tr>';
    
    PHP:
    For this simple code I am getting a weird range of problems... the while loop stops half way without any error message.

    The table is not properly displayed and also get strange characters such as ðXT€ðXT€����d in output !

    Any solutions ?
     
    technojuice, Dec 11, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    What's the character encoding of the database table? Also what data type are the columns that are outputing like this?
     
    jestep, Dec 11, 2008 IP
  3. brownskinman

    brownskinman Peon

    Messages:
    18
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    aside from the DB stuffs ( after you've fixed the character encoding issues as what jestep said ), you might also want to try

    <?php
    header('Content-Type: text/html; charset=utf-8');
    ?>
    PHP:
    for your page to properly display those *nasty* characters.
     
    brownskinman, Dec 11, 2008 IP
  4. technojuice

    technojuice Peon

    Messages:
    207
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    there are no special character only plain english.. site url.

    The while($row = mysql_fetch_assoc($q)) stops midway. Is there any bugs with this method ? total number of record is just 300+

    the records are properly show if i don't echo forms !
     
    technojuice, Dec 11, 2008 IP
  5. brownskinman

    brownskinman Peon

    Messages:
    18
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Maybe you can post your ( whole ) code at http://pastie.org/ then let's see what we can do.
     
    brownskinman, Dec 11, 2008 IP
  6. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    All I can see from a quick glance that the loop isn't closed and maybe its exiting the script due to memory issues. Try...

    
    $q = mysql_query("SELECT * FROM `".$db_table_site."`") or mysql_error();
    
    $n = 0;
    while($row = mysql_fetch_assoc($q)){
      $key = $row['key'];
      $site = trim($row['site']);
      $delkey = $row['key'];
    echo '<tr>';
      echo'<td width="10%" valign="bottom" align="center"><form name="frmdel" method="POST" action="'.$_SERVER['PHP_SELF'].'?page=site"><input name="delkey" type="hidden" value="'.$row['key'].'"><input name="delsite" type="hidden" value="'.$row['site'].'"><input type="image" src="admin/del.png" align="middle"></form></td>';
      echo'<td width="90%">'.$n.'<form name="edit" method="POST" action="'.$_SERVER['PHP_SELF'].'?page=site"><input name="editkey" type="hidden" value="'.$row['key'].'"><input type="text" name="site" value="'.$row['site'].'" size="40"> <input name="edit" type="submit" value="Edit"></form></td>';
      echo'</tr>';
    } // This wasnt there
    
    Code (markup):
    Also, what's the n=0 for? I don't see it being incremented anywhere in that script so $n will always equal 0.
     
    xxKillswitch, Dec 11, 2008 IP
  7. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #7
    You do mean that you want to edit the contents of the tables? Not the tables or structure.

    Do you need to see all 300 records at the same time?

    Are you trying to run this on localhost or on a shared server?

    I can post a routine that will allow you to edit a single item for multiple fields.

    I'm not real experienced but I think you are timing out or do not have the query structured correctly.
     
    Colbyt, Dec 11, 2008 IP
  8. technojuice

    technojuice Peon

    Messages:
    207
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks for the kind replies !

    Here is full code that iam using
    
    <?php
    $q = mysql_query("SELECT * FROM `".$db_table_site."`") or mysql_error();
    
    $n = 1;
    while($row = mysql_fetch_assoc($q)){
      $key = $row['key'];
      $site = trim($row['site']);
      $delkey = $row['key'];
    echo '<tr>';
    echo '<td>'.$n.'</td>';
      echo '<td><a href="'.$_SERVER['PHP_SELF'].'?page=site&delkey='.$key.'&delsite='.$site.'"><img border="0" src="admin/del.png"></a></td>';
      echo'<td><input name="editkey" type="hidden" value="'.$key.'">'.$site.'<a href="'.$_SERVER['PHP_SELF'].'?page=editsite&key='.$key.'"><img border="0" src="admin/edit.png"></a></td>';
      echo'</tr>'."\n";
      $n++;
    }
    ?>
    PHP:
    There weird error still there in my localhost but is not there in a hosting server, could a memory or a timeout issue !

    When I run the loop without the form or the table there error is not there !
     
    technojuice, Dec 13, 2008 IP
  9. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #9
    Whats the actual error?

    Change "or mysql_error()" to "die(mysql_error())" or echo it so we can see if there any problems there.
     
    chopsticks, Dec 13, 2008 IP