Insert Query through PHP does not insert data into MySQL Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • servo
    New Member
    • Nov 2007
    • 3

    #1

    Insert Query through PHP does not insert data into MySQL Table

    I am using the following code. Why it does not insert record in the MySQL Table through php script:
    [code=php]
    <?php
    $dbhost='localh ost';
    $dbuser='root';
    $dbpass='newpas s';
    $mysqldb='mysql ';

    if(isset($_POST['add'])){

    $username=$_POS T['username']; // echo test for $username is OK
    $password=$_POS T['password']; // echo test for $password is OK

    $conn=mysql_con nect($dbhost, $dbuser, $dbpass) or die ('Error connecting MySQL'); mysql_select_db ($mysqldb) or die ('Error connecting database');

    $query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', '$username', PASSWORD ('password'), 'Y', 'Y', 'Y')";

    //more code to close database and html form
    ?>[/code]

    Plz help me regarding this.

    Regards
    Last edited by pbmods; Dec 9 '07, 06:05 PM. Reason: Added CODE tags.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Servo.

    You need to execute your query using mysql_query().

    Please use CODE tags when posting source code:

    &#91;CODE=ph p]
    PHP code goes here.
    &#91;/CODE]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      While you're at it, check out this article for more information on creating MySQL User accounts.

      Comment

      Working...