hours12 Posted May 21, 2007 Share Posted May 21, 2007 hey , how come my INSERT INTO can't work? .. what could be the possible reasons? Plese help ... thanks <?php if (!empty($_POST["submit"])) { $conn = mssql_connect("172.20.129.172", "SCS WebPortal", "scs"); mssql_select_db("SCS WebPortal", $conn); $sql = "INSERT INTO rejection(reason)VALUES (''); $sql .= "'" . $_POST["textarea"] . "')"; mssql_query($sql, $conn); mssql_close($conn); echo("<p>Entry added to database!</p>"); } ?> <img src="../Unnamed Site 5/top.jpg" alt="top" width="602" height="140"></p> <p class="style1">Reason for rejection has been successfully sent. Thank you </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/52308-regarding-insert-using-phpmssql/ Share on other sites More sharing options...
tedh19 Posted May 27, 2007 Share Posted May 27, 2007 Couple things wrong here: 1. Your first $sql string isn't closed with a quote. 2. Your INSERT SQL query is terminating in the first $sql variable, but you're placing the $_POST result in a second query in the second $sql variable and concatenating it to the first. This effectively gives you two SQL queries in one $sql variable. The second query is failing because of incomplete syntax errors, the first is mostly likely going through and inserting unless you have a NOT NULL constraint on the "reason" data field. $sql = "INSERT INTO rejection(reason)VALUES (''); $sql .= "'" . $_POST["textarea"] . "')"; This is correct: $sql = "INSERT INTO rejection(reason) VALUES ('" . $_POST["textarea"] . "');"; With a SQL query this short you probably don't need to concatenate the $sql string variable. Quote Link to comment https://forums.phpfreaks.com/topic/52308-regarding-insert-using-phpmssql/#findComment-262730 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.