user1567956
user1567956

Reputation: 131

Inserting data into mysql data base not working

i am inserting data from iphone application to mysql but it is not inserting data into table i echo result and inputed values but it also show no any values

HTML CODE For the page

  <html>


  <head>
  <title>data to server</title>
  </head>
  <body>
  <form action="surveyAnswer.php" method="post" enctype="multipart/form-data"><br>

  <INPUT TYPE = "Text" VALUE ="1" NAME = "survey_question_response_id">

  <INPUT TYPE = "Text" VALUE ="1" NAME = "survey_id">
  <INPUT TYPE = "Text" VALUE ="1" NAME = "question_id">
  <INPUT TYPE = "Text" VALUE ="1" NAME = "survey_response_answer_id">
   <input type="submit" value="Upload File">
  </form>
  </body>
  </html>



     <?php
     $host = ""; 
     $user = ""; 
     $pass = ""; 
     $database = ""; 

     $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
     mysql_select_db($database, $linkID) or die("Could not find database."); 

     $survey_question_response_id=$_POST['survey_question_response_id'];
     $survey_id=$_POST['survey_id'];
     $question_id=$_POST['question_id'];
     $survey_response_answer_id=$_POST['survey_response_answer_id'];
     echo($survey_question_response_id);
     $query=("INSERT INTO survey_question_responses   (survey_question_response_id,survey_id,question_id,survey_response_answer_id)
     VALUES ('$survey_question_response_id', '$survey_id','$question_id','$survey_response_answer_id')");
     mysql_query($query,$con);
     printf("Records inserted: %d\n", mysql_affected_rows());
     echo($survey_id) 
    ?>

Upvotes: 0

Views: 89

Answers (3)

asprin
asprin

Reputation: 9823

Your form method is POST and you're using $_GET to capture variables. Use $_POST instead of $GET to solve your problem.

Also, wrong tag syntax.

<form action="surveyAnswer.php" method="post" enctype="multipart/form-data">

This points to surveyAnswer.php. So put the below code in surveyAnswer.php page and remove it from the page where html form is displayed.

    <?php

       $survey_question_response_id=$_POST['survey_question_response_id'];
       $survey_id=$_POST['survey_id'];
       $question_id=$_POST['question_id'];
       $survey_response_answer_id=$_POST['survey_response_answer_id'];
       $query=("INSERT INTO survey_question_responses     (survey_question_response_id,survey_id,question_id,survey_response_answer_id)
      VALUES ('$survey_question_response_id', '$survey_id','$question_id','$survey_response_answer_id')");
     mysql_query($query,$con);
     printf("Records inserted: %d\n", mysql_affected_rows());
     echo($survey_id);

 ?>

Upvotes: 1

noobie-php
noobie-php

Reputation: 7223

As in your form you have form method="post" where as you are storing values using GET either change your form method="GET" or use

$_POST['survey_question_response_id'];  

instead of

$_GET['survey_question_response_id'];

etc for other variables as well.

Also you are missing ";" here " echo($survey_id)"

Upvotes: 0

donald123
donald123

Reputation: 5739

You shoot up your action with POST but in your PHP-Code you use $_GET

change all $_GET:

 <?php
   $survey_question_response_id=$_POST['survey_question_response_id'];
   // OR eighter to
   $survey_question_response_id=$_REQUEST['survey_question_response_id'];
   ....

Upvotes: 0

Related Questions