Jump to content

Steve_Berry

New Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Steve_Berry

  • Rank
    Newbie
  1. Steve_Berry

    Undefined offset & error in your SQL syntax

    Thanks for the help. The advice helped. I am following a tutorial that has caused issues. However, as I am new to PHP and/or PDO I am sticking with the PHP tutorial. That wy, some day I can figure out how to use PHP without tutorials. Once, again, thanks.
  2. What I am trying to do is to associate a user (id) to a page they create, so if joe blogs is user 4, then the data base will show the page details, and add the id (from a user page). However, when I try the code to save data I get the following error messages: Notice: Undefined offset: 4 in C:\xampp\htdocs\MyCMS\admin\index.php on line 98 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' 'Thom\'s page', 'testing Tom', 'Tom')' at line 1 I include the code to insert the page: <!-- Insert Page --> <?php if(isset($_POST['submitted']) == 1) { $header = stripslashes($_REQUEST['header']); $header = mysqli_real_escape_string($dbc, $header); $title = stripslashes($_REQUEST['title']); $title = mysqli_real_escape_string($dbc, $title); $body = stripslashes($_REQUEST['body']); $body = mysqli_real_escape_string($dbc, $body); $userid = stripslashes($_REQUEST['userid']); $userid = mysqli_real_escape_string($dbc, $userid); $q = "INSERT INTO `pages` (`userid`, `header`, `title`, `body`) VALUES ($_POST[$userid], '$header', '$title', '$body')"; $r = mysqli_query($dbc, $q) or die(mysqli_error($dbc)); if($r) { $message = '<p>Page was added.</p>'; } else { $message = '<p>Page could not be added due to: </p>'.mysqli_error($dbc); $message .= '<p>'.$q.'</p>'; } // end if inner } // end if outer ?> The form has - Page Header, Page Title, User, and boys. There is a working list of current users. It is these users (and new users) that I want to add to a 'Pages' database, which has the following fields: id, userid, header, title, body; and a 'User' database with the following fields: id, firstname, lastname, username, password, status. Any help to solve the issues will be appreciated. Thanks.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.