jvsmooth
asked on
voting results to mysql database
i have this code based on a player:
$testFile = "test.txt";
if($_REQUEST['action']=="v ote"){
	function writeTextFile2($theFileNam e, $theContent, $openCondition='w+'){
		if($theContent=="" || is_null($theContent)){
			$enterContent = " ";
		} else {
			$enterContent = $theContent;
		}
		$retval = TRUE;
		if (!$fp = fopen($theFileName, $openCondition)) {
			$retval = FALSE;
		}
		if($retval){
			if (!$filewrite = fwrite($fp, stripslashes($enterContent ))) {
				$retval = FALSE;
				exit;
			} else {
				$retval = TRUE;
			}
		}
		@fclose($fp);
		return $retval;
		@chmod ($theFileName, 0777);
	}
	
	// NOTE: Some PHP installations may use a different nomenclature for the "$_REQUEST" such as "$_HTTP_SERVER"
	$theContent = "";
	
	// Here we are extracting all of the info contained in the request.
	foreach($_REQUEST as $key => $value){
		$theContent .= $key." : \t".urldecode($value)."\r\ n";
	}
	strstr( PHP_OS, "WIN") ? $slash = "\\" : $slash = "/";
	
	//print "$testFile";
	if(writeTextFile2(getc wd ().$slash.$testFile, $theContent, 'w+')){
		print "&retval=ok";
	} else {
		print "&retval=error";
	}
	$dbc=mysql_connect('17 3.201.136. 40','jschi n','Js2759 067') or die(mysql_error());
	mysql_query("jschin",$ dbc);
	
}
the code returns the result of a user voting on a song and returns all of the variables of the song such as title, artist, filename to the text file. What i am looking to do is take this information and scan a database and add a vote to a song based upon the information that is posted. How would I do this using a php function?
$testFile = "test.txt";
if($_REQUEST['action']=="v
	function writeTextFile2($theFileNam
		if($theContent==""
			$enterContent = " ";
		} else {
			$enterContent = $theContent;
		}
		$retval = TRUE;
		if (!$fp = fopen($theFileName, $openCondition)) {
			$retval = FALSE;
		}
		if($retval){
			if (!$filewrite = fwrite($fp, stripslashes($enterContent
				$retval = FALSE;
				exit;
			} else {
				$retval = TRUE;
			}
		}
		@fclose($fp);
		return $retval;
		@chmod ($theFileName, 0777);
	}
	
	// NOTE: Some PHP installations may use a different nomenclature for the "$_REQUEST" such as "$_HTTP_SERVER"
	$theContent = "";
	
	// Here we are extracting all of the info contained in the request.
	foreach($_REQUEST as $key => $value){
		$theContent .= $key." : \t".urldecode($value)."\r\
	}
	strstr( PHP_OS, "WIN") ? $slash = "\\" : $slash = "/";
	
	//print "$testFile";
	if(writeTextFile2(getc
		print "&retval=ok";
	} else {
		print "&retval=error";
	}
	$dbc=mysql_connect('17
	mysql_query("jschin",$
	
}
the code returns the result of a user voting on a song and returns all of the variables of the song such as title, artist, filename to the text file. What i am looking to do is take this information and scan a database and add a vote to a song based upon the information that is posted. How would I do this using a php function?
ASKER
Yes the function works the layout is id , song_title, song_artist, genre, filepath
In that order
In that order
If you are wanting to record a vote, where are you going to store that? Are you wanting to keep a count in table with a foreign key constraint to the table you mentioned above so it will grow vertically and you have an audit trail of the votes or do you want to just have a vote column in the table you mentioned and update it with a running total of votes?
What is your table name, so I can reference it by name?
What is your table name, so I can reference it by name?
ASKER
I would rather have a vote column that is numerically increased by one when the user votes and the name of the table is music
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so as it is the function creates a function called test.txt which has all of the information in it. How do I catch this information? Do I jus make a file called votecapture.php, which has the above function in it, and set that where the test.txt currently is? Or do i need to do something else.
@jvsmooth, here is how I would handle the voting. Make a junction table that contains (at a minimum) two columns - the key of the song and the key of the user. You could augment this table to include other interesting things like the DATETIME of the vote, or the IP address (can be used to determine the geographic location of the voter). This table will be quite long, but if you have an index on the key columns you will have pretty good performance even if it goes into the hundreds of thousands of rows.
I would not have a vote column in the music table. To understand why, you would need to understand all about data base normalization and that is a little too much for you to learn over a question at EE.
If you're still fairly new to PHP and data base driven web sites, this book will help you get a strong foundation.
http://www.sitepoint.com/books/phpmysql4/
Best regards, ~Ray
I would not have a vote column in the music table. To understand why, you would need to understand all about data base normalization and that is a little too much for you to learn over a question at EE.
If you're still fairly new to PHP and data base driven web sites, this book will help you get a strong foundation.
http://www.sitepoint.com/books/phpmysql4/
Best regards, ~Ray
2) What is the layout of your database tables?