Little help with error

Discussion in 'PHP' started by Kurt Whittingham, Feb 29, 2012.

  1. #1
    Hello im new to php, and i am following a video on youtube about creating a blog for my website.. i got this error on the "add category" page

    Parse error: syntax error, unexpected '=' in /home/motorbik/public_html/1/add_category.php on line 8

    this is the code

    <?php
    include_once('init.php');
    
    if ( isset($_POST['name']) ){
        $name = trim($_POST['name']);
        
        if ( empty($name) ){
            error = 'You Must Submit A Category Name.';
        } else if ( category_exists($name) ){
            error = 'That Category Already Exists.';
        } else if ( strlen($name) > 24 ){
            error = 'Category Name To Long.';
        }
        
        if ( ! isset($error) ){
            add_category($name);
        }
    }
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    
       "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
       
       <html>
       <body>
       
       <table>
       <tr>
       <td>
       <h1>Add Category</h1>
       </td>
       </tr>
       <tr>
       <td>
            <form action="" method="post">
                <div>
                    <label for="name"> Name </lable>
                    <input type="text" name="name" value="">
        </td>
        </tr>
        <tr>
        <td>
                    <input type="submit" value="Add Category">
        </td>
        </tr>
        </table>
        </form>
                
    </body>
    </html>
    PHP:
     
    Kurt Whittingham, Feb 29, 2012 IP
  2. trendint

    trendint Peon

    Messages:
    52
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The error message is pretty accurate in getting you to the resolution of the problem;

    On line 8 (as well as lines 10 and 12) you are attempting to set a value to "error". You can not use plain text strings in the place of variables, these should be "$error" in all three instances.
     
    trendint, Feb 29, 2012 IP