Jump to content
soimuletzu1

Problema la editare php

Recommended Posts

Posted

AM un script de editare pt. o tabela din baza de date ... totul merge corect , adica cand dau pe butonul de editare imi apare formul , ii schimb continutul si dau pe buton salveaza , primesc ca mesaj: Bannerul a fost editat, dar in baza de date nu se editeaza nimic ..


<?php
if($_POST['action']=="salveaza"){
//var_dump($_POST);
if (isset($_POST['banner']) && isset($_POST['banner_link']) && isset($_POST['target'])) {
// Se filtreaza datele pt. eliminare posibile spatii exterioare si tag-uri
$_POST = array_map("trim", $_POST);
$_POST = array_map("strip_tags", $_POST);

// Se verifica daca "magic_quotes_gpc()" este setat ON
// Daca e ON, se aplica stripslashes() pentru a nu se adauga de 2 ori '\' cand va fi aplicat "mysql_real_escape_string()"
if(get_magic_quotes_gpc()) { $_POST = array_map("stripslashes", $_POST); }

// Se verifica daca au fost completate corect toate campurile
// Daca au fost completate le preia in variabile, in caz contrar seteaza o variabila tip Array cu mesaj de eroare

// Verifica daca Pachetul are cel putin 1 caractere si maxim 150
if(strlen($_POST['banner'])>1 && strlen($_POST['banner'])<150) $pachet = $_POST['banner'];
else $eroare[] = 'Error Banner : Bannerul trebuie sa contina intre 1 si 150 de caractere!';

// Verifica daca tip are cel putin 1 si cel mult 1000
if(strlen($_POST['banner_link'])>0 && strlen($_POST['banner_link'])<1000) $tip = $_POST['banner_link'];
else $eroare[] = 'Error Banner link : Linkul trebuie sa contina intre 0 si 1000 de caractere!';

// Verifica daca tip are cel putin 1 si cel mult 1000
if(strlen($_POST['target'])>0 && strlen($_POST['target'])<1000) $tip = $_POST['target'];
else $eroare[] = 'Error target : Targetul trebuie sa contina intre 0 si 1000 de caractere!';

$banner = mysql_real_escape_string($banner);
$banner_link = mysql_real_escape_string($banner_link);
$target = mysql_real_escape_string($target);

$sql = "UPDATE `host_banner` SET `banner`='{$banner}', `banner_link`='{$banner_link}', `target`='{$target}' WHERE id_banner='{$_POST['id']}'";
if (mysql_query($sql)) {
$mesaj = "<center><br><br><br><br>Bannerul a fost editat!<br><br></center>";

}
else $mesaj = '<font color="red">Bannerul nu a putut fi editat: '. mysql_error(). '</font>';
}
echo $mesaj;
}

if($_GET['action']=="editeaza"){
$row = mysql_fetch_array(mysql_query("SELECT * FROM `host_banner` WHERE id_banner='{$_GET['id']}'"));
$id = $row[0];
$banner = $row[1];
$banner_link = $row[2];
$target = $row[3];
?>



<form method="post" action="bannere.php">
<table width="474" align="left" class="myform" id="stylized">
<tbody>
<tr>
<td colspan="2"><h1>Adaugare bannere</h1>
Adaugare bannere in partea dreapta sus: <a href="../index.php">Vizualizare</a></td>
</tr>
<tr>
<th><label>Banner: <span class="small">Link catre imagine</span> </label></th>
<td width="256"><input name="banner" type="text" id="banner" size="60" value="<?php echo $banner; ?>" /></td>
</tr>
<tr valign="left">
<th><label>Link: <span class="small">Link-ul asociat bannerului</span> </label></th>
<td><input name="banner_link" type="banner_link" id="banner_link" size="60" value="<?php echo $banner_link; ?>" /></td>
</tr>
<tr>
<td colspan="2"><button name="action" value="salveaza" />Salvare</button></td>
</tr>
</tbody>
</table>
</form>

<?php
}
mysql_close($conexiune);
?>

Astept reply care stie ... ms.

app asta ii linkul care il folosesc la edit:

<a href="?action=editeaza&id=<? print $id_banner; ?>"><img src="css/edit.gif" border="0" width="29" height="18" /></a>

Posted

$banner = mysql_real_escape_string($banner);
$banner_link = mysql_real_escape_string($banner_link);
$target = mysql_real_escape_string($target);

Argumentele: $banner, $banner_link, $target - Care sunt? Sigur nu era $_POST['banner']...? Sau probabil $pachet, $tip... ? Oricum acele if-uri sunt ciudate, pune macar un if - elseif ca sa iti execute query-ul si sa creeze acele variabile numai daca toate datele sunt corecte...

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.   Paste as plain text instead

  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...