R4nk3d Posted October 22, 2008 Share Posted October 22, 2008 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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/129579-solved-php-mysql-wont-insert-new-page/ Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 The sql query wont work correctly What exactly to you mean? What happens, are there errors? Quote Link to comment https://forums.phpfreaks.com/topic/129579-solved-php-mysql-wont-insert-new-page/#findComment-671760 Share on other sites More sharing options...
R4nk3d Posted October 22, 2008 Author Share Posted October 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129579-solved-php-mysql-wont-insert-new-page/#findComment-671765 Share on other sites More sharing options...
R4nk3d Posted October 22, 2008 Author Share Posted October 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129579-solved-php-mysql-wont-insert-new-page/#findComment-671784 Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 Change this line: $result = mysql_query($sql,$connection) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/129579-solved-php-mysql-wont-insert-new-page/#findComment-671786 Share on other sites More sharing options...
R4nk3d Posted October 22, 2008 Author Share Posted October 22, 2008 Change this line: $result = mysql_query($sql,$connection) or die(mysql_error()); Nvm, some how the auto increment got turned off. Sorry for wastin ur time but thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/129579-solved-php-mysql-wont-insert-new-page/#findComment-671799 Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 No worries Quote Link to comment https://forums.phpfreaks.com/topic/129579-solved-php-mysql-wont-insert-new-page/#findComment-671808 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.