Mysql problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David ©tefiæ

    Mysql problem

    could someone please write the code for read out of the database...

    here is my input code:

    $Host = "localhost" ;
    $User = "david";
    $Password = "david";
    $DBName = "hej";
    $TableName = "text";

    $Link = mysql_connect ($Host, $User, $Password );

    //$db = mysql_select_db ($DBName,$Link)
    $Query = "INSERT into $TableName values ('11','22','33' )";

    print ("The query is:<BR>$Query<P >\n");

    if (mysql_db_query ($DBName, $Query, $Link))

    {
    print ("The query was successfully executed!<BR>\n ");
    }
    else
    {
    print ("The query could not be executed!<BR>\n ");
    {

    mysql_close ($Link);
    }
    }


  • PagCal

    #2
    Re: Mysql problem

    what problem are you having?

    David ©tefiæ wrote:[color=blue]
    > could someone please write the code for read out of the database...
    >
    > here is my input code:
    >
    > $Host = "localhost" ;
    > $User = "david";
    > $Password = "david";
    > $DBName = "hej";
    > $TableName = "text";
    >
    > $Link = mysql_connect ($Host, $User, $Password );
    >
    > //$db = mysql_select_db ($DBName,$Link)
    > $Query = "INSERT into $TableName values ('11','22','33' )";
    >
    > print ("The query is:<BR>$Query<P >\n");
    >
    > if (mysql_db_query ($DBName, $Query, $Link))
    >
    > {
    > print ("The query was successfully executed!<BR>\n ");
    > }
    > else
    > {
    > print ("The query could not be executed!<BR>\n ");
    > {
    >
    > mysql_close ($Link);
    > }
    > }
    >
    >[/color]

    Comment

    • Margaret MacDonald

      #3
      Re: Mysql problem

      David ©tefiæ wrote:
      [color=blue]
      >could someone please write the code for read out of the database...
      >
      >here is my input code:
      >
      >$Host = "localhost" ;
      >$User = "david";
      >$Password = "david";
      >$DBName = "hej";
      >$TableName = "text";
      >
      >$Link = mysql_connect ($Host, $User, $Password );
      >
      >//$db = mysql_select_db ($DBName,$Link)
      >$Query = "INSERT into $TableName values ('11','22','33' )";[/color]

      I don't think this will work, for a start, because you're not
      specifying what the field name is that receives the values you're
      trying to store. If you mean to create 3 new records, try something
      like

      $query = 'INSERT INTO' . $TableName . ' SET
      fieldname="11", fieldname="22", fieldname="33"' ;

      where 'fieldname' is whatever name you gave when you created the table
      with the CREATE TABLE statement.
      [color=blue]
      >
      >print ("The query is:<BR>$Query<P >\n");
      >
      > if (mysql_db_query ($DBName, $Query, $Link))
      >
      > {
      > print ("The query was successfully executed!<BR>\n ");
      > }
      > else
      > {
      > print ("The query could not be executed!<BR>\n ");
      > {
      >
      >mysql_close ($Link);
      >}
      >}
      >[/color]

      To read them back, you would do

      $query = 'SELECT * FROM $TableName' ;
      $dataset = mysql_query( $query, $Link ) ;
      if ( $dataset )
      {
      while( $record = mysql_fetch_ass oc( $dataset ) )
      echo $record['fieldname'] ;
      }

      Did I understand correctly what it was you wanted to know?

      Margaret
      --
      (To mail me, please change .not.invalid to .net, first.
      Apologies for the inconvenience.)

      Comment

      • David''

        #4
        Re: Mysql problem

        i am trying to read data 11, 22 and 33 that i have written to the database.

        "PagCal" <pagcal@runbox. com> wrote in message
        news:10gv1s4a79 tq745@corp.supe rnews.com...[color=blue]
        > what problem are you having?
        >
        > David ©tefiæ wrote:[color=green]
        > > could someone please write the code for read out of the database...
        > >
        > > here is my input code:
        > >
        > > $Host = "localhost" ;
        > > $User = "david";
        > > $Password = "david";
        > > $DBName = "hej";
        > > $TableName = "text";
        > >
        > > $Link = mysql_connect ($Host, $User, $Password );
        > >
        > > //$db = mysql_select_db ($DBName,$Link)
        > > $Query = "INSERT into $TableName values ('11','22','33' )";
        > >
        > > print ("The query is:<BR>$Query<P >\n");
        > >
        > > if (mysql_db_query ($DBName, $Query, $Link))
        > >
        > > {
        > > print ("The query was successfully executed!<BR>\n ");
        > > }
        > > else
        > > {
        > > print ("The query could not be executed!<BR>\n ");
        > > {
        > >
        > > mysql_close ($Link);
        > > }
        > > }
        > >
        > >[/color]
        >[/color]


        Comment

        • David''

          #5
          Re: Mysql problem

          [color=blue]
          > I don't think this will work, for a start, because you're not
          > specifying what the field name is that receives the values you're
          > trying to store. If you mean to create 3 new records, try something
          > like[/color]

          inputing data works. But i cant read what i have written...
          i dont know how to read 11,22 and 33 that i have written to the database.

          David Stefic


          Comment

          • Tim Tyler

            #6
            Re: Mysql problem

            Margaret MacDonald <scratch65536@a tt.not.invalid> wrote or quoted:[color=blue]
            > David ?tefi? wrote:[/color]
            [color=blue][color=green]
            > >could someone please write the code for read out of the database...
            > >
            > >here is my input code:
            > >
            > >$Host = "localhost" ;
            > >$User = "david";
            > >$Password = "david";
            > >$DBName = "hej";
            > >$TableName = "text";
            > >
            > >$Link = mysql_connect ($Host, $User, $Password );
            > >
            > >//$db = mysql_select_db ($DBName,$Link)
            > >$Query = "INSERT into $TableName values ('11','22','33' )";[/color]
            >
            > I don't think this will work, for a start, because you're not
            > specifying what the field name is that receives the values you're
            > trying to store. [...][/color]

            Doing that is not necessary - the supplied code should work fine.
            --
            __________
            |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.

            Comment

            Working...