Forum Moderators: coopster
I'm using a few tutorial pages just to try to get some working stuff up. But I'm getting nothing but errors back. My PHP docs can't find my MySQL databases. And frankly, I can't either.
I have created a Db both threw myAdminPHP (CPanel) and also tried using a tutorial that created the base/table for me.
What is the local host? The address of where my Db is? I use an FTP program, should I be able to find my Db among my folders? Is it saved server side, to where I won't see it?
I've been trying to no avail for a week now to figure something out. When your lost, you are lost.
mysql_pconnect("localhost","user","pass");
mysql_select_db("db name");
Also, the error message would help too.
When I create a Db or username threw myAdminPHP it changes the name slightly. if i enter ireKevin for user name, it will display irekevin_irekevi, same thing with the Db, I call it ireKevin, it displays ireKevin_
Sugguestions?
SHOUTBOX.PHP
<?php
mysql_pconnect("localhost","irekevin_irekevi","my_password");
mysql_select_db("shoutbox?");
if($submit) {
$time = date("d.m.Y., H:i ");
$result = mysql_query("
INSERT INTO
shoutbox
SET
message = '$message',
name = '$name',
time = '$time'
");
header("Location: viewshoutbox.php");
}
?>
VIEWSHOUTBOX.PHP
<html>
<head>
<title>Shoutbox</title>
</head>
<body>
<!--forma za upis-->
<form action="shoutbox.php" method="post">
<input type="text" value="name/nick" name="name">
<input type="reset" name="Reset" value="clear">
<br>
<input type="text" value="message" name="message">
<input type="submit" name="submit" value="shout!">
</form>
<?php
mysql_pconnect("localhost","irekevin_irekevi","my_password");
mysql_select_db('shoutbox');
$result = mysql_query("
SELECT
*
FROM
shoutbox
ORDER BY
id DESC
LIMIT 20
");
while($a>$b) {
$c++;
}
?>
</body>
</html>
Am I missing PHP that will write the Db Content, or code that will write to the table? Maybe missing some `` or ' ' or " " or?
Suggestions?
I think u are facing problem because u not passed second parameter of mysql_select_db() that is "link_resource_identifier".
Ur Code
==========
mysql_pconnect("localhost","irekevin_irekevi","my_password");
mysql_select_db('shoutbox');
Replace With This
===================
$db = mysql_pconnect("localhost","irekevin_irekevi","my_password");
mysql_select_db('shoutbox',$db);
Vineet
just an idea
also, I think a @ is very usefull here, what if there is a time the script can not connect to the DB?
It will echo out your full login credentials to the browser if you dont surpress the error!
I dont think this is what anyone wants :)
<? @ $db = mysql_connect('localhost', 'mysql_user', 'mysql_pass');?>
I think u are facing problem because u not passed second parameter of mysql_select_db() that is "link_resource_identifier".
the link resourcr identifier is totally optional ;)
[nl3.php.net...]
link_identifierThe MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.
$db =mysql_pconnect("localhost","irekevin_irekevi","my_password");
the connect function returns a connection, you need to store it in a var
also I would use mysql_connect not mysql_pconnect unless you already uncerstand a reason why you might need pconnect.