Jump to content

Form not submitting information to the database, but displays it fine


chrislukehowell

Recommended Posts

First of all i'd just like to mention that the captchas on this website are so hard to read it took me ages to register!

Anyway...

 

I recently made a content management system, or tried to, using some tutorials i found, and everything worked perfectly really, I could submit new posts, they'd go to the database then appear on my index page, but since coming back to it and reopening it it just won't submit the posts anymore. I am very new to php so it could be a really simple error and im just overlooking something but I cant figure it out.

 

The Add content script it...

 

<?php

// connect to MySQL database here

require_once "connect_to_mysql.php";

// Requiring date from forms on admin page

 

$title = $_POST['title'];

$body = $_POST['body'];

 

// Build the sql command string

$sqlCommand = "INSERT INTO cms_content (id, title, body)

VALUES('$id','$title','$body')";

// Execute the query here now

$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());

// Attain the auto-incremented id field automatically if needed here

$id = mysqli_insert_id($myConnection);

// Echo output showing success and new user ID number

echo "Posted Succesfully!";

// close mysql connection

mysqli_close($myConnection);

?>

 

I've got no idea where ive gone wrong really to be honest. Would be grateful if anyone can help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.