SamohtVII Posted March 22, 2013 Share Posted March 22, 2013 I have a form posting 3 things, title, user, and content and it only ends up inserting the content and date parts into the table.insert.php: <?php$con=mysql_connect('localhost','root','*******');// Check connectionif (!$con) { echo "Failed to connect to MySQL: " . mysql_error(); }mysql_select_db("tutorials_blog2", $con);$sql="INSERT INTO posts (username, title, content, date)VALUES('$_POST[Username]','$_POST[Title]','$_POST[Content]', UNIX_TIMESTAMP())";if (!mysql_query($sql, $con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con);?> This is the only place i can see anything being wrong but i'm not sure what's the problem. maybe my form? <form action="insert.php" method="post">Username: <input type="text" name"Username">Title: <input type="text" name"Title" size="30">Content: <input type="text" name="Content" class="inputtext"><input type="submit"> Please help. ty Link to comment Share on other sites More sharing options...
fikiwan Posted March 22, 2013 Share Posted March 22, 2013 (edited) <form action="insert.php" method="post">Username: <input type="text" name"Username" />Title: <input type="text" name"Title" size="30" />Content: <input type="text" name="Content" class="inputtext" /><input type="submit" /></form> <!--Add this u forget close tag --> Edited March 22, 2013 by fikiwan Link to comment Share on other sites More sharing options...
SamohtVII Posted March 22, 2013 Author Share Posted March 22, 2013 Thanks for the correction but my problem still happens . Any other suggestions? Link to comment Share on other sites More sharing options...
Nico Posted March 22, 2013 Share Posted March 22, 2013 (edited) You're missing equal signs in your form: name"Username" But for the love of God, stop using the mysql_* functions. They're old, deprecated, slow, ugly, and oh yeah... insecure as ######. With your code right now, I promise you you'll get hacked. Use PDO instead. You won't regret it. <?php$dsn = 'mysql:dbname=tutorials_blog2;host=127.0.0.1';$user = 'root';$password = '';$db = new PDO($dsn, $user, $password);$stmt = $db->prepare(" INSERT INTO posts (username, title, content, date) VALUES (?, ?, ?, UNIX_TIMESTAMP())");$result = $stmt->execute([$_POST['Username'], $_POST['Title'], $_POST['Content']]);if ($result){ echo '1 record added';}?> It looks complicated at first sight, but trust me, it's worth it.Read more here:http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developersphp.net/pdo Edited March 22, 2013 by Nico Link to comment Share on other sites More sharing options...
SamohtVII Posted March 23, 2013 Author Share Posted March 23, 2013 Thanks mate. Can't believe I missed such an easy mistake. Works fine now... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now