Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Adding values to insert query [was: Plz help with this code]

New Here ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

I have created a comments section in which there is only one field comment here is the code of the form:

<form id="frmComment" name="frmComment" method="POST" action="<?php echo $editFormAction; ?>">

    <h3>

      <label for="namegd"></label>Comment:</h3>

    <p>

      <label for="comment2"></label>

      <textarea name="comment" id="comment2" cols="60" rows="10" ></textarea>

    </p>

    <p>

      <label for="submit">

      </label>

      <input type="submit" name="submit" id="submit" value="Submit" />

      <label for="reset"></label>

      <input type="reset" name="reset" id="reset" value="Clear" />

    </p>

<input type="hidden" name="MM_insert" value="frmComment" />

</form>

and the insert into code applied to the form is this

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frmComment")) {

  $insertSQL = sprintf("INSERT INTO comments (`comment`, ) VALUES (%s)",

                       GetSQLValueString($_POST['comment'], "text"));


  mysql_select_db($database_my_connection, $my_connection);

  $Result1 = mysql_query($insertSQL, $my_connection) or die(mysql_error());

}

But I want the form to insert two more values to the database one will be the commented_by and the other will be post_id where commented_by = ($_SESSION['Username']) and post_id = $row_Recordset1['id'] can some one plz let me know what will be the modified code and ya commented_by is a text field and post_id is an int field.
Plz guys help me Thanks in advance
TOPICS
Server side applications

Views

1.1K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 21, 2009 Jun 21, 2009

Adding the extra values to the insert query is easy:

$insertSQL = sprintf("INSERT INTO comments (`comment`, commented_by, post_id) VALUES (%s, %s, %s)",
         GetSQLValueString($_POST['comment'], "text"),
         GetSQLValueString($_SESSION['Username'], "text"),
         GetSQLValueString($row_recordset1['id'], "int"));

You need to make sure that the code for recordset1 comes before the insert query. By default, Dreamweaver places recordset code immediately above the DOCTYPE declaration, and belo

...

Votes

Translate
LEGEND ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

Posting three separate threads about the same issue is a sure way to make yourself unpopular in any web forum, particularly when you start using garish colours, bold font, and unhelpful subject lines. I have locked your duplicate threads.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

Sorry for that but I was not sure how to put the whole situation in front of the reader so I tried to explain in different ways in all the different threads and by the way can u help me with this plz sir

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

Adding the extra values to the insert query is easy:

$insertSQL = sprintf("INSERT INTO comments (`comment`, commented_by, post_id) VALUES (%s, %s, %s)",
         GetSQLValueString($_POST['comment'], "text"),
         GetSQLValueString($_SESSION['Username'], "text"),
         GetSQLValueString($row_recordset1['id'], "int"));

You need to make sure that the code for recordset1 comes before the insert query. By default, Dreamweaver places recordset code immediately above the DOCTYPE declaration, and below other server behaviors. So, you need to move the code. Otherwise, this insert query won't work.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

Hey it isn't working the problem is that when ever is use the above code and preview it in the browser I just get a blank page but the address in the address bar is correct

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

If you're getting a blank page, it means there's an error somewhere in the PHP code, but you have display_errors turned off. Change your php.ini to display errors, and restart Apache. Then you should see an error message that helps identify where the problem is.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

well m testing on a server that I plan to host my site on so will it have this option

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

It depends on your hosting company. Some hosting companies let you change the configuration options by giving you access to your own php.ini. Others don't.

One thing you can try is to add the following at the top of the script:

<?php ini_set('display_errors', '1'); ?>

That turns on the display of errors for that particular script. However, it won't work if it's a parse error (missing semicolon, unmatched quote, etc).

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

Well I don't know what the problem was but I just took the backup of my page and inserted the code in it and it works fine now thanks man I can't express how much I owe you

Thanks a lot man

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

LATEST

Glad you got it working.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 21, 2009 Jun 21, 2009

Copy link to clipboard

Copied

Nope not working

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines