0

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) 
    ?>
0

3 Answers 3

1

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);

 ?>
Sign up to request clarification or add additional context in comments.

Comments

0

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'];
   ....

2 Comments

please change mysql_query($query,$con); to mysql_query($query,$con) or die(mysql_error()); and give us the output
i have updated the code as you told but it shows in return []
0

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)"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.