W
W
Wilson2020-04-28 11:31:56
PHP
Wilson, 2020-04-28 11:31:56

Why is the data not saved to the database?

I made the site test-answ.online and everything seems to be well and correctly written, but the tags disappear after the page is reloaded. They are not stored in the database. Where is my mistake?

bd.php

<?php

$sdb_name = "localhost";
$user_name = "name";
$user_password = "pasword";
$db_name = "name";

// ���������� � �������� ���� ������
if(!$link = mysql_connect($sdb_name, $user_name, $user_password))
{
  echo "<br>�� ���� ����������� � �������� ���� ������<br>";
  exit();
}

// �������� ���� ������
if(!mysql_select_db($db_name, $link))
{
  echo "<br>�� ���� ������� ���� ������<br>";
  exit();
}

mysql_query('SET NAMES utf8');

?>

addmetki.php
<?php

header('Content-Type: text/html; charset=utf-8');

include("bd.php");

require_once "html_filter_class.php";
    
  $tags_set = array(
    
    'h1'		=> array('id', 'class'),
    'h2'		=> array('id', 'class'),
    'h3'		=> array('id', 'class'),
    'h4'		=> array('id', 'class'),
    'h5'		=> array('id', 'class'),
    'h6'		=> array('id', 'class'),
    
    'p'			=> array('id', 'class'),
    'span'		=> array('id', 'class'),
    'a'			=> array('id', 'class', 'href'),
    'img'		=> array('id', 'class', 'src', 'alt', FALSE),
    'br'		=> array(FALSE),
    'hr'		=> array(FALSE),
    
    'strong'		=> array('id', 'class'),	
    'div'		=> array('id', 'class', 'style'),		
    
    
    'ul'		=> array('id', 'class'),
    'ol'		=> array('id', 'class'),
    'li'		=> array('id', 'class'),
    
    'table'		=> array('id', 'class'),
    'tr'		=> array('id', 'class'),
    'td'		=> array('id', 'class'),
    'th'		=> array('id', 'class'),
    'thead'		=> array('id', 'class'),
    'tbody'		=> array('id', 'class'),
    'tfoot'		=> array('id', 'class')	
    
  );
  
  
  $html_filter = new html_filter();
  $html_filter->set_tags($tags_set);

$iconText = htmlspecialchars($_POST['icontext']);
$hintText = htmlspecialchars($_POST['hinttext']);
$balloonText = $html_filter->filter($_POST['balloontext']);
$stylePlacemark = $_POST['styleplacemark'];
$lat = $_POST['lat'];
$lon = $_POST['lon'];

$sql = "INSERT INTO ymapapiv2_markers (`id`, `iconText`, `hintText`, `balloonText`, `stylePlacemark`, `lat`, `lon`) VALUES (NULL, '$iconText', '$hintText', '$balloonText', '$stylePlacemark', '$lat', '$lon');";

$result = mysql_query($sql) or die("Ошибочный запрос: " . mysql_error());

?>

vivodpointsmap.php
<?php
header('Content-Type: text/html; charset=utf-8');
 
require ("bd.php");
 
if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
 
$result = mysql_query("SELECT * FROM ymapapiv2_markers");
if(mysql_num_rows($result)>0)
{
while ($mar = mysql_fetch_array($result))
{
$json =  array(icontext=>$mar['iconText'], hinttext=>$mar['hintText'], balloontext=>$mar['balloonText'], styleplacemark=>$mar['stylePlacemark'], lat=>$mar['lat'], lon=>$mar['lon']);
$markers[] = $json;
}
 
}
$points = array(markers=>$markers);
 
echo json_encode($points);
 
}
 
 
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Lashchevsky, 2020-04-30
@Alexanevsky

Try to remove 'id' from the request altogether, and accordingly null, that is, to get it like this:

$sql = "INSERT INTO ymapapiv2_markers (`iconText`, `hintText`, `balloonText`, `stylePlacemark`, `lat`, `lon`) VALUES ('$iconText', '$hintText', '$balloonText', '$stylePlacemark', '$lat', '$lon');";

Most likely, there is an auto-increment on the id column and it will put it down, but passing NULL there may break the logic and it cannot execute the request, because you can transfer there either only integer (and even unique), or not transfer at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question