Jump to content

Archived

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

devarmagan

need help in connecting mysql using php

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]

Share this post


Link to post
Share on other sites
Please read this [url=http://www.phpfreaks.com/forums/index.php/topic,95378.0.html]thread[/url]

You need to enable the mysql extension in the php.ini in order to use the mysql functions for PHP.

Share this post


Link to post
Share on other sites
Well, the extension is not properly installed, then.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites
Is that the correct path (C:\PHP\) to php.ini? and did you turn on display_startup_errors too?

Share this post


Link to post
Share on other sites
No the server, as in the server software (not hardware). Restart IIS, Apache or whatever you server software is.

Share this post


Link to post
Share on other sites
Why don't you post the output of phpinfo()?

Share this post


Link to post
Share on other sites
wildteen88 suggested that you dump phpinfo() to see how the configuration variables were defined; just cut & paste.

Share this post


Link to post
Share on other sites
I believe that your link above contains the necessary configuration details; however, I'm not a PHP expert, nor do I know how it should "look".  Wildteen?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.