开发者

Problem in Fetching Table contents when adding rows in same table

开发者 https://www.devze.com 2022-12-25 05:06 出处:网络
Im trying to write a function for adding category: function addCategory() { $cname 开发者_C百科= mysql_fix_string($_POST[\'cname\']);

Im trying to write a function for adding category:

function addCategory() {
$cname 开发者_C百科  = 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?


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)){
0

精彩评论

暂无评论...
验证码 换一张
取 消