Hey whats up guys? I was using thenewboston tutorials on youtube and I am stuck. I was trying to connect to my database that i made.

<?php
//opens connection to mysql server
$dbc=mysql_connect('localhost','kybo13','****');
if(!$dbc)
{
die('Not connected: ' . mysql_error()); 
}

//select database
$db_selected=mysql_select_db("kybo13_game",$dbc);
if(!$db_selsected)
{
die("Cant connect: " . mysql_error());
}

//test
$query="UPDATE game SET email='hopethisworks' WHERE username='kybo13'";
$result=mysql_query($query);
?>

Thanks for your help guys.

Start by changing the line if(!$db_selsected) -to- if(!$db_selected)

commented: Very helpful +1

Ok thank you for that mistake I missed. It still doesnt work though.

You have to be more explicit. "It still doesn't work" doesn't help much. I ran a modified version of your code as follows and it worked correctly:

<?php
//opens connection to mysql server
$dbc=mysql_connect('localhost','root','');
if(!$dbc)
	{
	die('Not connected: ' . mysql_error());
	}

//select database
$db_selected = mysql_select_db("test",$dbc);
if(!$db_selected)
	{
		die("Cant connect: " . mysql_error());
	}

//test
$query="UPDATE test_table SET field1='hopethisworks' WHERE id='00001'";
$result=mysql_query($query);
?>

You may have a problem with your DB or the names / parms you are using for it.

Chris

AWESOME!! Thank you for helping me. This now works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.