PHP error problem.

Posted by TaG on Stack Overflow See other posts from Stack Overflow or by TaG
Published on 2010-04-08T14:18:05Z Indexed on 2010/04/08 14:23 UTC
Read the original article Hit count: 311

Filed under:
|

I get the following error on line 8: Undefined index: real_name which is $privacy_policy = mysqli_real_escape_string($mysqli, $_POST['privacy_policy']); I was wondering how can I fix this problem?

Here is the PHP.

if (isset($_POST['submitted'])) {

$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT users.*
                             FROM users 
                             WHERE user_id=3");

$privacy_policy = mysqli_real_escape_string($mysqli, $_POST['privacy_policy']);

    if (mysqli_num_rows($dbc) == 0) {
            $mysqli = mysqli_connect("localhost", "root", "", "sitename");
            $dbc = mysqli_query($mysqli,"INSERT INTO users (user_id, privacy_policy) 
                                         VALUES ('$user_id', '$privacy_policy')");
    }


    if ($dbc == TRUE) {
            $dbc = mysqli_query($mysqli,"UPDATE users 
                                         SET privacy_policy = '$privacy_policy' 
                                         WHERE user_id = '$user_id'");

            echo '<p class="changes-saved">Your changes have been saved!</p>';

    }


    if (!$dbc) {
            print mysqli_error($mysqli);
            return;
    }

}

Here is the HTML.

<form method="post" action="index.php">
    <fieldset>
        <ul>
            <li><input type="checkbox" name="privacy_policy" id="privacy_policy" value="yes" <?php if (isset($_POST['privacy_policy'])) { echo 'checked="checked"'; } else if($privacy_policy == "yes") { echo 'checked="checked"'; } ?> /></li>

            <li><input type="submit" name="submit" value="Save Changes" class="save-button" />
                <input type="hidden" name="submitted" value="true" />
            <input type="submit" name="submit" value="Preview Changes" class="preview-changes-button" /></li>
            </ul>
    </fieldset>
</form>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql