Jump to content

[SOLVED] PHP MySQL Won't Insert New Page


R4nk3d

Recommended Posts

if($_POST['type'] == "page")
					{
						$name = $_POST['name'];
						$body = $_POST['pagebody'];
						$sql = "INSERT INTO links (name,body) VALUES ($name,$body)";
						$result = mysql_query($sql,$connection);
						if(!$result)
						{
							echo "<h1>Creation Unsuccessful</h1>";
							echo "The page could not be created. Please try again later.";
						}
						else
						{
							echo "<h1>Creation Successful</h1>";
							echo "The page <a href=\"$r[location]\" />$r[name]</a> has been successfully created.";
						}
					}

I am developing a small cms system and i am working on the create.php page to create new news articles and pages. I am having a small bit of trouble tho. The sql query wont work correctly. Can anyone help me?

 

Heres the html form of the previous page:

if($_GET['type'] == "page")
				{
					echo "<h1>Create: Page:</h1>";
					echo "Please enter all the facts about the page and then the body of the page.";
					echo "<br>";
					echo "<form action=\"create.php\" method=\"post\" name=\"newpage\"><table width=\"0\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
					echo "<input name=\"submitting\" type=\"hidden\" value=\"1\" /><input name=\"type\" type=\"hidden\" value=\"page\" />";
           				echo "<tr>";
                    	echo "<td>Name Of Page:</td>";
                    	echo "<td><input type=\"text\" name=\"name\" id=\"name\" /></td>";
                  		echo "</tr>";
                  		echo "<tr>";
                    	echo "<td>Page Body:</td>";
                    	echo "<td><textarea name=\"pagebody\" id=\"pagebody\" cols=\"45\" rows=\"5\"></textarea></td>";
                  		echo "</tr>";
                  		echo "<tr>";
                    	echo "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Submit\" /></td>";
                  		echo "</tr>";
                		echo "</table></form>";
				}

Link to comment
https://forums.phpfreaks.com/topic/129579-solved-php-mysql-wont-insert-new-page/
Share on other sites

The sql query wont work correctly

 

What exactly to you mean?  What happens, are there errors?

It says it wasnt created and i look in the database and its not. there arent any errors. It just wont insert it.

 

Dont worry, i have the mysql connection info in the file and thats not the problem.

The sql query wont work correctly

 

What exactly to you mean?  What happens, are there errors?

It says it wasnt created and i look in the database and its not. there arent any errors. It just wont insert it.

 

Dont worry, i have the mysql connection info in the file and thats not the problem.

 

 

Ok, heres the error it gave me:

ErrorDuplicate entry '0' for key 1.

 

Im trying to find a way to count all of the rows in the database, and then set the new page to that id.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.