Jump to content
xisto Community
Eggie

SQL Doesn't Connect In PHP Script I made some code updates now the script is broken.

Recommended Posts

i have created a website and it is not working properly...
i have had a website on sphosting.com and everything worked fine till i got some errors(i got the errors because of the crappy host)...now the fun part starts...they said they solved the problem but i got another one..i said them to repair it again and they did...now i tried to login but as i entered the info it said the info isn't correct...i checked the SQL and everything seemed fine..i tried again and again the error came...i tried than to register,entered ALL info and when this was suppose to come out "You have now registered to play $gamename. Please check you e-mail for the verification link. E-mail can take up to 24 hours to recieve, please be patient" the register.php was there again ...
i uploaded the script that I KNOW that worked fine before i made major updates on the scripts and it didn't work...
i changed my host and installed the newer script and the let me call it "default" script and none worked...

i think the problem could be that it doesn't connect to my database correctly but the news on the index.php is in the database and it's correctly shown without any problems...i even tried the

echo mysql_error();
and it didn't work
does anyone have time to see my scripts and see what is wrong??
EDIT:BTW:i use p_connect for connecting to my database
Edited by Eggie (see edit history)

Share this post


Link to post
Share on other sites

i have created a website and it is not working properly...i have had a website on sphosting.com and everything worked fine till i got some errors(i got the errors because of the crappy host)...now the fun part starts...they said they solved the problem but i got another one..i said them to repair it again and they did...now i tried to login but as i entered the info it said the info isn't correct...i checked the SQL and everything seemed fine..i tried again and again the error came...i tried than to register,entered ALL info and when this was suppose to come out "You have now registered to play $gamename. Please check you e-mail for the verification link. E-mail can take up to 24 hours to recieve, please be patient" the register.php was there again ...
i uploaded the script that I KNOW that worked fine before i made major updates on the scripts and it didn't work...
i changed my host and installed the newer script and the let me call it "default" script and none worked...

i think the problem could be that it doesn't connect to my database correctly but the news on the index.php is in the database and it's correctly shown without any problems...i even tried the

echo mysql_error();
and it didn't work
does anyone have time to see my scripts and see what is wrong??
EDIT:BTW:i use p_connect for connecting to my database
Well, just looking at your method, I have no idea what p_connect is!

Did you mean pg_connect or pg_pconnect?
If so, those are for PostgreSQL Databases which are different than MySQL databases!

Anyway, nobody will be able to help you with your problem without seeing some code. Additionally, this sounds more like a PHP issue than a SQL problem.

vujsa

Share this post


Link to post
Share on other sites

Maybe one simple test could be to use phpMyadmin with this user's name and password, in order to see if the user exists.then, you should also verify that the user's tables still exist and have rows.

Share this post


Link to post
Share on other sites

Maybe one simple test could be to use phpMyadmin with this user's name and password, in order to see if the user exists.then, you should also verify that the user's tables still exist and have rows.

i checked sql database and there is that table...but no information in it after i register a account...

@vujsa: mysql_pconnect("","",""); i meant i use that ;) and for the code-i asked if someone wants i can grant him my account information so he can check it if he wants... but i ain't gonna post it on the forum :P

Share this post


Link to post
Share on other sites

mysql_pconnect("","",""); i meant i use that and for the code-i asked if someone wants i can grant him my account information so he can check it if he wants...

I guess that vujsa wanted to have some lines from your php source code around the "connect" word, in order to see what could explain not being conneted. The username and passord is here a useless detail, the important thing is the syntax of the php lines trying to connect. Or you can, as usual, say myname/blahblah or blah/password, just to explain where you put the password. As a matter of example, when I talk with my Oracle support I say "I try sqlplus blah/brol ", and everybody knows that here "blah" stands for my username and "brol" replaces my secret password. And the syntax sqlplus blah/brol has to be accepted unless the RDBMS system is down.

Share this post


Link to post
Share on other sites

i meant that i will give you my Cpanel login information if you want to help me so i don't need to copy the entire page of "config.php" or "register.php" because it will be too long and people will think that i'm doing it for credits which i wouldn't like (but i can do it if you want me to) and i will be denied once more for the hosting and i don't want that

Share this post


Link to post
Share on other sites

OK, you are right. vujsa will PM you if he prefers working that way.

Can't you help me?;)i would like help from anyone only if he's not so stupid that he steals my scripts or delete my hosting plan but i think that noone will...i believe that people won't fool me:) i hope i'm right

Share this post


Link to post
Share on other sites

Can't you help me?

I would if I could. Unfortunately, I'm not a king in php. I'm only able to use the automatic scripts within the Xisto cpanel, where you have nothing to do except giving your account name and password. So, if something is wrong inside one of your scripts, let's wait until one of the php gods around here come and have a look.

Share this post


Link to post
Share on other sites

I think you should give a clearer picture of what's your situation and the error message you're getting. I'm guessing that the script you're referring to is a game engine or sort of alike. And now you're facing the problem of connecting to your SQL database? But the previous problem with your hosting wasn't clear at all, are they also related to the SQL problem? What kind of error was that? Maybe with more information we can help you narrow down your problem.We don't actually need your login to see your code. We actually prefer for you too look into it yourself, while we provide you some guidance, that way you can learn better, and be able to tackle any future problem. I'm sure they'll be more problem coming along if you're doing programming.Anyway, for troubleshooting, you should try to eliminate the problem one by one. For example, now that you cannot connect. Maybe you can create a simple page, with just a few line of code to connect to you SQL database, and see if it works. This will confirm that your username, password and database is correctly configured. If not, you can also try diff method of connecting, to eliminate problem from a particular SQL library. So the list goes one, until you are left with 1 or more item that's contributing to the problem. Then you can start to think of a solution, including "shooting" at your hosting.Good Luck

Share this post


Link to post
Share on other sites

This is how i connect to my database:
config.php

<?phpmysql_pconnect("localhost","eggie_Eggie","jajetic");mysql_select_db("eggie_Eggie");$cpass="resetpasswordhere";$gamename="Land of Damned";$site_com = "eggie.sphosting.com"; $end_of_email = "@eggie.sphosting.com"; $admin_name = "Eggie";$admin_email = "jurica@mail.com"; $bottom_link = "http://eggie.sphosting.com";  // note some of these just dont work...$top_color = "000000";$table_border = "466AB0";$text_color = "466AB0";$bg_color = "#000000";$bordercolor = "#666666";$bg_color2 = "#003366";$highlitec = "#003366";$forumsbgc = "#000000";if ($title == NULL) {	$title = "CANNOT FIND NAME OF PAGE!";}else{	end;}?>

this is my register script::register.php
it includes head.php which includes config.php

<?php $title = "Register"; include("head.php"); ?><script language="JavaScript" type="text/JavaScript"><!--function launchName() { name=window.open("reghelp.php?help=Name","","width=200,height=200,top=100,left=100,resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no")}function launchSecquestion() { secquestion=window.open("reghelp.php?help=SQ","","width=200,height=200,top=100,left=100,resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no")}function launchSecanswer() { secanswer=window.open("reghelp.php?help=SA","","width=200,height=200,top=100,left=100,resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no")}function launchRefid() { refid=window.open("reghelp.php?help=refid","","width=200,height=200,top=100,left=100,resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no")}function launchClasses() { refid=window.open("reghelp.php?help=classes","","width=400,height=400,top=100,left=100,resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no")}</script><?phpif (!$action == 'register') {?><center><b>A random password will be sent to your e-mail after registration</b><br /><br /><b>/@*#%{}()-<> can't be used.</b><br /><br /><b>The e-mail can't be sent to AOL, Netscape, or Comcast accounts as far as I know. Use <a href=http://yahoo.com/ /><br /><br /><b>* = Required Information</b><br /><br /><br /><?php$players = mysql_query("SELECT * FROM players WHERE varified = 'Yes'") or die(mysql_error());$nump = mysql_num_rows($players);echo "<b>$nump</b> people have already registered.";?></center><br /><form method="post" action="register.php"><input type=hidden name="action" value="register" /><center><table><tr><td>*Username:</td><td><input type=text name=new_user>-<a href="java script:launchName()">?</a></td></tr><tr><td>*Class:</td><td>	<select size=5 name="class" id="class">	<option value="Swordman">Swordman</option>	<option value="Archer">Archer</option>	<option value="Thief">Thief</option>	<option value="Mage">Mage</option>	<option value="Acolyte">Acolyte</option>	</select>-<a href="java script:launchClasses()">?</a>  </td></tr><tr><td>*Password:</td><td><input type=password name=new_pass></td></tr><tr><td>*Varify Password:</td><td><input type=password name=var_pass></td></tr><tr><td>*Email:</td><td><input type=text name=new_email></td></tr><tr><td>*Varify Email:</td><td><input type=text name=var_email></td></tr><tr><td>*Password Recovery Question:</td><td>	<select name=sec_question id=type>	<option value="Whats your mothers Maiden Name?">Whats your mothers Maiden Name?</option>	<option value="When is your B-day?">When is your B-day?</option>	<option value="What is your pets name?">What is your pets name?	</select>-<a href="java script:launchSecquestion()">?</a>	</td></tr><tr><td>*Answer:</td><td><input type=text name=sec_pass>-<a href="java script:launchSecanswer()">?</a></td></tr><?phpprint "<tr><td>Referral ID:</td><td><input type=text name=ref value=$ref>-<a href=java script:launchRefid()>?</a> <i>Not needed</i></td></tr><tr><td colspan=2 align=center><input type=submit value=Register></td></tr></form></table></center>";}?><?phpif ($action == 'register') {$new_user = htmlspecialchars($new_user);$new_user = strip_tags($new_user);$skill = htmlspecialchars($skill);$new_pass = htmlspecialchars($new_pass);$var_pass = htmlspecialchars($var_pass);$new_email = htmlspecialchars($new_email);$var_email = htmlspecialchars($var_email);$sec_question = htmlspecialchars($sec_question);$sec_pass = htmlspecialchars($sec_pass);$ref = htmlspecialchars($ref);if (ereg("^([a-zA-Z0-9_\.]*)@([A-Za-z0-9_]*)\.([A-Za-z_\.]*)$", $new_email)) {if(eregi('[/@*#%{}()=<>-]', $new_user)) {	print "The Username contains an invalid character!";	include("foot.php");	exit;}if(eregi('[/@*#%{}()=<>]', $sec_question)) {	print "'$sec_question' contains invalid character(s)!";	include("foot.php");	exit;}if(eregi('[@*#%{}()=<>-]', $sec_pass)) {	print "'$sec_pass' contains an invalid character(s)!";	include("foot.php");	exit;}if(strlen($new_user) < 3) {	print "Your Username $new_user is too small, 3 character minimum"; 	include("foot.php");	exit;}if(strlen($new_user) > 15) {	print "Your Username $new_user is too big, 15 character maximum"; 	include("foot.php");	exit;}if(strlen($new_pass) < 3) {	print "Your Password $new_pass is too small, 3 character minimum"; 	include("foot.php");	exit;}if(strlen($new_pass) > 15) {	print "Your Password $new_pass is too big, 15 character maximum"; 	include("foot.php");	exit;}	if (!$new_user || !$new_email || !$sec_question || !$sec_pass || !$new_pass || !$var_pass || !$class) {		print "You must fill out all fields.";		include("foot.php");		exit;	}	$dupe1 = mysql_num_rows(mysql_query("select * from players where user='$new_user'"));	if ($dupe1 > 0) {		print "Someone has already registered that username. Please choose another.";		include("foot.php");		exit;	}	$dupe2 = mysql_num_rows(mysql_query("select * from players where email='$new_email'"));	if ($dupe2 > 0) {		print "Someone has already registered using that email.";		include("foot.php");		exit;	}	if ($new_email != $var_email) {		print "The emails do not match.";		include("foot.php");		exit;	}	if ($new_pass != $var_pass) {		print "The passwords do not match.";		include("foot.php");		exit;	}	if ($class == "Swordman") {		$charclass = "Swordman";	}	if ($class == "Archer") {		$charclass = "Archer";	}	if ($class == "Thief") {		$charclass = "Thief";	}	if ($class == "Mage") {		$charclass = "Mage";	}	if ($class == "Acolyte") {		$charclass = "Acolyte";	}	$email_pass = ($new_pass);	$db_pass = md5($new_pass);	$db_pass2 = md5($db_pass);	$db_pass3 = md5($db_pass2);	$db_pass4 = md5($db_pass3);	$db_pass5 = md5($db_pass4);	mysql_query("insert into players (user, email, pass, question, answer, class) values('$new_user','$new_email','$db_pass5', '$sec_question', '$sec_pass','$charclass')") or die("Could not register.. trouble with adding you to the players table.");	$randomver = rand(1000 , 9000);	$info = mysql_fetch_array(mysql_query("select * from players where user='$new_user' and pass='$db_pass5'"));	mysql_query("insert into register (userid, refid, random) values('$info[id]','$ref','$randomver')") or die("Could not register. trouble with adding you to the register table.");	$register = mysql_fetch_array(mysql_query("select * from register where userid='$info[id]'"));	$message = "Welcome to $site_com\nYou must validate your account by clicking the link below\n<a href=$email_link/verify.php?action=verify&id=$info[id]&pass=$register[random]>Click Here</a>\nYour Username is: $new_user\nYour Password is: $email_pass\nThank You for signing up\n\n\nDON'T REPLY TO THIS E-MAIL, IT IS AUTOMATED.";	mail("$new_email", "Welcome to $site_com", "$message","From: webadmin$end_of_email\r\n"."Reply-To: $admin_email\r\n"."X-Mailer: PHP/" . phpversion()) or die("Well bad news is, your user name is now taken, more bad news is that the e-mail could not be sent");	print "<center><br><br><b><i><u>You have now registerd to play $gamename. Please check you e-mail for the verification link. E-mail can take up to 24 hours to recieve, please be patient</center></b></i></u><br>";	echo mysql_error();}else{	print "Your e-mail is in an invalid format";	include("foot.php");	exit;	}}?><?php include("foot.php"); ?>


Remove my credits if you want to vujsa:P
EDIT:i said that i reinstalled all the scripts to original and sql tables but it didn't help me solve the problem
http://forums.xisto.com/no_longer_exists/ thats the page for registration and it is getting from the table that one person is registered(the one i made manually in the mysql) but it won't put anything into the tables ;)
Edited by Eggie (see edit history)

Share this post


Link to post
Share on other sites

After looking through your code just a few lines down I realized you are connecting to your mysql in a different way then I use. I am not sure if that is the problem but I think you should use mysql_connect(); rather then mysql_pconnect();
Here is an example:

if (!mysql_connect(localhost, database username, password)) {echo("Could not connect to mysql");exit;}$result = mysql_list_tables(databasename);if (!$result) {print "DB Error, could not list tables\n";print 'MySQL Error: ' . mysql_error();exit;}
That should allow you to connect if you have given correct permissions. You should know where to put this but if you need any more help feel free to ask. I have only looked through the first few lines of your code this should solve the problem. If not just say so.
Hope this helps,
Sparkx

Good Luck ;)

Share this post


Link to post
Share on other sites

After looking through your code just a few lines down I realized you are connecting to your mysql in a different way then I use. I am not sure if that is the problem but I think you should use mysql_connect(); rather then mysql_pconnect();Here is an example:

if (!mysql_connect(localhost, database username, password)) {echo("Could not connect to mysql");exit;}$result = mysql_list_tables(databasename);if (!$result) {print "DB Error, could not list tables\n";print 'MySQL Error: ' . mysql_error();exit;}
That should allow you to connect if you have given correct permissions. You should know where to put this but if you need any more help feel free to ask. I have only looked through the first few lines of your code this should solve the problem. If not just say so.
Hope this helps,
Sparkx

Good Luck ;)

isn't that the same as mine...just your has more lines? i don't think that that's the problem...

Share this post


Link to post
Share on other sites

n't that the same as mine...just your has more lines? i don't think that that's the problem...

Maybe yes, maybe not. But, there is no risk.You have sparkx's program which is able to connect.
Simply backup your own program, and change the two lines to push them the way sparkx says.
If this does not help, then, you are right and this is not the problem, and you restore your original php file from the backyp.
But if this happens to work, you will be happy and you will shout "thanks a lot for the help, folks".

Share this post


Link to post
Share on other sites

The mysql_pconnect() PHP function simply allows to use persistent database connections to a MySql database and in general it works most exactly the same as the mysql_connect() PHP function, the only advantage that gives is efficiency, so, try to use only non persistent connections to verify your script.

 

mysql_pconnect() acts very much like mysql_connect() with two major differences.

 

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

 

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).

 

This type of link is therefore called 'persistent'.

Generaly i use the following code to connect to any MySql database:

<?php$link = mysql_connect("localhost", "user_name", "user_password") or die("Could not connect to server. MySql error: " . mysql_error());mysql_select_db("database_name",$link) or die("Error, could not select database. MySql error: " . mysql_error());// $link generally is not necesary, so, you can use the following// mysql_connect("localhost", "user_name", "user_password") or die("Could not connect to server. MySql error: " . mysql_error());// mysql_select_db("database_name") or die("Error, could not select database. MySql error: " . mysql_error());?>
The colors don't work because you forgot to include the "#" character.

 

And, check your php configuration maybe you are not allowed to use persistent connections, check the mysql.allow_persistent and the mysql.max_persistent configuration settings on your php.ini file. Also, check if PHP is running as a MODULE or as a CGI wrapper.

 

Some links from the Online PHP Manual:

Persistent Connections

mysql_pconnect() function

mysql_connect() function

Best regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.