Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/52308-regarding-insert-using-phpmssql/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.