1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem Add Data Into Database (Mysql)

Discussion in 'PHP' started by Sasikumar, Mar 17, 2008.

  1. Sasikumar

    Sasikumar Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #21
    its working now.. i have dbconnection file the coding is as below

    <?
    mysql_connect("localhost", "database", "password") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());
    ?>

    i want include this file in ur coding. but it seems not working, plz guide me
     
    Sasikumar, Mar 17, 2008 IP
  2. deepak3018

    deepak3018 Peon

    Messages:
    353
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #22
    replace these two lines from my code...

    $conns=mysql_connect("localhost", "root", "root") or die(mysql_error());
    mysql_select_db("webzwork_red") or die(mysql_error());


    and put there these lines

    $conns=mysql_connect("localhost", "database", "password") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());
     
    deepak3018, Mar 18, 2008 IP
  3. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #23
    he can use 'text' as many times as he wants ..because its the type="text"
    telling the <input> what type of data is used

    At the beginning of this thread, you posted your username and password to database in your connect file perhaps.


    when putting the data into the databasefields
    instead of saying WHERE 'users' ... try to be more specific.

    if you had a form with say first_name , last_name, and email

    mysql_query ("INSERT INTO users (first_name, last_name, email ) VALUES ( '$first_name', '$last_name', '$email' )") or trigger_error('Error with insert: '.mysql_error(),FATAL) ;

    Tell it WHERE its putting them in the 'users' table
    so that the names of the fields in your database match

    so say you had a database with: First_Name , Last_Name, Email

    then you would do it like this mysql_query ("INSERT INTO users (First_Name, Last_Name, Email ) VALUES ( '$first_name', '$last_name', '$email' )") or trigger_error('Error with insert: '.mysql_error(),FATAL) ;

    doesnt matter as long as the fields coorespond in linear order to the right variables - but its better practice to make them match exactly..so theres no problems
     
    ezprint2008, Mar 18, 2008 IP
  4. rnilucero

    rnilucero Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #24
    you got no problem on your form, the problem is that you forgot to add fields,
    like insert into table(FIELD1,FIELD2,FIELDn) values('$var1','$var2','$varN'); :)
     
    rnilucero, Mar 19, 2008 IP