By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Insert Query through PHP does not insert data into MySQL Table

P: 3
I am using the following code. Why it does not insert record in the MySQL Table through php script:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbhost='localhost';
  3. $dbuser='root';
  4. $dbpass='newpass';
  5. $mysqldb='mysql';
  6.  
  7. if(isset($_POST['add'])){
  8.  
  9. $username=$_POST['username']; // echo test for $username is OK
  10. $password=$_POST['password']; // echo test for $password is OK
  11.  
  12. $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting MySQL'); mysql_select_db($mysqldb) or die ('Error connecting database');
  13.  
  14. $query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', '$username', PASSWORD ('password'), 'Y', 'Y', 'Y')";
  15.  
  16. //more code to close database and html form
  17. ?>
Plz help me regarding this.

Regards
Dec 9 '07 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Servo.

You need to execute your query using mysql_query().

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]
Dec 9 '07 #2

pbmods
Expert 5K+
P: 5,821
While you're at it, check out this article for more information on creating MySQL User accounts.
Dec 9 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.