Jump to content

php database


Caitlin-havener

Recommended Posts

I'm not connecting to my database... anything wrong with the code you can see? i'm not sure how to put hostname in, before I had localhost but it didn't work

function inserthistory($x, $y, $color){global $Login, $Password;	$connection=mysql_connect('hostname:184.168.45.20',$Login,$Password) or print 'main connect failed';	mysql_select_db('ca081919',$connection) or print "main select failed";		$q="INSERT INTO history VALUES (null, '$x','$y', '$color')";	$result = mysql_query ($q, $connection) or print "query '$q' failed";		} #inserthistory

Link to comment
Share on other sites

When connecting to your your local server you would usually use ('localhost' , 'root', 'mypassword'), when using a hosting web server they usually provide their own hostname, username, and mysql db name to use, when you setup the database.

Link to comment
Share on other sites

When connecting to your your local server you would usually use ('localhost' , 'root', 'mypassword'), when using a hosting web server they usually provide their own hostname, username, and mysql db name to use, when you setup the database.
This is the server info it gives me: ca081919.db.7515989.hostedresource.com (184.168.45.20 via TCP/IP). I tried both the name and just the numbers... I have the username and password right. 'localhost' wasn't working. Database name is correct.... table name correct...
Link to comment
Share on other sites

have you placed them in correct order$conn = mysql_pconnect('hostedresource.com', 'ca081919', 'yourpassword') or trigger_error(mysql_error(),E_USER_ERROR);mysql_select_db('db.7515989', $conn);
Yes, they are in order and I just tried it the way you have it here:
$connection=mysql_connect('hostedresource.com',$Login,$Password) or print 'main connect failed';	mysql_select_db('db.7515989',$connection) or print "main select failed";

Again I know my pass and login are right and they are of global scope.Is that how I am supposed to do it then?? Or is that wrong?

Link to comment
Share on other sites

I also tried

$connection=mysql_connect('hostedresource.com',$Login,$Password) or print 'main connect failed';	mysql_select_db('ca081919',$connection) or print "main select failed";

because I know I named the database ca081919.Still getting main connect failed.

Link to comment
Share on other sites

$connection=mysql_connect('184.168.45.20',$Login,$Password) or print 'main connect failed';

Does that at least print "main connection failed"?

Link to comment
Share on other sites

Sweet. That worked! Thanks. Can you see why my Back off button is not working...Functions:

#removelasthistory:function removelasthistory(){global $Login, $Password;	$maxitnum=largest_itemnumber(); // most recently added will have largest item number.		$connection=mysql_connect('184.168.45.20',$Login,$Password) or print 'main connect failed';	mysql_select_db('ca081919',$connection) or print "main select failed";			$g="SELECT x FROM history WHERE turn_number=$maxitnum";		$result = mysql_query ($g, $connection) or print "query '$g' failed";		while($row=mysql_fetch_array($result))								{				global $x;			$x=$row[0];					//return $x;					}		$h="SELECT y FROM history WHERE turn_number=$maxitnum";		$result2 = mysql_query ($h, $connection) or print "query '$h' failed";		while($row2=mysql_fetch_array($result2))								{				global $y;			$y=$row2[0];				//return $y;						}		$q="DELETE FROM history WHERE turn_number=$maxitnum";	$result3 = mysql_query ($q, $connection) or print "query '$q' failed";	}function largest_itemnumber(){global $Login, $Password;	$connection=mysql_connect('184.168.45.20',$Login,$Password) or print 'main connect failed';	mysql_select_db('ca081919',$connection) or print "main select failed";			$q="SELECT MAX(turn_number) FROM history";		$result = mysql_query ($q, $connection) or print "query '$q' failed";		$row=mysql_fetch_array($result);		$maxitnum=$row[0];		return $maxitnum;} # largest_itemnumber

Case for clicking Back Off:

case 'BACK OFF':			$blackbackoff = $_SESSION['blackbackoff'];			$goldbackoff = $_SESSION['goldbackoff'];			$turn=$_SESSION['turn'];						if($turn=='BLACK') {				if($blackbackoff==1) {					$blackbackoff= 0;					$_SESSION['blackbackoff'] = $blackbackoff;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;								} 			}			if($turn=='GOLD') {				if($goldbackoff==1) {					$goldbackoff = 0;					$_SESSION['goldbackoff'] = $goldbackoff;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;										removelasthistory();					$Grid[$x][$y]=WHITE;									} 

It is supposed to remove the last three moves for each team. See the site: http://havener.me/files/project3/project3.php

Link to comment
Share on other sites

I don't get it... why are you doing

					removelasthistory();					$Grid[$x][$y]=WHITE;

several (like 6 or 7) times? $x and $y aren't changing thoughout the whole thing, and BTW, what's the value of this WHITE constant?I thought you learned the lesson from last time to avoid globals, and carefully track those that you do have.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...