Jump to content

need help in connecting mysql using php


devarmagan

Recommended Posts

iam inserting a new record in php and iam gertting a error while connecting to mysql  the error msg is
"Fatal error: Call to undefined function mysql_connect() in C:\webs\test\insert.php on line 2"

while iam configuring the the mysql i9 have given username and password admin and admin
is that the way
please help me

[code]<?php
$con = mysql_connect('localhost','admin','admin');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("my_db", $con);$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";mysql_close($con)
?>[/code]

Link to comment
https://forums.phpfreaks.com/topic/23993-need-help-in-connecting-mysql-using-php/
Share on other sites

Run the following functoin in a script:
[code]<?php
phpinfo();
?>[/code]

Do you get a mysql or a mysqli section? If you dont make sure PHP is using the correct php.ini by checking the line that starts with [b]Configuration File (php.ini) Path[/b]. Also turn on the [b]display_startup_errors[/b] too in the php.ini to see if PHP is loading up okay.

Also make sure that you restart your server whenever you make any changes to the php.ini!
Here's the phpinfo code - just put this into a template foo.php in your webroot and then browse to it.  You'll get several pages of information.

<?php
phpinfo();
?>

In php.ini do you have the following WITHOUT ; in front of them?

display_errors = On
display_startup_errors = On
doc_root = c:\inetpub\wwwroot  (or whatever it is)
extension_dir = "C:\PHP\ext" (or whatever it is)
extension=php_mysql.dll
extension=php_mysqli.dll - (one or both, depending on which type of MySQL you want to use)

If you're running IIS, you'll also need the Windows versions of php_mysql.dll or php_mysqli.dll (which go into your "extentions" directory, as above) and libmysql.dll, which goes into your PHP directory.  You can get them from php.net.

Hope this helps.
yes now connecting but again iam getting an error

this is the code iam  runing

[code]<?php
$con = mysql_connect('localhost','root','admin');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("my_db", $con);$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";mysql_close($con)
?>[/code]


"error msg"

Error: No database selected

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.