I need help

Discussion in 'PHP' started by m-1o, May 8, 2010.

  1. #1
    hello every body
    i have one error in this code
    i don't know what us the error
    ++ sorry my english is sp bad
    <?php
    $query=mysql_query("SELECT * FROM setting") or die(mysql_error());
    $row=mysql_fetch_object($query);
    $name=$_POST['site_name'];
    $url=$_POST['site_url'];
    $mail=$_POST['site_mail'];
    $desc=$_POST['site_desc'];
    $tags=$_POST['site_tags'];
    $close=$_POST['site_close'];
    $tclose=$_POST['site_tclose'];
    if(isset($_POST['do']) &&$_POST['do']=='save'){
      $up=mysql_query("update setting set
      site_name='$name',
      site_url='$url',
      site_email='$mail',
      site_desc='$desc',
      site_tags='$tags',
      site_close='$close',
      site_tclose='$tclose',
     
      ") or die(mysql_error()); 
      if(isset($up)){
        echo '
        تم بنجاح
        <meta http-equiv="refresh" content="2; url=?cpages=m_setting" />';
      } 
    }
     
    echo "
    <head>
    <link rel='stylesheet' type='text/css' href='styles/admincp.css' />
    </head>
    <div class='head'>اعدادات عامة</div>
    <div class='bodypanel'>
    <form action='?cpages=m_setting' method='post'>
    <table align='center' cellpadding='0' cellspacing='0'>
    <td valign='top' class='rpanel' width='20%'>
     
    <tr>
    <td class='font'>اسم الموقع</td>
    <td><input type='text' name='site_name' value='".$row->site_name."' /></td>
    </tr>
    <tr>
    <td class='font'>رابط الموقع</td>
    <td><input type='text' name='site_url' value='".$row->site_url."' /></td>
    </tr>
    <tr>
    <td class='font'>بريد الموقع</td>
    <td><input type='text' name='site_email' value='".$row->site_email."' /></td>
    </tr>
    <tr>
    <td class='font'>وصف الموقع</td>
    <td><textarea name='site_desc' cols='40' rows='5'>".$row->site_desc."</textarea></td>
    </tr>
    <tr>
    <td class='font'>الكلمات الدليلية</td>
    <td><textarea name='site_tags' cols='40' rows='5'>".$row->site_tags."</textarea></td>
    </tr>
    <tr>
    <td class='font'>حالة الموقع</td>
    <td><select name='site_close'>
    ";
    if ($row->site_close==1){
        echo "<option value='1'>مفتوح للزوار</option>
        <option value='2'>مغلق للزآر</option>";
        
    }
    else{
        echo "<option value='2'>مغلق للزوار</option>
    <option value='1'>مفتوح للزوار</option>";
    }
     
    echo "
    </select>/<td>
    </tr>
    <tr>
    <td class='font'>رسآلة الاغلآق</td>
    <td><textarea name='site_tags' cols='40' rows='5'>".$row->site_tclose."</textarea></td>
    </tr>
    <tr>
    <td><input  class='sub' type='submit' name='ارسل' /></td>
    <input type='hidden' value='do' value='save' />
    </tr>
     
    </table>
    </div>
    </form>";
    ?>
    
    PHP:
    sql
     CREATE TABLE `setting` (
    `site_name` VARCHAR( 250 ) NOT NULL ,
    `site_url` VARCHAR( 250 ) NOT NULL ,
    `site_mail` VARCHAR( 250 ) NOT NULL ,
    `site_desc` TEXT NOT NULL ,
    `site_tags` TEXT NOT NULL ,
    `site_close` VARCHAR( 2 ) NOT NULL ,
    `site_tclose` TEXT NOT NULL
    ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci 
    Code (markup):

     
    m-1o, May 8, 2010 IP
  2. hodbod

    hodbod Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    please state the error you are getting

    thanks

    Chris
     
    hodbod, May 8, 2010 IP
  3. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #3
    It's difficult without seeing the actual error, although this doesn't look well formed:

     
    mfscripts, May 8, 2010 IP
  4. jcwebhole

    jcwebhole Active Member

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    send me more details so i can help you
     
    jcwebhole, May 9, 2010 IP
  5. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #5
    What type of error you're getting??
    In PHP or MYSQL first??
     
    roopajyothi, May 9, 2010 IP
  6. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #6
    remove that last comma:
    site_tclose='$tclose', <--
     
    gapz101, May 11, 2010 IP
  7. musicmasteria

    musicmasteria Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Agreed.

    Also
    if(isset($_POST['do']) &&$_POST['do']=='save')
    The bold part is unnecessary. $_POST['do'] must be set to have a value 'save'

    Another thing
    $query=mysql_query("SELECT * FROM setting") or die(mysql_error());
    $row=mysql_fetch_object($query);
    PHP:
    Should be after the if( $_POST['do'] == 'save' ) { ............ }, just before the echo " <head>... "

    Your logic is out of order so after you post the form you will still see old content until you refresh the page once again.
     
    musicmasteria, May 11, 2010 IP
  8. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #8
    hey, he is doing it correctly, he wants to display it in the form as default values, lol :D
     
    gapz101, May 11, 2010 IP