Data Input

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Quijote

    Data Input

    Hello
    with this script I need to show the user (utenti) list and after I need to
    input in the table RICHIESTA the field COGNOME e NOME.
    This is the code but don't go. Someone can tell me where is the mistake???
    Many Thanks!!


    <select name="user" id="user">
    <?
    $q= mysql_query("se lect * from utenti order by user");
    while ($res=mysql_fet ch_array($q))
    {
    echo "<OPTION VALUE=\"$res[user]\">$res[user] --
    $res[reparto]</OPTION>";
    }
    mysql_free_resu lt($q);

    $rs = mysql_query("SE LECT * FROM utenti WHERE user = ".$user);

    $cognome = mysql_result($r s, 0, "cognome");
    $nome = mysql_result($r s, 0, "nome");
    mysql_query("IN SERT INTO richiesta (cognome,nome) VALUES
    ($cognome,$nome )");
    ?>
    </select>


  • Pedro Graca

    #2
    Re: Data Input

    Quijote wrote:[color=blue]
    > with this script I need to show the user (utenti) list and after I need to
    > input in the table RICHIESTA the field COGNOME e NOME.[/color]
    [color=blue]
    > <select name="user" id="user">
    > <?
    > $q= mysql_query("se lect * from utenti order by user");[/color]
    (snip)


    Do some error-checking in your scripts!

    For a SQL select action I do:

    <?php
    $conn = mysql_connect($ host, $user, $pass)
    or die('Impossible to connect to '.$host.' now: '.mysql_error() );
    $sql = 'select * from utenti order by user';
    $q = mysql_query($sq l)
    or die('Error '.mysql_error() .' in query '.$sql);
    while ($res = mysql_fetch_arr ay($q)) {
    /* whatever */
    }
    // ...
    ?>

    This way, if there's an error connecting or in the select string I get
    feedback about it.

    In your second query to the "utenti" table you are using a variable
    named $user. Where did it come from?
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Quijote

      #3
      Re: Data Input


      "Pedro Graca" <hexkid@hotpop. com> ha scritto nel messaggio
      news:c0admo$157 j5i$1@ID-203069.news.uni-berlin.de...[color=blue]
      >
      > In your second query to the "utenti" table you are using a variable
      > named $user. Where did it come from?
      > --[/color]

      Thanks Pedro, in the code there is a mistake the right line is

      $rs = mysql_query("SE LECT * FROM utenti WHERE user=".$_POST[user]);


      Comment

      • Quijote

        #4
        Re: Data Input


        "Pedro Graca" <hexkid@hotpop. com> ha scritto nel messaggio
        news:c0admo$157 j5i$1@ID-203069.news.uni-berlin.de...[color=blue]
        >
        > Do some error-checking in your scripts!
        >
        > For a SQL select action I do:
        >
        > <?php
        > $conn = mysql_connect($ host, $user, $pass)
        > or die('Impossible to connect to '.$host.' now: '.mysql_error() );
        > $sql = 'select * from utenti order by user';
        > $q = mysql_query($sq l)
        > or die('Error '.mysql_error() .' in query '.$sql);
        > while ($res = mysql_fetch_arr ay($q)) {
        > /* whatever */
        > }
        > // ...
        > ?>
        >[/color]

        Thanks, the problem for me is not to list the users (utenti) this is
        possible but the problem is to update the fields COGNOME and NOME that are
        in table UTENTI and I need to fill in table RICHIESTA connecting the posted
        user with the table UTENTI ... I hope it's clear :-). Many many thanks again
        ....


        Comment

        • Pedro Graca

          #5
          Re: Data Input

          Quijote wrote:[color=blue]
          > "Pedro Graca" <hexkid@hotpop. com> ha scritto nel messaggio
          > news:c0admo$157 j5i$1@ID-203069.news.uni-berlin.de...[color=green]
          >> Quijote wrote:[color=darkred]
          >>>
          >>> $rs = mysql_query("SE LECT * FROM utenti WHERE user = ".$user);
          >>>
          >>> $cognome = mysql_result($r s, 0, "cognome");
          >>> $nome = mysql_result($r s, 0, "nome");
          >>> mysql_query("IN SERT INTO richiesta (cognome,nome) VALUES ($cognome,$nome )");[/color]
          >>
          >> Do some error-checking in your scripts![/color][/color]

          Do some error-checking in your scripts!
          [color=blue][color=green][color=darkred]
          >>> $rs = mysql_query("se lect * from utenti where user=".$_POST["user"]);[/color][/color][/color]

          Are you sure? Why not doing some error-checking? :)
          I guess $_POST["user"] is a string, and as such, should be enclosed in
          single quotes.
          [color=blue][color=green][color=darkred]
          >>> mysql_query("IN SERT INTO richiesta (cognome,nome) VALUES ($cognome,$nome )");[/color][/color][/color]

          Are you sure? Why not doing some error-checking? :-))
          Don't $cognome and $nome need to be enclosed in single quotes?
          [color=blue]
          > Thanks, the problem for me is not to list the users (utenti) this is
          > possible but the problem is to update the fields COGNOME and NOME that are
          > in table UTENTI and I need to fill in table RICHIESTA connecting the posted
          > user with the table UTENTI ... I hope it's clear :-). Many many thanks again[/color]

          It helps to do error-checking.

          Ii does not hurt your script noticeably (if at all) and it is a great
          tool to aid in debugging when something goes wrong.


          Happy Coding :-)
          --
          --= my mail box only accepts =--
          --= Content-Type: text/plain =--
          --= Size below 10001 bytes =--

          Comment

          Working...