Problem in Fetching Table contents when adding rows in same table

Im trying to write a function for adding category:

function addCategory() {
$cname   = mysql_fix_string($_POST['cname']);
$kabst   = mysql_fix_string($_POST['kabst']);
$kselect = $_POST['kselect'];
$kradio  = $_POST['kradio'];
$ksubmit = $_POST['ksubmit'];
$id         = $_POST['id'];
if($ksubmit){
  $query = "INSERT INTO category  VALUES (' ', '{$cname}', '{$kabst}', {$kselect},    {$kradio}, ' ') "; 
  $result = mysql_query($query);
  if ($result) {
    echo "ok";
  }
  else{
   echo $query ;
 }
}
 $text .= '<div class="form">
        <h2>ADD new category</h2>
         <form action="?page=addCategory" method="post">
             <ul>
                 <li><label>Category</label></li>
                 <li><input name="cname" type="text" class="inp" /></li>
                 <li><label>Description</label></li>
                 <li><textarea name="kabst" cols="40" rows="10" class="inx"></textarea></li>
                 <li>Published:</li>
                 <li>
                   <select name="kselect"  class="ins">
                     <option value="1">Active</option>
                     <option value="0">Passive</option>

                   </select>
                 </li>
                     <li>Show in home page:</li> 
                     <li>
                      <input type="radio" name="kradio" value="1" /> yes
                      <input type="radio" name="kradio" value="0" /> no
                     </li>
                 <li>Subcategory of</li>
                 <li>
                  <select>';
                    while ($row = mysql_fetch_assoc(mysql_query("SELECT * FROM category"))){
                    $text .= '<option>'.$row['name'].'</option>';
                    }
                    $text .= '</select>
                    </li>
                    <li><input name="ksubmit" type="submit"  value="ekle" class="int"/></li>
                </ul>
            </form>
';

return $text;}

And the error:

Fatal error: Maximum execution time of 30 seconds exceeded

What is wrong in my function?

Answers


You keep on re-executing the query and fetching the first row, creating an infinite loop (and ∞ seconds > 30 seconds). Try this:

$result = mysql_query("SELECT * FROM category");
while ($row = mysql_fetch_assoc($result)){

Need Your Help

VBA Excel 2010 ComboBox and Select Case

vba excel-vba excel-2010 excel

Sorry to hassle you, I have been reading and searching through Google but cant find my answer...

webmatrix and php directing to another page

php mysql

I have a simple application that I would like to read data from mysql. My index page include simple form to send data to server to process , especially to match data against database.