Jump to content

Insert error


Kev0121

Recommended Posts

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

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

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.