View Full Version : sql - can't connect [noob]
hroth
April 12th, 2007, 12:14 PM
Hi everyone,
I'm following the tutorial "Login Using Flash MX, PHP, and MySQL" (http://www.kirupa.com/developer/actionscript/authentication.htm)
It's giving me this error: "Unable to connect to SQL server"
the error logs on the server are saying: "Unknown MySQL server host "
so I must be typing something in wrong.
when I created the db, I named it, let's say.. "dbname"
however the CP displays the database name and username as "thingey_dbname"
it added text in front with an underscore. Naturally I've tried that as my database name and username, no sucess.
here is pretty much what I have for the part drawing the error:
mysql_connect("dbname.mywebsite.com","theusername","password")
or die("Unable to connect to SQL server");
mysql_select_db("dbname") or die("Unable to select database");
I've tried:
mysql_connect("thingey_dbname.mywebsite.com","thingey_theusername","password")
or die("Unable to connect to SQL server");
mysql_select_db("thingey_dbname") or die("Unable to select database");
also:
sql.mywebsite.com
mysql.mywebsite.com
anyone know what I'm doing wrong here?
-hroth
foodpk
April 12th, 2007, 12:24 PM
Hi! Try
mysql_connect("localhost","thingey_theusername","password") or die ("Out of cheese error");
mysql_select_db("thingey_dbname") or die ("Out of ham error");
hroth
April 12th, 2007, 01:17 PM
thank you~foodpk~!
that has worked great! It connects! Only problem now is that when I submit a new user and password it is not writing to the db and I get no error. When I click submit the fields are cleared and nothing else happens.
I manually added a user and password and it displays it no prob.
The password check works, (when I type two different passwords)
what information can I provide to help solve the riddle?
here are the server error logs:
ON RERESH:
0: [client IPADDRESS] PHP Notice: Undefined variable: result in /home/thingey/website.com/html/usercheck.php on line 36, referer: http://www.website.com/usercheck.php
1: [client IPADDRESS] PHP Notice: Undefined variable: REQUEST_METHOD in /home/thingey/website.com/html/usercheck.php on line 17, referer: http://www.website.com/usercheck.php
ON SUBMIT:
2: [client IPADDRESS] PHP Notice: Undefined index: passTwo in /home/thingey/website.com/html/usercheck.php on line 6
3: [client IPADDRESS] PHP Notice: Undefined index: passOne in /home/thingey/website.com/html/usercheck.php on line 5
4: [client IPADDRESS] PHP Notice: Undefined index: newUser in /home/thingey/website.com/html/usercheck.php on line 4
(followed by the two errors above)
I'll paste the php and some info I have from phpadmin below:
<?PHP
$newUser = $_POST['newUser'];
$passOne = $_POST['passOne'];
$passTwo = $_POST['passTwo'];
if ($passOne == $passTwo) {
$newPass = $passOne;
} else {
print "Passwords mismatched";
}
if (($REQUEST_METHOD=='POST')) {
for(reset($HTTP_POST_VARS);
$key=key($HTTP_POST_VARS);
next($HTTP_POST_VARS)) {
$this = addslashes($HTTP_POST_VARS[$key]);
$this = strtr($this, ">", " ");
$this = strtr($this, "<", " ");
$this = strtr($this, "|", " ");
$$key = $this;
}
if ($newUser && $newPass) {
$query = "insert into auth (userid,username,userpassword) ";
$query .= "VALUES(0000,'$newUser','$newPass')";
mysql_connect("localhost","thing_username","zepassword")
or die("Unable to connect to SQL server");
mysql_select_db("thing_username") or die("Unable to select database");
$result = mysql_query($query) or die("Insert Failed!");
}
}
if ( $result ){
print "You have successfully entered ".$newUser." with the password of ".$newPass." to your database!!";
}
?>
<html>
<head>
<title>:::::::MYSQL::::::::</title>
</head>
<body bgcolor="#FFFFFF">
<h1>Insert Into Database • UCS</h1>
<form action="usercheck.php" method="POST">
New User Name: <input type="text" size="20" name="newUser" style="background-color: cyan;"><br>
New User Password: <input type="text" size="20" name="passOne" style="background-color: cyan;"><br>
Verify Password: <input type="text" size="20" name="passTwo" style="background-color: cyan;"><br>
<input type="submit" value="Add User" style="background-color: cyan;">
</form>
<br><br>
<hr>
<?
$queryb="SELECT COUNT(*) FROM auth";
mysql_connect("localhost","thing_username","zepassword")
or die("Unable to connect to SQL server");
mysql_select_db("thing_username") or die("Unable to select database");
$numusers=mysql_query($queryb) or die ("Select Failed - count");
$numuser=mysql_fetch_array($numusers);
?>
<h3>Current Users in Database</h3>
<p>
There are <? echo $numuser[0]; ?> current users in database.<br>
Listed in alphabetical order by user's name:<br>
<br>
<?
$queryc="SELECT * FROM auth ORDER BY username";
$userlist=mysql_query($queryc) or die("Select Failed - users");
?>
<center>
<table border="1" bordercolor="#000000">
<tr>
<td width="20%" bgcolor="#000000">
<font size="2" color="#FFFFFF"><center>
USERS
</font></center>
</td>
<td width="20%" bgcolor="#000000">
<font size="2" color="#FFFFFF"><center>
PASSWORDS
</font></center>
</td>
</tr>
<?
while ($userinfo = mysql_fetch_array($userlist)){
?>
<tr>
<td width="20%" bgcolor="#FFCC33">
<center>
<? echo $userinfo['username']; ?>
</center>
</td>
<td width="20%" bgcolor="#FFCC33">
<center>
<? echo $userinfo['userpassword']; ?>
</center>
</td>
</tr>
<? } ?>
</table>
</center>
<p>
With this form, you can submit new users and passwords. However, you are not able to update or erase enteries once
entered. All changes made to your database are updated in real time.
<br><br><br>
<small>
© 2003<a href="http://www.tempethunderpress.com" target="blank"> • Tempe Thunder Press •</a> All Rights Reserved
</small>
</body>
</html>
perhaps the db is setup wrong?
My sql query window would not accept the table setup script that
was provided in the tutorial. So I did it manually.
here is some of the db settings info:
table name: auth
Fields: userid, username, userpassword
Type: int(4), varchar(20), varchar(20)
Index
Keyname: PRIMARY
Type: PRIMARY
Cardinality: 0
Field: userid
the user has full rights on the db
the php file has full permission (777)
(though it does not likely need write permission hun?)
please help~! :puzzle: confused db_newbie
-hroth
hroth
April 13th, 2007, 06:14 PM
bump.. ~
--(shuffles feet with his head hung low)--
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.