Я создал форму HTML и попытался сохранить данные из своих полей в базу данных. Входы, выпадающие меню и радиокнопка сохраняются правильно, но текстовое поле всегда добавляется в базу данных как пустое поле. Вот код:Textarea пуст в поле базы mySQL PHP
HTML:
<head>
<link rel="stylesheet" type="text/css" href="feedback_form_style.css">
</head>
<form name="feedbackform" method="post" class="basic-grey" action="feedback_form_send.php">
<h1>Feedback form
<span>Please answer the questions below.</span>
</h1>
<table width="450px">
</tr>
<tr>
<td valign="top">
<label for="School">School</label>
</td>
<td valign="top">
<input type="text" name="School" placeholder="Name of your school" maxlength="50" size="30" required/> <! required not supported in Safari>
</td>
</tr>
<tr>
<td valign="top">
<label for="Year">Year</label>
</td>
<td valign="top">
<input type="text" name="Year" placeholder="Which year you are" maxlength="50" size="30"/>
</td>
</tr>
<tr>
<td valign="top">
<label for="Gender">Gender</label>
</td>
<td valign="top">
<select name="Gender">
<option value="male"/>Male</option>
<option value="female"/>Female</option>
</select>
</td>
</tr>
</table>
<p></p> <!emptyline>
<table>
<tr>
<td valign="top">
<label for="What do you think and engineer does">What do you think an engineer does? </label>
</td>
</tr>
<tr>
<td valign="top">
<textarea name="What do you think an engineer does" placeholder="Your answer here" maxlength="1000" cols="60" rows="10"/></textarea>
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td valign="top">
<label for="What was the most enjoyable part about the visit today?">What was the most enjoyable part about the visit today? </label>
</td>
</tr>
<tr>
<td valign="top">
<textarea name="What was the most enjoyable part about the visit today" placeholder="Your answer here" maxlength="1000" cols="60" rows="10"></textarea>
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td valign="top">
<label for="Was there anything you did not like?">Was there anything you did not like? </label>
</td>
</tr>
<tr>
<td valign="top">
<input type="radio" name="Was there anything you did not like?" value="yes">Yes (plese give details below)
<input type="radio" name="Was there anything you did not like?" value="no">No
</td>
</tr>
<tr>
<td valign="top">
<textarea name="Was there anything you did not like (comment)?" placeholder="Details here" maxlength="1000" cols="60" rows="10"></textarea>
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td valign="top">
<label for="Would you consider studying Engineering at university?">Would you consider studying Engineering at university? </label>
</td>
</tr>
<tr>
<td valign="top">
<input type="radio" name="Would you consider studying Engineering at university?" value="yes">Yes
<input type="radio" name="Would you consider studying Engineering at university?" value="no">No
<input type="radio" name="Would you consider studying Engineering at university?" value="unsure">Unsure
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td valign="top">
<label for="Has today's session inspired you to consider becoming an engineer?">Has today's session inspired you to consider becoming an engineer? </label>
</td>
</tr>
<tr>
<td valign="top">
<input type="radio" name="Has today's session inspired you to consider becoming an engineer?" value="yes">Yes
<input type="radio" name="Has today's session inspired you to consider becoming an engineer?" value="no">No
<input type="radio" name="Has today's session inspired you to consider becoming an engineer?" value="unsure">Unsure
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td valign="top">
<label for="Before today's session did you know much about engineering?">Before today's session did you know much about engineering? </label>
</td>
</tr>
<tr>
<td valign="top">
<input type="radio" name="Before today's session did you know much about engineering?" value="yes">Yes
<input type="radio" name="Before today's session did you know much about engineering?" value="no">No
<input type="radio" name="Before today's session did you know much about engineering?" value="unsure">A little
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td valign="top">
<label for="Has todays session taught you much about engineering?">Has todays session taught you much about engineering? </label>
</td>
</tr>
<tr>
<td valign="top">
<input type="radio" name="Has todays session taught you much about engineering?" value="yes">Yes
<input type="radio" name="Has todays session taught you much about engineering?" value="no">No
<input type="radio" name="Has todays session taught you much about engineering?" value="unsure">A little
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td valign="top">
<label for="Based on today's session, what do you think an engineer does?">Based on today's session, what do you think an engineer does? </label>
</td>
</tr>
<tr>
<td valign="top">
<textarea name="Based on today's session, what do you think an engineer does?" placeholder="Your answer here" maxlength="1000" cols="60" rows="10"></textarea>
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td valign="top">
<label for="Comments/Suggestions/Questions">Comments/Suggestions/Questions </label>
</td>
</tr>
<tr>
<td valign="top">
<textarea name="Comments/Suggestions/Questions" placeholder="Enter your comments, suggestions and questions here" maxlength="1000" cols="60" rows="10"></textarea>
</td>
</tr>
<tr> <td><p></p></td></tr> <!emptyline>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" class="submit" value="Submit">
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
Thank you for your feedback
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
© Girls in Engineering 2015
</td>
</tr>
</table>
</form>
PHP:
$value = test_input($_POST['School']);
$value2 = test_input($_POST['What do you think an engineer does']);
$sql = "INSERT INTO form1 (input1,input2) VALUES ('$value', '$value2')";
if($_POST){
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
Выход из print_r ($ _ POST):
Array
(
[School] => 123
[Year] =>
[Gender] => male
[What_do_you_think_an_engineer_does] => 234
[What_was_the_most_enjoyable_part_about_the_visit_today] =>
[Was_there_anything_you_did_not_like_(comment)?] =>
[Based_on_today's_session,_what_do_you_think_an_engineer_does?] =>
[Comments/Suggestions/Questions] =>
)
Спасибо за вашу помощь.
Вы уверены, что 'test_input()' функция работает правильно? Попробуйте отладить его возвращаемое значение. 'var_dump ($ data)' или 'print_r ($ data)' – Chris
Вы не можете сделать это: '
Функция @Chris test_input отлично работает для полей другого типа , но для textarea ничего не печатает. – user2758935