Hi all
hope this is the right place for my post
can you please help me out
this code…it is from a php file that is supposed to read the information from a mysql db connected to a flash poll and send the info back to flash for display…
I checked my username, password, database ecc. but I keep getting the same error “Unable to select database”…here’s the code
<?
$choice =$_POST[‘choice’];
$user=“myusername”;
$password=“mypassword”;
$database=“mybd”;;
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( “Unable to connect to database”);
// what choice did the user choose in flash?
if($choice == 1){
$query=“UPDATE votesystem SET vote1=vote1+1”;
}
if($choice == 2){
$query=“UPDATE votesystem SET vote2=vote2+1”;
}
if($choice == 3){
$query=“UPDATE votesystem SET vote3=vote3+1”;
}
if($choice == 4){
$query=“UPDATE votesystem SET vote4=vote4+1”;
}
mysql_query($query);
//Get values from the database
$query=“SELECT * FROM votesystem”;
$result=mysql_query($query);
mysql_close();
//What are the values from the database?
$vote1_out=mysql_result($result,0,“vote1”);
$vote2_out=mysql_result($result,0,“vote2”);
$vote3_out=mysql_result($result,0,“vote3”);
$vote4_out=mysql_result($result,0,“vote4”);
//Votes in total
$total=$vote1_out+$vote2_out+$vote3_out+$vote4_out;
//Info to send back to flash:
$values="&totalVotes=$total&vote1total=$vote1_out&vote2total=$vote2_out&vote3total=$vote3_out&vote4total=$vote4_out";
echo “$values”;
?>
Another file was included with the flash poll and it was supposed to create the table for the db…that file didn’t worked either…same error “Unable to select database”
so I created the table myself using phpMyAdmin but I still get the error…
here’s the code from this other file that was supposed to create the table (just so you can see it)…
<?
$user=“myusername”;
$password=“mypassoword”;
$database=“mybd”;
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die(“Unable to select database”);
$query=“CREATE TABLE votesystem (vote1 int(4),vote2 int(4),vote3 int(4),vote4 int(4))”;
mysql_query($query);mysql_close();
?>
What really doesn’t convince me in this code is that reference to “localhost” … it is in both the files code…shouldn’t that point to my db address or name??
I’m not that handy with mysql and php…but in my little knowledge that localhost should not be there…I tried to change it to $database but it didn’t worked…
Please let me know if you can help me make this work
thank you