jd2007 Posted July 10, 2007 Share Posted July 10, 2007 how to insert user input into a mysql table through php? for example input 'name' into column name and input 'comments' into column 'comments' ... Quote Link to comment Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 <?php // connect to db. if (isset($_POST['name']) && isset($_POST['comments'])) { if (!get_magic_quotes_gpc()) { $name = mysql_real_escape_string($_POST['name']); $comments = mysql_real_escape_string($_POST['comments']); } else { $name = $_POST['name']; $comments = $_POST['comments']; } $sql = "INSERT INTO tbl (name,comments) VALUES ('$name','$comments')"; if (mysql_query($sql)) { echo "insert successfull"; } else { echo "query failed<br />$sql<br />" . mysql_error(); } } ?> Quote Link to comment 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.