Help connecting to SQL with php

I am very new to PHP and SQL. I am trying to use the “Build Your Own Database Driven Web Site Using PHP & MySQL, Part 4: Publishing MySQL Data on the Web” article found here: http://articles.sitepoint.com/article/publishing-mysql-data-web

I have everything set up the way shown and I get this error:Fatal error: Call to undefined function mysql_connect()…

Any help will be appreciated. Thanks

I get this…Parse error: syntax error, unexpected ‘}’ in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Welcome2\index.php on line 13

create one php file with this code::
<?php
echo phpinfo();
?>
and run it… for knowing the php version and functionality.

and

<?php
if (!isset($_REQUEST[‘firstname’]))
{
include ‘form.html.php’;
}
else3 // remove 3 here, only else is there

$firstname = $_REQUEST[‘firstname’];
$lastname = $_REQUEST[‘lastname’];
if ($firstname == ‘Kevin’ and $lastname == ‘Yank’)

$output = ‘Welcome, oh glorious leader!’;
}
else
{
$output = 'Welcome to our web site, ’ .
htmlspecialchars($firstname, ENT_QUOTES, ‘UTF-8’) . ’ ’ .
htmlspecialchars($lastname, ENT_QUOTES, ‘UTF-8’) . ‘!’;

include ‘welcome.html.php’;5 // remove 5 here…
}

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head>
<title>Form Example</title>
<meta http-equiv=“content-type”
content=“text/html; charset=utf-8”/>
</head>
<body>
<form action=“” method=“post”> // here give action=“index.php”
<div><label for=“firstname”>First name:
<input type=“text” name=“firstname” id=“firstname”/></label>
</div>
<div><label for=“lastname”>Last name:
<input type=“text” name=“lastname” id=“lastname”/></label>
</div>
<div><input type=“submit” value=“GO”/></div>
</form>
</body>
</html>
if any error comes please specify details…

what about mysqli_connect() problem?
Is it modified.

Give me the specific details of another problem…(you put code but what’s your need to correct it.)

Im also having problems with this code:

<?php    
if (!isset($_REQUEST['firstname']))    
{    
 include 'form.html.php';    
}    
else3    
{    
 $firstname = $_REQUEST['firstname'];    
 $lastname = $_REQUEST['lastname'];    
 if ($firstname == 'Kevin' and $lastname == 'Yank')    
    
   $output = 'Welcome, oh glorious leader!';    
 }    
 else    
 {  
   $output = 'Welcome to our web site, ' .    
       htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' .    
       htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!';    
     
   
 include 'welcome.html.php';5    
}   
?>

I went in to my php.ini file and took out the “;” before both extension=php_mysql.dll,
extension=php_mysqli.dll. And am still getting the same error.

When I run that code I get this error: Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\phpmysql.php on line 4… I ran the code by opening notepad++ and copied your code to it changing the values of the username and password. Should I have added the the <head> and <body> to the page or would it matter since it was only php?

Where would I find the “output phpinfo ()”?

Actual method is like this::
YOu are not choosen the database name to connect…
$link=mysqli_connect(“localhost”, “database_user”, “database_password”, “database_name”);

Here is the code I have for index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"       
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">       
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">       
 <head>       
   <title>Login</title>       
   <meta http-equiv="content-type"       
       content="text/html; charset=utf-8"/>       
 </head>       
 <body>             
    <?php 
$link = mysqli_connect('localhost', '#####', '#####'); 
if (!$link) 
{ 
 $output = 'Unable to connect to the database server.'; 
 include 'output.html.php'; 
 exit(); 
} 

if (!mysqli_set_charset($link, 'utf8')) 
{ 
 $output = 'Unable to set database connection encoding.'; 
 include 'output.html.php'; 
 exit(); 
} 

if (!mysqli_select_db($link, 'ijdb')) 
{ 
 $output = 'Unable to locate the joke database.'; 
 include 'output.html.php'; 
 exit(); 
} 

$output = 'Database connection established.'; 
include 'output.html.php'; 
?>    
   </p>       
 </body>       
</html>

you miss the ‘{’ after else statement…

<?php
if (!isset($_REQUEST[‘firstname’]))
{
include ‘form.html.php’;
}
else
{ // here you miss open braces
$firstname = $_REQUEST[‘firstname’];
$lastname = $_REQUEST[‘lastname’];
if ($firstname == ‘Kevin’ and $lastname == ‘Yank’)

$output = ‘Welcome, oh glorious leader!’;
}
else
{
$output = 'Welcome to our web site, ’ .
htmlspecialchars($firstname, ENT_QUOTES, ‘UTF-8’) . ’ ’ .
htmlspecialchars($lastname, ENT_QUOTES, ‘UTF-8’) . ‘!’;

include ‘welcome.html.php’;5
}
?>

Please read my last post, I fixed this issue myself yesterday.

Chris

Im using Apache HTTP server 2.2

Are you using WAMP server or any other?

venkat6134: On the other problem I Have three files in a directory that should be a welcome type deal. When I go to “localhost/welcome” I get this error: Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\welcome\index.php on line 8

Here is my index.php file

<?php    
if (!isset($_REQUEST['firstname']))    
{    
 include 'form.html.php';    
}    
else3    
    
 $firstname = $_REQUEST['firstname'];    
 $lastname = $_REQUEST['lastname'];    
 if ($firstname == 'Kevin' and $lastname == 'Yank')    
    
   $output = 'Welcome, oh glorious leader!';    
 }    
 else    
 {  
   $output = 'Welcome to our web site, ' .    
       htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' .    
       htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!';    
     
   
 include 'welcome.html.php';5    
}   
?>

form.html.php file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"    
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">    
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">    
 <head>    
   <title>Form Example</title>    
   <meta http-equiv="content-type"    
       content="text/html; charset=utf-8"/>    
 </head>    
 <body>    
   <form action="" method="post">    
     <div><label for="firstname">First name:    
       <input type="text" name="firstname" id="firstname"/></label>    
     </div>    
     <div><label for="lastname">Last name:    
       <input type="text" name="lastname" id="lastname"/></label>    
     </div>    
     <div><input type="submit" value="GO"/></div>    
   </form>    
 </body>    
</html>

and welcome.html.php file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"    
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">    
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">    
 <head>    
   <title>Form Example</title>    
   <meta http-equiv="html/php"    
       content="text/html; charset=utf-8"/>    
 </head>    
 <body>    
   <p>    
     <?php echo $output; ?>    
   </p>    
 </body>    
</html>

I think I am getting a little better but still get this error. I am trying to to do all of this off of this article: http://articles.sitepoint.com/article/mysql-3-getting-started-php/4

You can see the syntax of mysqli_connect()::::

http://www.phpbuilder.com/manual/en/function.mysqli-connect.php

Make changes if any wrong…

Yes after i made and saved the changes in the: php.ini file I restarted the server I also completely took it off line and started it again. I am still getting this error-- Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\connect.php on line 11

dxm3119, with regard to your first problem, did you restart the server? The server has to be restarted for the changes to take effect.

The part of the code posted by dxm3119 for selecting the database is:

if (!mysqli_select_db($link, 'ijdb')) 
{ 
 $output = 'Unable to locate the joke database.'; 
 include 'output.html.php'; 
 exit(); 
} 

dxm3119, in your php.ini file look for these two lines:

extension=php_mysql.dll
extension=php_mysqli.dll

If they have a ; remove the ; from the start of them two lines, save the file then restart the server.

Try running this (substituting “db_user_name” and “db_password” for the appropriate values:

 <?php
$apache_version            = $_SERVER['SERVER_SOFTWARE'];
$php_version            = phpversion();
$link                    = mysqli_connect("localhost", "db_user_name", "db_password");
$mysql_server_version    = mysqli_get_server_info($link);

echo "
    <p>Apache (Version: $apache_version) is running the following versions of PHP and MySQL:</br>
    PHP: $php_version</br>
    MySQL: $mysql_server_version</p>
    ";
?>  

If it doesn’s display the MySQL server version then there is something amiss with the PHP’s MySQLi extension.

In the output of phpinfo() do you have a section for mysqli?