Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I can't insert data from forms in the database...

    Help me please!

    I'm portuguese informatic girl and I need some help please!!

    It gives the following error:
    Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\formularios\inserir_clientes.php on line 105

    Here is my code:
    (NOTE: The variables names are in portuguese...)
    <?php
    $cod_cliente = $_POST['cod_cliente'];
    $nome = $_POST['nome'];
    $morada = $_POST['morada'];
    $localidade = $_POST['localidade'];
    $cod_postal = $_POST['cod_postal'];
    $telefone = $_POST['telefone'];
    $fax = $_POST['fax'];
    $e_mail = $_POST['e_mail'];
    $prazo_pagamento = $_POST['prazo_pagamento'];
    $desc = $_POST['desc'];
    $num_contribuinte = $_POST['num_contribuinte'];
    $pessoa_contacto = $_POST['pessoa_contacto'];
    $utilizador = $_POST['utilizador'];
    $password = $_POST['password'];
    if (!$cod_cliente || !$nome || !$morada|| !$localidade || !$cod_postal || !$telefone || !$fax ||!$e_mail || !$prazo_pagamento || !$desc || !$num_contribuinte || !$pessoa_contacto || !$utilizador || !$password) {
    echo '<p align=center>Campos em falta.
    <a href="inserir_clientes.html">Volte atrás</a> e tente de novo.'; exit;}

    $ligax = mysql_connect('localhost', 'root','');
    if (!$ligax)
    {echo '<p> Erro: Falha na ligação.'; exit;}
    mysql_select_db($ligax, 'joana');
    line 105 ----->$insert = "insert into 'cad_clientes' values ('"$cod_cliente"','"$nome"','"$morada"','"$localidade"','"$cod_postal"','"$telefone"','"$fax"','"$pr azo_pagamento"','"$desc"','"$num_contribuinte"','"$pessoa_contacto"','"$utilizador"','"$password"')" ;
    $result = mysql_query($ligax, $insert);
    if ($result==1) echo "<p>Dados inseridos<br>";
    else "<p>Dados não inseridos<br>";
    ?>

    It was a time that it didn't give any error but it didn't insert the data in the db either.~
    Can anyone help me please?? I need this 'till sunday!! Please, please, please!!!
    Thank you very much
    Kisses 4 all
    Kitalouka

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Which line is 105?

  • #3
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Ok well I looked at it, and I've escaped all your speech marks and that seemed to do it, you don't really need the speech marks though, also I saw this "$pr azo_pagamento" and I didn't know if that is meant to be there? Anyhow so I left it.. but there is no longer a PHP error. At the last line you've got else "<p>Dados não inseridos<br>"; are you meant to echo that? also I'll use html entities to make it use escape characters. valid.

    Code:
    <?php
    $cod_cliente = $_POST['cod_cliente'];
    $nome = $_POST['nome'];
    $morada = $_POST['morada'];
    $localidade = $_POST['localidade'];
    $cod_postal = $_POST['cod_postal'];
    $telefone = $_POST['telefone'];
    $fax = $_POST['fax'];
    $e_mail = $_POST['e_mail'];
    $prazo_pagamento = $_POST['prazo_pagamento'];
    $desc = $_POST['desc'];
    $num_contribuinte = $_POST['num_contribuinte'];
    $pessoa_contacto = $_POST['pessoa_contacto'];
    $utilizador = $_POST['utilizador'];
    $password = $_POST['password'];
    if (!$cod_cliente || !$nome || !$morada|| !$localidade || !$cod_postal || !$telefone || !$fax ||!$e_mail || !$prazo_pagamento || !$desc || !$num_contribuinte || !$pessoa_contacto || !$utilizador || !$password) {
    echo '<p align=center>Campos em falta.
    <a href="inserir_clientes.html">Volte atrás</a> e tente de novo.'; exit;}
    
    $ligax = mysql_connect('localhost', 'root','');
    if (!$ligax)
    {echo '<p> Erro: Falha na ligação.'; exit;}
    mysql_select_db($ligax, 'joana');
    $insert = "insert into 'cad_clientes' values ('\"$cod_cliente\"','\"$nome\"','\"$morada\"','\"$localidade\"','\"$cod_postal\"','\"$telefone\"','\"$fax\"','\"$pr azo_pagamento\"','\"$desc\"','\"$num_contribuinte\"','\"$pessoa_contacto\"','\"$utilizador\"','\"$password\"')";
    $result = mysql_query($ligax, $insert);
    if ($result==1) echo "<p>Dados inseridos<br>";
    else "<p>Dados não inseridos<br>";
    ?>

  • #4
    New to the CF scene
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It still doesn't work mate...Now it's giving me this errors:
    Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\formularios\inserir_clientes.php on line 104

    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\formularios\inserir_clientes.php on line 106

    mysql_select_db($ligax, 'joana'); --->(line 104)
    $result = mysql_query($ligax, $insert); ---->(line 106)

    If you could help me once again It would be great!!
    Thank you!!
    Kisses

  • #5
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Shouldnt that be
    PHP Code:
    mysql_select_db('joana'$ligax); --->(line 104)
    $result mysql_query($insert$ligax); ---->(line 106
    ?

  • #6
    New to the CF scene
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you!! It doesn't give any error now!!
    But It still won't insert the data...I'll post the code again:
    <?php
    $cod_cliente = $_POST['cod_cliente'];
    $nome = $_POST['nome'];
    $morada = $_POST['morada'];
    $localidade = $_POST['localidade'];
    $cod_postal = $_POST['cod_postal'];
    $telefone = $_POST['telefone'];
    $fax = $_POST['fax'];
    $e_mail = $_POST['e_mail'];
    $prazo_pagamento = $_POST['prazo_pagamento'];
    $desc = $_POST['desc'];
    $num_contribuinte = $_POST['num_contribuinte'];
    $pessoa_contacto = $_POST['pessoa_contacto'];
    $utilizador = $_POST['utilizador'];
    $password = $_POST['password'];
    if (!$cod_cliente || !$nome || !$morada|| !$localidade || !$cod_postal || !$telefone || !$fax || !$e_mail || !$prazo_pagamento || !$desc || !$num_contribuinte || !$pessoa_contacto || !$utilizador || !$password) {
    echo '<p align=center>Campos em falta.
    <a href="inserir_clientes.html">Volte atrás</a> e tente de novo.'; exit;}

    $ligax = mysql_connect('localhost', 'root','');
    if (!$ligax)
    {echo '<p> Erro: Falha na ligação.'; exit;}
    mysql_select_db('joana', $ligax);
    $insert = "insert into 'cad_clientes' values ('\"$cod_cliente\"','\"$nome\"','\"$morada\"','\"$localidade\"','\"$cod_postal\"','\"$telefone\"','\ "$fax\"','\"$prazo_pagamento\"','\"$desc\"','\"$num_contribuinte\"','\"$pessoa_contacto\"','\"$utili zador\"','\"$password\"')";
    $result = mysql_query($insert, $ligax);
    if ($result==1) echo "<p>Dados inseridos<br>";
    ?>

    I don't understand what's wrong in here...Please help me again!!
    Thank you so much!!
    Kisses

  • #7
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    well I noticed on the last line, your missing brackets on the if statement, but that should generate an error...

    PHP Code:
    if ($result==1) echo "<p>Dados inseridos<br>" 
    PHP Code:
    if ($result==1) {
       echo 
    "<p>Dados inseridos<br>";

    Maybe you have a typo somewhere, or the database and/or table doesn't actually exist.

  • #8
    New to the CF scene
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What's a typo?? Sorry for my ignorance *blush*

    the database and the table exists, I'm sure of that
    This is really weird...

  • #9
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    If your only doing 1 thing inside an if satement you dont need curly brackets, it just does the code up to the next semi-colon, the curly brackets just groups the lines together. A typo is a misspelling on a computer where someone has typed something in wrong, eg helol should be hello.

    Try putting

    PHP Code:
    echo mysql_error(); 
    at the end of your script.

  • #10
    New to the CF scene
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your tip
    But it still doesn't work...What should I do?
    Thank you

  • #11
    New to the CF scene
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My actual code is the following:

    <?php
    $cod_cliente = $_POST['cod_cliente'];
    $nome = $_POST['nome'];
    $morada = $_POST['morada'];
    $localidade = $_POST['localidade'];
    $cod_postal = $_POST['cod_postal'];
    $telefone = $_POST['telefone'];
    $fax = $_POST['fax'];
    $e_mail = $_POST['e_mail'];
    $prazo_pagamento = $_POST['prazo_pagamento'];
    $desc = $_POST['desc'];
    $num_contribuinte = $_POST['num_contribuinte'];
    $pessoa_contacto = $_POST['pessoa_contacto'];
    $utilizador = $_POST['utilizador'];
    $password = $_POST['password'];
    if (!$cod_cliente || !$nome || !$morada|| !$localidade || !$cod_postal || !$telefone || !$fax || !$e_mail || !$prazo_pagamento || !$desc || !$num_contribuinte || !$pessoa_contacto || !$utilizador || !$password) {
    echo '<p align=center>Campos em falta.
    <a href="inserir_clientes.html">Volte atrás</a> e tente de novo.'; exit;}

    $ligax = mysql_connect('localhost', 'root','');
    if (!$ligax)
    {echo '<p> Erro: Falha na ligação.'; exit;}
    mysql_select_db('joana', $ligax);
    $insert = "Insert into cad_clientes values ('\"$cod_cliente\"','\"$nome\"','\"$morada\"','\"$localidade\"','\"$cod_postal\"','\"$telefone\"','\ "$fax\"','\"$prazo_pagamento\"','\"$desc\"','\"$num_contribuinte\"','\"$pessoa_contacto\"','\"$utili zador\"','\"$password\"')";
    $result = mysql_query($insert, $ligax);
    if ($result==1){
    echo "<p>Dados inseridos<br>";
    }
    ?>

    Can you give me some suggestions? Can you see something wrong??
    Please help!!

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Try this
    PHP Code:
    <?php
    // Get post variables
    $cod_cliente $_POST['cod_cliente'];
    $nome $_POST['nome'];
    $morada $_POST['morada'];
    $localidade $_POST['localidade'];
    $cod_postal $_POST['cod_postal'];
    $telefone $_POST['telefone'];
    $fax $_POST['fax'];
    $e_mail $_POST['e_mail'];
    $prazo_pagamento $_POST['prazo_pagamento'];
    $desc $_POST['desc'];
    $num_contribuinte $_POST['num_contribuinte'];
    $pessoa_contacto $_POST['pessoa_contacto'];
    $utilizador $_POST['utilizador'];
    $password $_POST['password'];

    // If any of the post variables are blank, then die and print out custom message
    if ($cod_cliente == '' || $nome == '' || $morada == '' || $localidade  == '' || $cod_postal  == '' || $telefone  == '' || $fax == '' || $e_mail == '' || $prazo_pagamento == '' || $desc == '' || $num_contribuinte == '' || $pessoa_contacto == '' || !$utilizador == '' || $password == '')
    die(
    '<p align=center>Campos em falta.<a href="inserir_clientes.html">Volte atrás</a> e tente de novo.')

    // Connect to the database, if the connection fails, then die saying error could not connect
    $ligax mysql_connect('localhost''root','') or die('<p> Erro: Falha na ligação.</p>');

    // Select the appropiate database using the $ligax connection or die if database couldn not be selected
    mysql_select_db('joana'$ligax) or die('<p>Could not select database called "joana"');

    // INSERT into the database, if sql statement is in double quotes then no need to use double quotes around variables
    $insert "INSERT INTO cad_clientes values ('$cod_cliente','$nome','$morada','$localidade','$cod_postal','$telefone','$fax','$prazo_pagamento','$desc','$num_contribuinte','$pessoa_contacto','$utili zador','$password')";

    // Run the query, if you get an error it will die telling you the error and the query
    $result mysql_query($insert$ligax) or die('The mysql error was: '.mysql_error().'<br>The query was: '.$sql);

    // Finally to find out if the query returns anything you should use mysql_num_rows(), if 1 echo, if not do nothing
    if (mysql_num_rows($result)==1)
    echo 
    "<p>Dados inseridos<br>";
    ?>
    If that doesn't work then your sql statement is incorrect. Usually sql statements look something like this
    PHP Code:
    $insert "INSERT INTO cad_clientes(fieldname1,fieldname2,fieldname3,fieldname4,fieldname5,fieldname6,fieldname7,fieldname8,fieldname9,fieldname10,fieldname11,fieldname12,fieldname13) values ('$cod_cliente','$nome','$morada','$localidade','$cod_postal','$telefone','$fax','$prazo_pagamento','$desc','$num_contribuinte','$pessoa_contacto','$utilizador','$password')"
    You also had a space in one of your variables in your query.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    New to the CF scene
    Join Date
    Jun 2007
    Location
    Portugal
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much for your help guys!! It was very usefull!!! It works now!!!
    Thank you, thank you very much!!
    Tomorrow I'll defend my project in front of a jury and when I get my result I'll let you know :P
    eheheh
    Thank you all for your time and patience

  • #14
    New Coder
    Join Date
    Jan 2010
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Hey guys. Sorry i have to continue this topic because my code doesn't insert info on my database.. Either it doesn't do anything.. or it simply gives the error

    "The mysql error was: Column count doesn't match value count at row 1"

    I changed it again and again.. Looked up this post over and over and i can't find the solution.

    My actual code is:

    <?php
    $nome = $_POST['nome'];
    $telefone = $_POST['telefone'];
    $e_mail = $_POST['e_mail'];
    $empresa = $_POST['empresa'];

    if ($nome == '' || $telefone == '' || $e_mail == '' || $empresa == ''){
    echo '<p align=center>Campos em falta.
    <a href="adicionar_fornec.html">Clique</a> para voltar e tente de novo.'; exit;}

    $connection = mysql_connect('localhost','root','');

    if (!$connection)
    {echo '<p> Erro: Falha na ligação.'; exit;}

    mysql_select_db('database', $connection);

    $insert = "INSERT INTO fornecedores values ('$nome','$telefone','$e_mail','$empresa')";

    $result = mysql_query($insert, $connection) or die('The mysql error was: '.mysql_error());
    if (mysql_num_rows($result)==1){
    echo "<p>Dados inseridos<br>";
    }
    ?>

    Sorry for bothering and i will apreciate the help.

    Thank You!

  • #15
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You really should have started your own thread for your issue.

    The error you are receiving is pretty self-explanatory. Another way to say it is: "The number of columns you are loading doesn't match the number of columns in the table."


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •