Results 1 to 4 of 4

Thread: insert query

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    16
    ΑΡ Credit
    160

    insert query

    slaam.... there is problem in my insert query..it is not working..and i am not able to find any error..


    PHP Code:
       <?php

    $dbconn
    =mysql_connect("localhost","root","") or die ("cannot connect to host");
    $mydb=mysql_select_db("madiha",$dbconn) or die ("cannot connect to database");
    $myquery="select * from mytab";
    $insert="insert into mytab(rollno,name,marks,city)values (3,xyz,80,multan)";
    mysql_query($insert);
    $resultset=mysql_query($myquery,$dbconn);



    while(
    $row=mysql_fetch_array($resultset))
    {

    echo
    "<br> rollno:".$row{0};
    echo
    "<br> name:".$row{1};
    echo
    "<br> marks:".$row{2};
    echo
    "<br> city:".$row{3};
     echo 
    "<hr>";
    }




    ?>

  2. #2
    Administrator AP admin's Avatar
    Join Date
    Jul 2010
    Posts
    103
    ΑΡ Credit
    1030
    I don't know what you're trying to do with that whole code.
    But as far Insert query is concerned, give space before keyword 'values' and remove space after it. add quotes around strings.
    PHP Code:
    $insert="insert into mytab(rollno,name,marks,city) values(3,'xyz',80,'multan')"
    last thing, make sure that if the column 'rollno' is set to have unique values or is primary key then there should not exist the row with the value for rollno which you're going to insert in table.

    in above code, no row with rollno 3 should exist in table.

    BTW, you forgot roll no 1 and 2?

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    2
    ΑΡ Credit
    20
    You can also use the "set" attribute. Its easier.

    $insert="insert into mytab set rollno=3,name=xyz,marks=80,city=multan";

  4. #4
    Administrator AP admin's Avatar
    Join Date
    Jul 2010
    Posts
    103
    ΑΡ Credit
    1030
    Quote Originally Posted by Wicked6 View Post
    You can also use the "set" attribute. Its easier.

    $insert="insert into mytab set rollno=3,name=xyz,marks=80,city=multan";
    Yes that query should also work ... but keep values between quotes..

Similar Threads

  1. Is it necessary to insert keyword in the post to get traffic?
    By Malcolm in forum Search Engines Talk
    Replies: 6
    Last Post: 09-07-2018, 07:25 AM
  2. Why coupon codes website and my query is falling down?
    By Lienia henna in forum Search Engines Talk
    Replies: 1
    Last Post: 12-04-2013, 07:28 AM
  3. Replies: 1
    Last Post: 11-13-2013, 08:33 AM
  4. sql query to find and update
    By Jennifer in forum Database Administration
    Replies: 0
    Last Post: 12-31-2011, 05:02 PM
  5. Query optimization in MySQL
    By Meer in forum Database Administration
    Replies: 0
    Last Post: 10-20-2010, 09:47 AM

Posting Permissions

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