Jump to content
soimuletzu1

Eroare in cod php

Recommended Posts

Posted

Am facut zilele acestea un formular de adaugare niste date intr-o baza de date, iar in fisierul de actiune am urmatorul script:


<head>
<SCRIPT language="JavaScript">
<!--
function getgoing()
{
top.location="add.php";
}

if (top.frames.length==0)
{
alert("In 5 secunde revii la pagina anterioara!");
setTimeout('getgoing()',5000);
}
//-->
</SCRIPT>
</head>



<?php
error_reporting(-1);
if (isset($_POST['pachet']) && isset($_POST['tip']) && isset($_POST['slot']) && isset($_POST['pret']) && isset($_POST['fps']) && isset($_POST['port']) && isset($_POST['dedicat']) && isset($_POST['bazadedate']) && isset($_POST['ftp']) && isset($_POST['antiflood']) && isset($_POST['antiddos']) && isset($_POST['cpanel']) && isset($_POST['subdomeniu']) && isset($_POST['restrictii'])) {
// 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['pachet'])>1 && strlen($_POST['pachet'])<150) $pachet = $_POST['pachet'];
else $eroare[] = 'Error Paket : Pachetul trebuie sa contina intre 1 si 150 de caractere!';

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

// Slot intre 1 si 100 de caractere
if(strlen($_POST['slot'])>1 && strlen($_POST['slot'])<100) $slot = $_POST['slot'];
else $eroare[] = 'Error Slot : Sloturile trebuie sa contina intre 1 si 100 caractere!';

// Verifica daca Pretul are cel putin 1 caractere si maxim 100
if(strlen($_POST['pret'])>1 && strlen($_POST['pret'])<100) $pret = $_POST['pret'];
else $eroare[] = 'Error Pret : Preturile trebuie sa contina intre 1 si 100 caractere!';

// Verifica daca FPS are cel putin 1 caractere si maxim 1000
if(strlen($_POST['fps'])>1 && strlen($_POST['fps'])<1000) $fps = $_POST['fps'];
else $eroare[] = 'Error FPS : Fps-ul trebuie sa contina intre 1 si 1000 caractere!';

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

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

// Baza de date intre 1 si 100 de caractere
if(strlen($_POST['bazadedate'])>1 && strlen($_POST['bazadedate'])<100) $bazadedate = $_POST['bazadedate'];
else $eroare[] = 'Error Baza de date : Baza de date trebuie sa contina intre 1 si 100 caractere!';

// Verifica daca FTP are cel putin 1 caractere si maxim 100
if(strlen($_POST['ftp'])>1 && strlen($_POST['ftp'])<100) $ftp = $_POST['ftp'];
else $eroare[] = 'Error FTP : FTP-UL trebuie sa contina intre 1 si 100 caractere!';

// Verifica daca Antiflood are cel putin 5 caractere si maxim 6
if(strlen($_POST['antiflood'])>1 && strlen($_POST['antiflood'])<1000) $antiflood = $_POST['antiflood'];
else $eroare[] = 'Error antiflood : antiflood-ul trebuie sa contina intre 1 si 1000 caractere!';

// Verifica daca antiddosul are cel putin 1 si cel mult 1000
if(strlen($_POST['antiddos'])>1 && strlen($_POST['antiddos'])<1000) $antiddos = $_POST['antiddos'];
else $eroare[] = 'Error Anti-ddos : Anti-ddosul trebuie sa contina intre 1 si 1000 de caractere!';

//Controlpanelul trebuie sa contina intre 1 si 100 de caractere
if(strlen($_POST['cpanel'])>1 && strlen($_POST['cpanel'])<100) $cpanel = $_POST['cpanel'];
else $eroare[] = 'Error Cpanel: Cpanelul trebuie sa contina intre 1 si 100 caractere!';

// Verifica daca Subdomeniu are cel putin 1 caractere si maxim 100
if(strlen($_POST['subdomeniu'])>1 && strlen($_POST['subdomeniu'])<100) $subdomeniu = $_POST['subdomeniu'];
else $eroare[] = 'Error Subdomeniu : Sub-domeniul trebuie sa contina intre 1 si 100 caractere!';

// Verifica daca Restrictii are cel putin 1 caractere si maxim 1000
if(strlen($_POST['restrictii'])>1 && strlen($_POST['restrictii'])<1000) $restrictii = $_POST['restrictii'];
else $eroare[] = 'Error Restrictii : restrictiile trebuie sa contina intre 1 si 1000 caractere!';

if (!isset($eroare)) {

$username="user";
$password="user";
$database="test";
$localhost = "localhost";
$con = mysql_connect("$localhost","$username","$password");
if (!$con)
{
die('Nu sa putut conecta la baza de date: ' . mysql_error());
}
mysql_select_db($database, $con);

// Se aplica functia de filtrare mysql_real_escape_string()
$pachet = mysql_real_escape_string($pachet);
$tip = mysql_real_escape_string($tip);
$slot = mysql_real_escape_string($slot);
$pret = mysql_real_escape_string($pret);
$fps = mysql_real_escape_string($fps);
$port = mysql_real_escape_string($port);
$dedicat = mysql_real_escape_string($dedicat);
$bazadedate = mysql_real_escape_string($bazadedate);
$ftp = mysql_real_escape_string($ftp);
$antiflood = mysql_real_escape_string($antiflood);
$antiddos = mysql_real_escape_string($antiddos);
$cpanel = mysql_real_escape_string($cpanel);
$subdomeniu = mysql_real_escape_string($subdomeniu);
$restrictii = mysql_real_escape_string($restrictii);

// Acum se adauga mai in siguranta aceste date in MySQL
$sql = "INSERT INTO `host_servere` (`pachet`, `tip`, `slot`, `pret`, `fps`, `port`, `dedicat`, `bazadedate`, `ftp`, `antiflood`, `antiddos`, `cpanel`, `subdomeniu`, `restrictii`) VALUES ('$pachet', '$tip', '$slot', '$pret', '$fps', '$port', '$dedicat', '$bazadedate', '$ftp', '$antiflood', '$antiddos', '$cpanel', '$subdomeniu', '$restrictii')";
if (mysql_query($sql)) {
$mesaj = "<center><br><br><br><br>Operatiune terminata cu succes!</center>";

}
else $mesaj = '<font color="red">Continutul nu a putut fi adaugat '. mysql_error(). '</font>';

mysql_close($con);
}
else $mesaj = '<font color="red">'. implode('<br />', $eroare). '</font>';
}

echo $mesaj;
?>

Imi da eroarea aceasta:

Notice: Undefined variable: mesaj in C:\xampp\htdocs\host\adauga.php on line 132, am verificat de mai multe ori dar nu gasesc problema , la linia 132 ii echo $mesaj.

Astept raspuns plz.

Posted

Cred ca mare dreptate ca eu am mai folosit scriptul acesta la alt form si mergea perfect ...

Formul actual care il folosesc ii acesta :


<form id="form_167766" class="appnitro" method="post" action="adauga.php">
<tr>
<td><table align="center" width="435" border="0">
<tr>
<td width="202"><label class="description" for="pachet">Nume Pachet:</label></td>
<td width="178"><label class="description">Caracteristici:</label></td>
<td width="178"><label class="description">Valori:</label></td>
</tr>
<tr>
<td><div>
<input id="element_1" name="pachet" class="element text medium" type="text" maxlength="255" value=""/>
</div></td>
<td><label class="description">Orice port dorit:</label></td>
<td><input name="port" type="radio" class="button_text" value="Da" checked="checked"/>
DA
<input type="radio" name="port" value="Nu"/>
NU </td>
</tr>
<tr>
<td><label class="description" for="tip">Tip: war/public</label></td>
<td><label class="description">IP dedicat:</label></td>
<td><input name="dedicat" type="radio" class="button_text" value="Da" checked="checked"/>
DA
<input type="radio" name="dedicat" value="Nu"/>
NU</td>
</tr>
<tr>
<td><div>
<input id="element_1" name="tip" class="element text medium" type="text" maxlength="255" value=""/>
</div></td>
<td><label class="description">Baza de date:</label></td>
<td><select name="bazadedate" id="bazadedate">
<option>MySQL</option>
</select></td>
</tr>
<tr>
<td><label class="description" for="slot">Numar Sloturi:</label></td>
<td><label class="description">Acces FTP:</label></td>
<td><input name="ftp" type="radio" class="button_text" value="Da" checked="checked"/>
DA
<input type="radio" name="ftp" value="Nu"/>
NU</td>
</tr>
<tr>
<td><div>
<input id="element_1" name="slot" class="element text medium" type="text" maxlength="255" value=""/>
</div></td>
<td><label class="description">Antiflood:</label></td>
<td><input name="antiflood" type="radio" class="button_text" value="Da" checked="checked"/>
DA
<input type="radio" name="antiflood" value="Nu"/>
NU</td>
</tr>
<tr>
<td><label class="description" for="pret">Pret server:</label></td>
<td><label class="description">Antiddos:</label></td>
<td><input name="antiddos" type="radio" class="button_text" value="Da" checked="checked"/>
DA
<input type="radio" name="antiddos" value="Nu"/>
NU</td>
</tr>
<tr>
<td><div>
<input id="element_1" name="pret" class="element text medium" type="text" maxlength="255" value=""/>
</div></td>
<td><label class="description">Control Panel:</label></td>
<td><select name="cpanel" id="cpanel">
<option>GameCP</option>
</select></td>
</tr>
<tr>
<td><label class="description" for="fps">Numar FPS-uri:</label></td>
<td><label class="description">Subdomeniu:</label></td>
<td><div>
<input id="element_1" name="subdomeniu" class="element text medium" type="text" maxlength="255" value=""/>
</div></td>
</tr>
<tr>
<td><div>
<input id="element_1" name="fps" class="element text medium" type="text" maxlength="255" value=""/>
</div></td>
<td><label class="description">Restrictii/Contract:</label></td>
<td><input name="restictii" type="radio" class="button_text" value="Da" checked="checked"/>
DA
<input type="radio" name="restrictii" value="Nu"/>
NU</td>
</tr>
<td><input type="submit" value="TRIMITE" /></td>
<td><input name="Reset" type="reset" value="RESET" /></td>
</table>
</form>

M-am uitat de cateva ori pe el si nu observ greseli .... ar putea fi de la <label> ?

Astept raspuns din partea celor care stiu unde ii pb , ms ff mult.

Posted

Nu prea ma pricep eu la formulare, dar in codul HTML ai ceva ciudat ...

<form>

<tr>

<td>

<table>

Si tu inchei cu

</table>

</form>

Ai uitat sa mai inchizi <tr> si <td> ... sa nu mai zic ca e incorect sa deschizi un rand si o celula fara sa deschizi si un tabel. Nu stiu daca ajuta dar ar merita incercat sa iti corectezi codul html.

Posted

sa nu razi te rog ... Nu am deschis xampp-ul ...

Acelasi script il utilizasem cu o zi in urma si mergea si cu xampp=ul inchis iar dupa ce am mai adaugat niste campuri si variabile nu mai mergea .. mam gandit ca trebuie sa fie o problema de php dar na .. pana nu te lovesti nu te doare :))

Ms pt ajutor oricum! scriptul e foarte bun folositi-l cu incredere daca aveti nevoie va pot da si mysqlul.

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