Why i can't connect to my database??

Links for php scripts

Moderators: macek, egami, gesf

User avatar
x_sky58
New php-forum User
New php-forum User
Posts: 49
Joined: Thu Jun 16, 2005 5:38 am
Contact:

Why i can't connect to my database??

Postby x_sky58 » Tue Jul 12, 2005 1:35 am

When i open click on submit button,then the browser pop out this message:

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\dbconnect.php on line 2

this is the index file'code (file name:sign.php):

Code: Select all

<HTML>
<TITLE>let's sign in</TITLE>
<HEAD
<BODY>
<h2>Sign in to myt guestbook!</h2>

<form method=post action="create_entry.php">

<b>Name:</b>
<input type=text size=40 name=name>
<br>
<b>Location:</b>
<input type=text size=40 name=location>
<br>
<b>Email:</b>
<input type=text size=40 name=email>
<br>
<b>Home page URL:</b>
<input type=text size=40 name=url>
<br>
<b>Comments:</b>
<textarea name=comments cols=40 rows=4 wrap=virtual></textarea>
<br>

<input type=submit name=submit value="Submit">
<input type=reset name=reset value="Reset">

</form>


then the create_entry.php code:

Code: Select all

<?php include("dbconnect.php");

if($submit=="Submit")
{
  $query="insert into guestbook
  (name,location,email,url)values
  ('$name','$location','$email','$url')"
  ;
  mysql_query($query) or
  die (mysql_error());
?>
<h2>Thanks</h2>
<h2><a href="view.php">View my guestbook!</a></h2>
<?php
}
else
{
  include("sign.php");
 
}

?>


then dbconnect.php code:

Code: Select all

<?php
mysql_connect("localhost","guestbook","mysql") or
    die ("Could not connect to database");
mysql_select_db("guestbook") or
    die ("Could not select database");

?>


any teacher,please help me to solve this problem...

thank you......[/code]

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

Postby Alexej Kubarev » Tue Jul 12, 2005 2:05 am

easy: you simply need to enable php_mysql.dll in your php.ini extention section :)

User avatar
crm881125
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jun 22, 2011 6:06 am

Re: Why i can't connect to my database??

Postby crm881125 » Wed Jun 22, 2011 6:18 am

I have the same problem as above
I enabled the :
    extension=php_gd2.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll

and they are all in my extension folder : c:\php\ext

but it's still giving me :
Fatal error: Call to undefined function mysql_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\DB exercies\lib\opendb.php on line 2

My index file is :
Sql-insert.php

Code: Select all

<?php

include 'lib/config.php';

include 'lib/opendb.php';



$user_name = $_POST['user_name'];

$passwd = $_POST['passwd'];



//echo $user_name;

//echo $passwd;



//This script will insert the data to the user table

//you may keep some fields blank



$sql = "INSERT INTO User (User_Name,Passwd) Values ('$user_name','$passwd')";

$result = mysql_quarry($sql) or die ('quarry failed. '.mysql_error());

echo "Insert done";

include 'lib/closedb.php';

?>



</html>

<body>

<form name="select" action=" " method="post">



User Name <input name="user_name" type="text" />

<br />



Password <input name="passwd" type="text" />

<br />



<input name="button1" type="submit" value="Insert" />

</form>

</body>

</html>


and the included files are :
config.php

Code: Select all

<?php

//db properties



$dbhost = "localhost";

$dbuser = "root";

$dbpass = "test";

$dbname = "sql_exercises";

?>


opendb.php

Code: Select all

<?php

$conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('I cannot connect to  the database becouse: '. mysql_error());

mysql_select_db ($dbname);

?>


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron