Answer the question
In order to leave comments, you need to log in
How to send data to MySQL using PHP?
Colleagues, I don’t understand why the data is not added to the database?
Submission Form
<meta charset="UTF-8">
<form method="post" action="action.php">
Адрес: <input size="255" name="address" type="text">
IP-сервера: <input size="255" name="IP" type="text">
<input value="Добавить запись" type="submit" name="submit">
</form>
<?php header('Content-Type: text/html; charset=utf-8');
include ('db.php');
error_reporting (E_ALL);
if(isset($_POST['submit']))
$address = $_POST['address'];
$IP = $_POST['IP'];
$sql = 'INSERT INTO table(address, IP, Login, TV, Terminal, monitoring)
VALUES("'.$address.'", "'.$IP.'", "'.$IP.'", "'.$IP.'", "'.$IP.'", "'.$IP.'")';
// проверка
if(!mysql_query($sql))
{echo '<center><p><b>Ошибка при добавлении данных!</b></p></center>';}
else
{echo '<center><p><b>Данные добавлены!</b></p></center>';}
?>
Answer the question
In order to leave comments, you need to log in
The MySQL server returns an error message to the interpreter - figure out how to display it. Use the power of PDO . Check it out, it 's worth it .
Among other things,
if(isset($_POST['submit'])) // у Вас по данному условию выполняется только
$address = $_POST['address']; // это
// А вот всё следующее выполняется В ЛЮБОМ СЛУЧАЕ:
$IP = $_POST['IP'];
$sql = 'INSERT INTO table(address, IP, Login, TV, Terminal, monitoring) '
. 'VALUES("'.$address.'", "'.$IP.'", "'.$IP.'", "'.$IP.'", "'.$IP.'", "'.$IP.'")';
// проверка
if(!mysql_query($sql)) {
echo '<center><p><b>Ошибка при добавлении данных!</b></p></center>';
} else {
echo '<center><p><b>Данные добавлены!</b></p></center>';
}
1. Print the contents of $sql, execute in PhpMyAdmin, carefully read what is the error
2. Do not use mysql_* functions, they are obsolete, and the latest version of PHP does not exist at all
3. Do not substitute data directly, you need EXCLUSIVELY through prepared expressions
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question