Jump to content

MySql Connect [ERROR]


Recommended Posts

MySql error:
[quote]Fatal error: Call to undefined function: mysql_connect() in /website/create.php on line 18[/quote]
and "Line 18" is this:
[code]$db = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');[/code]

now i followed a tutorial exactly, and i still get this error.
also, i have specified the uname, pass, and host, and database and all, and trippple checked it all, and it's correct.

here is all my code:
[code]<?php
if(isset($_POST['add']))
{
$dbhost = '(my host goes here)';
$dbuser = '(my username goes here)';
$dbpass = '(my pass goes here)';
$dbname = '(my database name goes here)';

$db = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$username = $_POST['username'];
$password = $_POST['password'];

$query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', '$username', PASSWORD('$password'), 'Y', 'Y', 'Y')";
mysql_query($query) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

mysql_close($db);
echo "New MySQL user added";
}
else
{
?>

<form method="post">
<input name="username" type="text" id="username">
<input name="password" type="text" id="password">
<input name="add" type="submit" id="add" value="Add New User">
<?php
}
?>[/code]

little help?
Link to comment
Share on other sites

[quote author=mgallforever link=topic=116489.msg474616#msg474616 date=1164657870]
try using double quotes instead of single quotes while defining your host,user,pass and dbname
[/quote]
That wont make a single difference ;)

The problem is because you dont have the mysql extension enabled. Please read the thread titled "[b]Call To Undefinded Function mysql_connect[/b]" in the [url=http://www.phpfreaks.com/forums/index.php/board,41.0.html]FAQ/Code Snippet Repository[/url] forum. Should be able help you.

Note: that FAQ is for Windows only.

If you are on a linux based OS then you'll need to recompile PHP the --with-mysql=path/mysql/installDir command option
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.