Eroare Error: Unknown column in field list

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
Avatar utilizator
evident
Mesaje:168

Eroare Error: Unknown column in field list

INSERT.PHP

Cod: Selectaţi tot

<?php
    $con = mysql_connect("localhost","root","250644");
    if (!$con)  die('Could not connect: ' . mysql_error());

    mysql_select_db("anunturi", $con);

    if(isset($_POST['titluanunt']) && isset($_POST['nume']) && isset($_POST['categorie']) && isset($_POST['sunteti']) && isset($_POST['textanunt']) && isset($_POST['pret']) && isset($_POST['moneda']) && isset($_POST['email']) && isset($_POST['nrtel']) && isset($_POST['judet']) && isset($_POST['localitate'])) {
      $sql="INSERT INTO anunturi (titluanunt, nume, categorie, sunteti, textanunt, pret, moneda, email, nrtel, judet, localitate)
      VALUES
      ('".$_POST['titluanunt']."','".$_POST['nume']."','".$_POST['categorie']."','".$_POST['sunteti']."','".$_POST['textanunt']."','".$_POST['pret']."','".$_POST['moneda']."','".$_POST['email']."','".$_POST['nrtel']."','".$_POST['judet']."','".$_POST['localitate']."')";

      if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }
      echo "1 record added";
    }
    else echo 'Date POST ne primite';

    mysql_close($con);
    ?>
FORMULAR.PHP

Cod: Selectaţi tot

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {color: #CC0000}
-->
</style>
</head>

<body>
<table width="94%" border="1" align="center">
<form action="insert.php" method="post" enctype="multipart/form-data">
  <tr>
    <td width="16%"><div align="right">Nume de contact: </div></td>
    <td colspan="6"><input type="text" name="nume" />
      Sunteti:
        <input type="radio" name="sunteti" value="Persoana" />
Persoana
<input type="radio" name="sunteti" value="Companie" />
Companie
<label></label>&nbsp;</td>
    </tr>
  <tr>
    <td><div align="right">Categorie Anunt: </div></td>
    <td colspan="6"><select name="categorie">
<option value="Afaceri">Afaceri</option>
<option value="Articole">Articole</option>
<option value="Animale">Animale</option>
<option value="Anticariat">Anticariat</option>
<option value="Arta-Antichitati">Arta si Antichitati</option>
<option value="Auto">Auto</option>
<option value="Calculatoare">Calculatoare</option>
<option value="Colectii">Colectii</option>
<option value="Constructii">Constructii</option>
<option value="Diverse">Diverse</option>
<option value="Donatii">Donatii</option>
<option value="Electrice">Electrice</option>
<option value="Foto">Foto</option>
<option value="Hobby">Hobby</option>
<option value="Imobiliare">Imobiliare</option>
<option value="Locuri-de-munca">Locuri de munca</option>
<option value="Moda">Moda</option>
<option value="Mobilier">Mobilier</option>
<option value="Moto-Velo">Moto Velo</option>
<option value="Media-Publicitate">Media Publicitate</option>
<option value="Muzica">Muzica</option>
<option value="Pierderi-Gasiri">Pierderi Gasiri</option>
<option value="Servicii">Servicii</option>
<option value="Sport">Sport</option>
<option value="Turism">Turism</option>
<option value="Telefoane">Telefoane</option>


</select>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Titlu Anunt: </div></td>
    <td colspan="6"><input type="text" name="titluanunt" maxlength="87" />&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Text Anunt: </div></td>
    <td colspan="6"><input type="text" name="textanunt" maxlength="255" />&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Pret:</div></td>
    <td width="19%"><input type="text" name="pret"/>&nbsp;</td>
    <td width="11%">(<span class="style1">doar numere</span>) </td>
    <td width="7%"><div align="right">Moneda:</div></td>
    <td colspan="3"><select name="moneda">
<option value="RON">RON</option>
<option value="EUR">EUR</option>
<option value="USD">USD</option>

</select></td>
    </tr>
  <tr>
    <td><div align="right">Adresa e-mail:</div></td>
    <td colspan="6"><input type="text" name="email"/>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Numar de telefon:</div></td>
    <td colspan="6"><input type="text" name="nrtel"/>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Judet:</div></td>
    <td colspan="6"><select name="judet">
<option value="Alba">Alba</option>
<option value="Arad">Arad</option>
<option value="Arges">Arges</option>
<option value="Bacău">Bacău</option>
<option value="Bihor">Bihor</option>
<option value="Bistrita-Nasaud">Bistrita-Nasaud</option>
<option value="Botosani">Botosani</option>
<option value="Brăila">Brăila</option>
<option value="Brasov">Brasov</option>
<option value="Buzău">Buzău</option>
<option value="Călărasi">Călărasi</option>
<option value="Caras-Severin">Caras-Severin</option>
<option value="Cluj">Cluj</option>
<option value="Constanta">Constansa</option>
<option value="Covasna">Covasna</option>
<option value="Dâmbovita">Dâmbovita</option>
<option value="Dolj">Dolj</option>
<option value="Galati">Galati</option>
<option value="Giurgiu">Giurgiu</option>
<option value="Gorj">Gorj</option>
<option value="Harghita">Harghita</option>
<option value="Hunedoara">Hunedoara</option>
<option value="Ialomita">Ialomita</option>
<option value="Iasi">Iasi</option>
<option value="Ilfov">Ilfov</option>
<option value="Maramures">Maramures</option>
<option value="Mehedinti">Mehedinti</option>
<option value="Mures">Mures</option>
<option value="Neamt">Neamt</option>
<option value="Olt">Olt</option>
<option value="Prahova">Prahova</option>
<option value="Sălaj">Sălaj</option>
<option value="Satu Mare">Satu Mare</option>
<option value="Sibiu">Sibiu</option>
<option value="Suceava">Suceava</option>
<option value="Teleorman">Teleorman</option>
<option value="Timis">Timis</option>
<option value="Tulcea">Tulcea</option>
<option value="Vaslui">Vaslui</option>
<option value="Vâlcea">Vâlcea</option>
<option value="Vrancea">Vrancea</option>
</select>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Localitate:</div></td>
    <td colspan="6"><input type="text" name="localitate"/>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right"></div></td>
    <td colspan="6"><input type="submit" name="Submit" value="Submit" />&nbsp;</td>
  </tr>
  </form>
</table>
</body>
</html>
Unde am gresit?cand dau run imi zice Error: Unknown column 'nrtel' in 'field list'
daca sterg <input type="text" name="nrtel"/>
imi da eroarea Date POST ne primite

MarPlo Mesaje:4343
Eroarea este de la MySQL, ori acea coloana nu exista in tabel, ori adaugi in ea date cu un tip diferit decat este ea creata.
De exemplu, daca e creata ca numeric, INT(), dar adaugi in ea un sir (orice caracter sau numar intre ghilimele), da eroare.
Incearca sa adaugi variabila fara a fi delimitata de ghilimelele simple (numerele se adauga fara ghilimele).
Adica, in loc de: "... ,'".$_POST['nrtel']."', ..." sa fie: "... ,".$_POST['nrtel'].", ..." .

evident Mesaje:168
daca iti spun care a fost problema...:))
nu aveam nrtel in baza de date:D
acum as vrea daca ai un link cu un tutorial unde sa ma uit sa vad cum sa fac alea cu erori
daca bag un text mai mic de 2 caractere sa dea eroare,daca baga un format de email necorespunzator sa dea eroare,daca la pret baga text sa ii dea eroare etx
Multumesc

MarPlo Mesaje:4343

evident Mesaje:168
am citit tutorialele alea si sper sa reusesc sa fac si eu acelasi lucru in zilele urm.
acum as avea alta intrebare
de exemplu daca vreau sa fac un formular cu mai multe randuri...pe fiecare rand sa am un drop down din care sa selectez ceva
daca eu vreau sa selectez ceva din randul doi de drop down sa nu ma lase pana nu am selectat din primul
sper ca m-ai inteles:D
Multumesc

MarPlo Mesaje:4343
Se face cu JavaScript, sunt cateva etape si verficari JavaScript de facut si nu se potriveste cu subiectul acestui topic.
Poti studia lectiile si tutorialele JS de pe site, si din alte surse, apoi postezi unde anume nu te descurci in codul pe care-l faci.

Subiecte similare