Viva!
Ao editar um artigo qualquer no meu site, dá-me este erro:
Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'news_subtitle='Subtítulo da notícia', news_desc='A M' at line 2.
Ao mesmo tempo, quando crio um artigo, as imagens coladas (eu uso um servidor externo, faço um género de embed), o atributo de imagem coloca "\\" ao enviar para a DB:
Ao editar um artigo qualquer no meu site, dá-me este erro:
Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'news_subtitle='Subtítulo da notícia', news_desc='A M' at line 2.
Spoiler
Código :
Código :
// See if the edit news form has been sent.
if (isset($_POST["publish-p"]))
{
// Get the values of the form.
$link = mysqli_connect("DADOS") or die("Error " . mysqli_error($link));
$news_guid = mysqli_real_escape_string($link, $_POST['news_guid']);
$categoria = mysqli_real_escape_string($link, $_POST['categoria']);
$categoria2 = mysqli_real_escape_string($link, $_POST['categoria2']);
$destaque = mysqli_real_escape_string($link, $_POST['destaque']);
$publicado = mysqli_real_escape_string($link, $_POST['publicado']);
$news_title = mysqli_real_escape_string($link, $_POST['news_title']);
$news_slug = mysqli_real_escape_string($link, $_POST['news_slug']);
$news_subtitle = mysqli_real_escape_string($link, $_POST['news_subtitle']);
$news_desc = mysqli_real_escape_string($link, $_POST['news_desc']);
$news_post = mysqli_real_escape_string($link, $_POST['news_post']);
$news_date = mysqli_real_escape_string($link, $_POST['news_date']);
$hour = mysqli_real_escape_string($link, $_POST['hour']);
$news_image = mysqli_real_escape_string($link, $_POST['news_image']);
$copyright = mysqli_real_escape_string($link, $_POST['copyright']);
// Create the sql query
$update_sql = "UPDATE news
SET news_title='$news_title', news_slug='$news_slug' news_subtitle='$news_subtitle', news_desc='$news_desc', news_post='$news_post', news_date='$news_date',
news_hour='$news_hour', news_image='$news_image', categoria='$categoria', categoria2='$categoria2', copyright='$copyright', destaque='$destaque', publicado='$publicado'
WHERE news_guid='$news_guid'";
// Update the database
$link = mysqli_connect("DADOS") or die("Error " . mysqli_error($link));
mysqli_query($link, $update_sql) or die("Error " . mysqli_error($link));ysqli_error();
echo "<h3>Notícia actualizada!</h3>";
}
// See if the guid form has been sent.
else if (isset($_POST["edit_form_p"]))
{
// Check that the guid input field has something in it.
// Due to javascript validation the form shouldn't be sent without a value in the guid field, this is just a backup.
if (isset($_POST['guid_input']))
{
// Query the database using the guid
$link = mysqli_connect("localhost", "motorra_mrn", "cT86MLIVMQyKxmJ","motorra_mrn") or die("Error " . mysqli_error($link));
$guid = $_POST['guid_input'];
$query = "SELECT * FROM news WHERE news_guid='$guid' LIMIT 1";
$result = $result = $link->query($query) or die("Erro a seleccionar o artigo.");
$row = mysqli_fetch_array($result) or die("Erro. O artigo pode não existir");
// Get all the article information.
$news_title = $row['news_title'];
$news_slug = $row['news_slug'];
$news_subtitle = $row['news_subtitle'];
$news_desc = $row['news_desc'];
$news_html = $row['news_post'];
$news_date = $row['news_date'];
$news_hour = $row['hour'];
$news_image = $row['news_image'];
$categoria = $row['categoria'];
$categoria2 = $row['categoria2'];
$copyright = $row['copyright'];
$destaque = strtolower($row['destaque']);
$publicado = strtolower($row['publicado']);
if (isset($_POST["publish-p"]))
{
// Get the values of the form.
$link = mysqli_connect("DADOS") or die("Error " . mysqli_error($link));
$news_guid = mysqli_real_escape_string($link, $_POST['news_guid']);
$categoria = mysqli_real_escape_string($link, $_POST['categoria']);
$categoria2 = mysqli_real_escape_string($link, $_POST['categoria2']);
$destaque = mysqli_real_escape_string($link, $_POST['destaque']);
$publicado = mysqli_real_escape_string($link, $_POST['publicado']);
$news_title = mysqli_real_escape_string($link, $_POST['news_title']);
$news_slug = mysqli_real_escape_string($link, $_POST['news_slug']);
$news_subtitle = mysqli_real_escape_string($link, $_POST['news_subtitle']);
$news_desc = mysqli_real_escape_string($link, $_POST['news_desc']);
$news_post = mysqli_real_escape_string($link, $_POST['news_post']);
$news_date = mysqli_real_escape_string($link, $_POST['news_date']);
$hour = mysqli_real_escape_string($link, $_POST['hour']);
$news_image = mysqli_real_escape_string($link, $_POST['news_image']);
$copyright = mysqli_real_escape_string($link, $_POST['copyright']);
// Create the sql query
$update_sql = "UPDATE news
SET news_title='$news_title', news_slug='$news_slug' news_subtitle='$news_subtitle', news_desc='$news_desc', news_post='$news_post', news_date='$news_date',
news_hour='$news_hour', news_image='$news_image', categoria='$categoria', categoria2='$categoria2', copyright='$copyright', destaque='$destaque', publicado='$publicado'
WHERE news_guid='$news_guid'";
// Update the database
$link = mysqli_connect("DADOS") or die("Error " . mysqli_error($link));
mysqli_query($link, $update_sql) or die("Error " . mysqli_error($link));ysqli_error();
echo "<h3>Notícia actualizada!</h3>";
}
// See if the guid form has been sent.
else if (isset($_POST["edit_form_p"]))
{
// Check that the guid input field has something in it.
// Due to javascript validation the form shouldn't be sent without a value in the guid field, this is just a backup.
if (isset($_POST['guid_input']))
{
// Query the database using the guid
$link = mysqli_connect("localhost", "motorra_mrn", "cT86MLIVMQyKxmJ","motorra_mrn") or die("Error " . mysqli_error($link));
$guid = $_POST['guid_input'];
$query = "SELECT * FROM news WHERE news_guid='$guid' LIMIT 1";
$result = $result = $link->query($query) or die("Erro a seleccionar o artigo.");
$row = mysqli_fetch_array($result) or die("Erro. O artigo pode não existir");
// Get all the article information.
$news_title = $row['news_title'];
$news_slug = $row['news_slug'];
$news_subtitle = $row['news_subtitle'];
$news_desc = $row['news_desc'];
$news_html = $row['news_post'];
$news_date = $row['news_date'];
$news_hour = $row['hour'];
$news_image = $row['news_image'];
$categoria = $row['categoria'];
$categoria2 = $row['categoria2'];
$copyright = $row['copyright'];
$destaque = strtolower($row['destaque']);
$publicado = strtolower($row['publicado']);
Ao mesmo tempo, quando crio um artigo, as imagens coladas (eu uso um servidor externo, faço um género de embed), o atributo de imagem coloca "\\" ao enviar para a DB:
Spoiler
<figure class=\"image\" style=\"float:right\"><img alt=\"Fórmula E terá oito construtores na segunda época ©FEH\" src=\"http://imagizer.imageshack.us/a/img538/3615/mR7WYo.jpg\" />
<figcaption>Fórmula E mais aberta em 2015-16 ©FEH</figcaption>
</figure>
<figure class=\"image\" style=\"float:right\"><img alt=\"Fórmula E terá oito construtores na segunda época ©FEH\" src=\"http://imagizer.imageshack.us/a/img538/3615/mR7WYo.jpg\" />
<figcaption>Fórmula E mais aberta em 2015-16 ©FEH</figcaption>
</figure>
Spoiler
Código :
Código :
if (isset($_POST["publish-p"]))
{
$link = mysqli_connect("DADOS") or die("Error " . mysqli_error($link));
$categoria= mysqli_real_escape_string($link, $_POST['categoria']);
$categoria2= mysqli_real_escape_string($link, $_POST['categoria2']);
$destaque= mysqli_real_escape_string($link, $_POST['destaque']);
$publicado= mysqli_real_escape_string($link, $_POST['publicado']);
$news_title= mysqli_real_escape_string($link, $_POST['news_title']);
$news_slug= mysqli_real_escape_string($link, $_POST['news_slug']. '-' . date('d-m-Y'));
$news_subtitle= mysqli_real_escape_string($link, $_POST['news_subtitle']);
$news_desc= mysqli_real_escape_string($link, $_POST['news_desc']);
$news_post= mysqli_real_escape_string($link, $_POST['news_post']);
$news_date= mysqli_real_escape_string($link, $_POST['news_date']);
$hour= mysqli_real_escape_string($link, date('H:i'));
$news_image= mysqli_real_escape_string($link, $_POST['news_image']);
$copyright= mysqli_real_escape_string($link, $_POST['copyright']);
$publish="INSERT INTO news
(news_guid, categoria, categoria2, destaque, publicado, news_title, news_slug, news_subtitle,
news_desc, news_post, news_date, hour, news_image, copyright)
VALUES
(uuid(), '$categoria', '$categoria2', '$destaque', '$publicado', '$news_title', '$news_slug', '$news_subtitle',
'$news_desc', '$news_post', '$news_date', '$hour', '$news_image', '$copyright')";
mysqli_query($link, $publish) OR DIE(mysql_error());
//mensagem após submeter dados
$message = "<script>alert('Notícia publicada!');</script>";
{
$link = mysqli_connect("DADOS") or die("Error " . mysqli_error($link));
$categoria= mysqli_real_escape_string($link, $_POST['categoria']);
$categoria2= mysqli_real_escape_string($link, $_POST['categoria2']);
$destaque= mysqli_real_escape_string($link, $_POST['destaque']);
$publicado= mysqli_real_escape_string($link, $_POST['publicado']);
$news_title= mysqli_real_escape_string($link, $_POST['news_title']);
$news_slug= mysqli_real_escape_string($link, $_POST['news_slug']. '-' . date('d-m-Y'));
$news_subtitle= mysqli_real_escape_string($link, $_POST['news_subtitle']);
$news_desc= mysqli_real_escape_string($link, $_POST['news_desc']);
$news_post= mysqli_real_escape_string($link, $_POST['news_post']);
$news_date= mysqli_real_escape_string($link, $_POST['news_date']);
$hour= mysqli_real_escape_string($link, date('H:i'));
$news_image= mysqli_real_escape_string($link, $_POST['news_image']);
$copyright= mysqli_real_escape_string($link, $_POST['copyright']);
$publish="INSERT INTO news
(news_guid, categoria, categoria2, destaque, publicado, news_title, news_slug, news_subtitle,
news_desc, news_post, news_date, hour, news_image, copyright)
VALUES
(uuid(), '$categoria', '$categoria2', '$destaque', '$publicado', '$news_title', '$news_slug', '$news_subtitle',
'$news_desc', '$news_post', '$news_date', '$hour', '$news_image', '$copyright')";
mysqli_query($link, $publish) OR DIE(mysql_error());
//mensagem após submeter dados
$message = "<script>alert('Notícia publicada!');</script>";