|
-
Mar 8th, 2007, 08:22 PM
#1
Thread Starter
Member
why doesn't the text appear in browseR? HELP NEEDED!
why doesnt the text "success" appear in the browser? when i execute this code, they did not give me any error message, instead they just give me a blank screen. issit probably because of my connection to MYSQL? or issit there is something wrong with the code?
These are the codes i am referring to.
<?
$connection = mysql_connect("localhost", "lina", "lina") or die (mysql_error());
if ($connection){
$msg = "success!";
}
?>
<html>
<head>
<title>MY SQL</title>
</head>
<body>
<?echo "$msg"; ?>
</body>
</html>
-
Mar 8th, 2007, 09:27 PM
#2
Re: why doesn't the text appear in browseR? HELP NEEDED!
is the rest of the code (the HTML you put there) being output? check the source of the page to make sure.
just as a side note: you might want to try it without if() statement to define $msg. since you have an "or die()" statement on your call to mysql_connect(), if there is no connection the script will just end, outputting any errors returned by mysql as to why a connection wasn't made. after your call to mysql_connect(), $connection should always be valid (although, I'm not so sure in this case). you can try this small script instead, which does basically the same thing (from php.net):
PHP Code:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
-
Mar 8th, 2007, 09:47 PM
#3
Thread Starter
Member
Re: why doesn't the text appear in browseR? HELP NEEDED!
i have tried using the code u have given to me. but there is still error. the error statement is this: PHP Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\fypj\lalala.php on line 3.
i have check the username and the password of my mysql database. it is all correct. but why there is an error on that line?
issit probably because there is something i shud do to my MYSQL database or there is something wrong with the code?
-
Mar 8th, 2007, 09:53 PM
#4
Re: why doesn't the text appear in browseR? HELP NEEDED!
looks like you don't have the mysql extension enabled. do you know what version of php you're using?
-
Mar 8th, 2007, 10:01 PM
#5
Thread Starter
Member
Re: why doesn't the text appear in browseR? HELP NEEDED!
i am using PHP version 5. so what should i do to solve the problem?
-
Mar 10th, 2007, 11:44 AM
#6
Re: why doesn't the text appear in browseR? HELP NEEDED!
If you're running PHP locally, the MySQL extension should be enabled by default. However, you might have to enable it manually: in php.ini, add the line (on Windows):
Code:
extension=php_mysql.dll
If you're on a hosted account, ask your administrator to enable it. Alternatively, you might have to use an alternative method of connecting to the database, such as MySQLi, MDB2, PDO, etc. The standard php_mysql extension is rather primitive; you should use one of those alternatives if you can anyway.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|