Jump to content

information from form not reaching database


webguync

Recommended Posts

Hello,

 

I have a form which submits info into a MySQL DB (or at least it is supposed to). I get a success msg. (no DB errors or anything), but no data. Not sure if the problem is w/ my PHP code or MySQL structure, so I am posting all my code including the form code. I am pretty sure the code can be simplified also, so any help with that is greatly appreciated also.

 

<form action ="TestSubmit.php">
<!--question1-->
<label for="Question1">
<p>1. Question1</p>
</label><br /><br />
<label for="Answer1">Answer 1</label><br /><br />
<textarea name="Answer1" id="Answer1" rows="15" cols="80">
</textarea>
<br /><br />
<!--question2-->
<label for="Question2"><p>2. Question2</p>
</label><br /><br />
<label for="Answer2">Answer 2</label><br /><br />
<textarea name="Answer2" id="Answer2" rows="15" cols="80">
</textarea>
<br /><br />
<!--question3-->
<label for="Question3"><p>3. Question3</p>
</label><br /><br />
<label for="Answer3">Answer 3</label><br /><br />
<textarea name="Answer3" id="Answer3" rows="15" cols="80">
</textarea>
<br /><br />
<!--question4-->
<label for="Question4"><p>Question4</p>
</label><br /><br />
<label for="Answer4">Answer 4</label><br /><br />
<textarea name="Answer4" id="Answer4" rows="15" cols="80">
</textarea>
<br /><br />
<!--question5-->
<label for="Question5">Question5</p>
</label><br /><br />
<label for="Answer5">Answer 5</label><br /><br />
<textarea name="Answer5" id="Answer5" rows="15" cols="80">
</textarea>
<br /><br />
<!--question6-->
<label for="Question6">Question6
</label><br /><br />
<label for="Answer6">Answer 6</label><br /><br />
<textarea name="Answer6" id="Answer6" rows="15" cols="80">
</textarea>
<br /><br />
<!--question7-->
<label for="Question7">Question7
</label><br /><br />
<label for="Answer7">Answer 7</label><br /><br />
<textarea name="Answer7" id="Answer7" rows="15" cols="80">
</textarea>
<br /><br />
<!--question8-->
<label for="Question8">Question8
</label><br /><br />
<label for="Answer8">Answer 8</label><br /><br />
<textarea name="Answer8" id="Answer8" rows="15" cols="80">
</textarea>
<br /><br />
<!--question9-->
<label for="Question9">Question9
</label><br /><br />
<label for="Answer9">Answer 9</label><br /><br />
<textarea name="Answer9" id="Answer9" rows="15" cols="80">
</textarea><br /><br />
<input type="submit" value="submit" name="submit" /><br /><br />
<input type="reset" value="reset" name="reset" /><br /><br />
</form>

 

 

<?php
$con = mysql_connect("localhost","uname","pw") or die('Could not connect: ' . mysql_error());

mysql_select_db("DBName") or die(mysql_error());

$name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file
$A1=mysql_real_escape_string($_POST['Answer1']); //This value has to be the same as in the HTML form file
$A2=mysql_real_escape_string($_POST['Answer2']); //This value has to be the same as in the HTML form file
$A3=mysql_real_escape_string($_POST['Answer3']); //This value has to be the same as in the HTML form file
$A4=mysql_real_escape_string($_POST['Answer4']); //This value has to be the same as in the HTML form file
$A5=mysql_real_escape_string($_POST['Answer5']); //This value has to be the same as in the HTML form file
$A6=mysql_real_escape_string($_POST['Answer6']); //This value has to be the same as in the HTML form file
$A7=mysql_real_escape_string($_POST['Answer7']); //This value has to be the same as in the HTML form file
$A8=mysql_real_escape_string($_POST['Answer8']); //This value has to be the same as in the HTML form file
$A9=mysql_real_escape_string($_POST['Answer9']); //This value has to be the same as in the HTML form file
$sql="INSERT INTO TableName (name,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,Answer8,Answer9) VALUES ('$name','$A1','$A2','$A3','$A4','$A5','$A6','$A7','$A8','$A9')"; /*form_data is the name of the MySQL table where the form data will be saved.
name and email are the respective table fields*/
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "Your information has been submitted successfully.";
mysql_close($con);
?>

 

CREATE TABLE `TableName` (
  `responses_id` smallint(6) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `Answer1` text NOT NULL,
  `Answer2` text NOT NULL,
  `Answer3` text NOT NULL,
  `Answer4` text NOT NULL,
  `Answer5` text NOT NULL,
  `Answer6` text NOT NULL,
  `Answer7` text NOT NULL,
  `Answer8` text NOT NULL,
  `Answer9` text NOT NULL,
  PRIMARY KEY  (`responses_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

Link to comment
Share on other sites

Best thing to do is echo your $sql variable and make sure it looks right.

 

I'm guessing all the values are null because you don't have a method set in your form but not sure if it assumes a default if you don't define it.

 

ie. <form action="TestSubmit.php" method="post">

Link to comment
Share on other sites

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.