Kev0121 Posted March 8, 2009 Share Posted March 8, 2009 Isnt inserting anything into my database heres my code <?php include 'connection.php'; ?> <html> <head> <title>Insert Into Blog</title> </head> <body> <form action = "<?php $_SERVER['PHP_SELF']; ?>" method="POST" name="insert"> <table> <tr> <td>Post Title : <input type="text" name="pTitle" /> </td> <tr> <tr> <td>Post Author : <input type="text" name="pAuth" /> </td> <tr> <td>Post Content : <br/> <input type="text" name="pContent"/> </td> <tr> <td><input type="submit" name="Submit" value="Done" /> </td> </table> </form> </body> </html> <?php $title = $_POST['pTitle']; $author = $_POST['pAuth']; $content = $_POST['pContent']; if(isset($_POST['Submit'])) { $insertData = "INSERT INTO `test` (title,author,content) VALUES ('$title', '$author', '$content')"; $query = mysql_query($insertData) or die(mysql_error()); } ?> Link to comment https://forums.phpfreaks.com/topic/148477-insert-error/ Share on other sites More sharing options...
wildteen88 Posted March 8, 2009 Share Posted March 8, 2009 Whats the error(s) you're getting. The things I see you should change is the following <form action = "<?php $_SERVER['PHP_SELF']; ?>" method="POST" name="insert"> Should of been <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="insert"> The following code $title = $_POST['pTitle']; $author = $_POST['pAuth']; $content = $_POST['pContent']; Should be within your if statement (after this line) if(isset($_POST['Submit'])) { Link to comment https://forums.phpfreaks.com/topic/148477-insert-error/#findComment-779636 Share on other sites More sharing options...
kickstart Posted March 8, 2009 Share Posted March 8, 2009 Hi First thing, echo out $insertData and see if it has actually been set. All the best Keith Link to comment https://forums.phpfreaks.com/topic/148477-insert-error/#findComment-779638 Share on other sites More sharing options...
Kev0121 Posted March 8, 2009 Author Share Posted March 8, 2009 Hey, i actually realised the problem was i was on the wrong database on phpmyadmin rofl, but those posts helped thanks alot Kevin Link to comment https://forums.phpfreaks.com/topic/148477-insert-error/#findComment-779646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.