Jump to content

Need this Upload Form to Generate a URL


Mesden

Recommended Posts

so i guess when someone submits, you would take their information a form and store it in the database, in this table you just created. Then you would just display it in the way that suits your needs the best.

Link to comment
Share on other sites

  • Replies 79
  • Created
  • Last Reply
so i guess when someone submits, you would take their information a form and store it in the database, in this table you just created. Then you would just display it in the way that suits your needs the best.
Right. But I'm not very familiar with MySQL so I'm not sure how that's done.
Link to comment
Share on other sites

I have the Tables configured, but I can't do anything with them until I'm able to click submit and have them shown on a generated new page. I mean it's all well if the submit button takes me to a page like preview.php which shows the tables, but then it's not doing what it's supposed to. I need a generated page like http://www.sc2x.net/1.php, then the next uploaded replay would be 2.php, 3.php, 4.php, and so on.

Link to comment
Share on other sites

... just keep in mind that you've already done the creation in this case. You don't need to create any more tables, and PHP doesn't need to execute any "CREATE" statements either. So, either skip the "MySQL Create" part, or look at it, but don't try to repeat it on your host.

Link to comment
Share on other sites

... just keep in mind that you've already done the creation in this case. You don't need to create any more tables, and PHP doesn't need to execute any "CREATE" statements either. So, either skip the "MySQL Create" part, or look at it, but don't try to repeat it on your host.
Okay so I presume now I need a code which connects to the Database and grabs that information from a particular section of that table?
Link to comment
Share on other sites

honestly, just try reading through that tutorial. everything you need to know to get you started is in there.

Link to comment
Share on other sites

I'm assuming it made a successful connection to the Database but the information was still displayed below the upload chart... I need the information on those tables to be displayed on a different page, and I don't want to create a page and just put some coding on it, otherwise the uploaded file will just be sent to that page for everyone.

		<form enctype="multipart/form-data" action="upload_file.php" method="POST">	<h2>	  <p>Upload a Replay<br />	</p>	</h2>	Locate the Replay on your Hard Drive you want to upload. This can typically be located <br />	at<em> C:\Users\(Your Profile)\Documents\StarCraft II Beta\Replays</em>. <br />	<br /><h2>  <p>		<textarea name="textarea" id="textarea" cols="45" rows="7">Type in a Description of the Replay		</textarea>		<br />		<br />		<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $MAX_FILE_SIZE;?>" />		<input name="userfile" type="file" size="35" /><br /><br />		<input type="image" src="/images/submit-button.jpg" /> 		<a href="/"><img src="images/cancel-button.jpg" width="84" height="25" longdesc="/" /></a> </p>	</h2>	<?php$con = mysql_connect("mysql913.ixwebhosting.com","Aaron21_Upload","(Protected)");if (!$con)  {  die('Could not connect to the Database: ' . mysql_error());  }// some code?>		</form>

Link to comment
Share on other sites

I'm assuming it made a successful connection to the Database but the information was still displayed below the upload chart... I need the information on those tables to be displayed on a different page, and I don't want to create a page and just put some coding on it, otherwise the uploaded file will just be sent to that page for everyone.
I'm not sure what you mean by this part. Do you want a person's form submission only available to them and no one else? If so, then there is a lot more to discuss that would be better left for a bit further on down the road. Or maybe I just don't get it.Back to the current issue, although you may have successfully connected, you still have to insert data into a table. some people choose to have the form submit to the same page, and from there if the data entered by the user is legitimate (according to what you require of the form itself), you can redirect to another page which will display the data they had entered and you had stored.
Link to comment
Share on other sites

I'm not sure what you mean by this part. Do you want a person's form submission only available to them and no one else? If so, then there is a lot more to discuss that would be better left for a bit further on down the road. Or maybe I just don't get it.Back to the current issue, although you may have successfully connected, you still have to insert data into a table. some people choose to have the form submit to the same page, and from there if the data entered by the user is legitimate (according to what you require of the form itself), you can redirect to another page which will display the data they had entered and you had stored.
Take a look at this. This is the Upload Form for another website:http://www.sc2rc.com/index.php/replay/uploadAnd here's the Result when an Upload is submitted:http://www.sc2rc.com/index.php/replay/show/7761http://www.sc2rc.com/index.php/replay/show/7758http://www.sc2rc.com/index.php/replay/show/7750http://www.sc2rc.com/index.php/replay/show/7749Notice how they are all sent to a unique URL each time a new upload is submitted to the website. Each of the Links contains different information depending on what the Parser had collected. That's what I'm trying to do.
Link to comment
Share on other sites

Back to the current issue, although you may have successfully connected, you still have to insert data into a table. some people choose to have the form submit to the same page, and from there if the data entered by the user is legitimate (according to what you require of the form itself), you can redirect to another page which will display the data they had entered and you had stored.
Didn't I just make the Tables in phpMyAdmin..? Why do I need to make them again..?
Link to comment
Share on other sites

you aren't, and I wasn't telling you to. you actually have to put the information in it though. that's the whole point behind databases. to store information in a meaningful way. It will be a way to keep track of all the submitted replays so you can have a way to display the information via a page dedicated to displaying the relevant content.

Link to comment
Share on other sites

you aren't, and I wasn't telling you too. you actually have to put the information in it though. that's the whole point behind databases. to store information in a meaningful way. It will be a way to keep track of all the submitted replays so you can have a way to display the information via a page dedicated to displaying the relevant content.
This is where I'm getting a little confused though, the PHP Coding under the Form already tells the server what information it wants in it's own tables. So when a File is uploaded to the web server, the PHP Coding is parsing that File and using it's own coding to indicate what's to be placed in it's table. What is the MySQL Table doing differently that the PHP Coding isn't already doing..?
<?phpfunction createAPMImage($vals, $length, $fn) {		$width = 300;		$height = 200;		$pixelsPerSecond = $width/ $length;		$pic = imagecreatetruecolor($width,$height);		$lineColor = imagecolorallocate($pic,0,0,0);		$lineColorGrey = imagecolorallocate($pic,192,192,192);		$bgColor = imagecolorallocate($pic,255,255,255);		$bgColorT = imagecolorallocatealpha($pic,255,255,255,127);		imagefill($pic,0,0,$bgColorT);		// first create x/y pairs		$xypair = array();		$maxapm = 0;		for ($x = 1;$x <= $width;$x++) {				$secs = ceil($x / $pixelsPerSecond);				$apm = 0;				if ($secs < 60) {						for ($tmp = 0;$tmp < $secs;$tmp++)								$apm += $vals[$tmp];						$apm = $apm / $secs * 60;				} else {						for ($tmp = $secs - 60;$tmp < $secs;$tmp++)								$apm += $vals[$tmp];						$apm = $apm;				}				if ($apm > $maxapm)						$maxapm = $apm;				$xypair[$x] = $apm;		}		// then draw them		if ($maxapm == 0)				return;		for ($i = 2;$i <= $width;$i++) {				imageline($pic,$i - 1,$xypair[$i - 1] / $maxapm * $height, $i, $xypair[$i] / $maxapm * $height,$lineColor);		}		$frame = imagecreatetruecolor($width +50,$height+50);		imagefill($frame,0,0,$bgColor);				imagerectangle($frame,40,0,$width + 40,$height,$lineColor);		imageline($frame,40,$height / 2,$width + 40,$height / 2, $lineColorGrey);		imagestringup($frame,4,5,$height - 15,"APM -->",$lineColor);		imagestring($frame,4,55,$height + 20,"Time (minutes)",$lineColor);		imagestring($frame,2,25,$height - 15,"0",$lineColor);		imagestring($frame,2,20,($height / 2),floor($maxapm / 2),$lineColor);		imagestring($frame,2,20,0,floor($maxapm),$lineColor);		$lengthMins = ($length / 60);		for ($i = 0;$i < $lengthMins;$i+=5) {				imagestring($frame,2,40+($width / ($lengthMins / 5) * ($i / 5)),$height + 5,$i,$lineColor);				if ($i > 0)						imageline($frame,40+($width / ($lengthMins / 5) * ($i / 5)),0,40+($width / ($lengthMins / 5) * ($i / 5)),$height, $lineColorGrey);			  		}		imagecopy($frame,$pic,40,0,0,0,$width,$height);		imagepng($frame,$fn);		imagedestroy($frame);		imagedestroy($pic);}$MAX_FILE_SIZE = 1000000;if (isset($_FILES['userfile'])) {		$error = $_FILES['userfile']['error'];		$type = $_FILES['userfile']['type'];		$name = $_FILES['userfile']['name'];		$tmpname = $_FILES['userfile']['tmp_name'];		$size = $_FILES['userfile']['size'];		$err = false;		if ($size >= $MAX_FILE_SIZE) {				echo "Error: File is too large. Replay File must be below 1MB.<br />";				$err = true;		}		if ($error == UPLOAD_ERR_PARTIAL) {				echo "Error: The upload was not completed successfully. Please try again.<br />";				$err = true;		}		if ($error == UPLOAD_ERR_NO_FILE) {				echo "Error: Please select a File to upload.<br />";				$err = true;		}		if (!is_uploaded_file($tmpname)) {				echo "Error: Uploaded filename doesn't point to an uploaded file.<br />";				$err = true;		}		if ($err !== true) {				if (class_exists("MPQFile") || (include 'mpqfile.php')) {						$start = microtime_float();						if ($_POST['debug'] == 1) {								echo sprintf("<b>Debugging is on.</b><br />\n");						}						$a = new MPQFile($tmpname,true,(($_POST['debug'] == 1)?2:0));						$init = $a->getState();						if ($init == MPQ_ERR_NOTMPQFILE)								echo "Could not parse the Replay. Check to make sure it's a valid .SC2Replay File.<br />\n";						else if ($a->getVersion() < 9)								echo "Error: Invalid Version.<br />\n";						else {								echo sprintf("Major version %d, build %d<br />\n",$a->getVersion(),$a->getBuild());								$b = $a->parseReplay();								$tmp = $b->getPlayers();								echo sprintf("Map name: %s, Game length: %s<br />\n",$b->getMapName(),$b->getFormattedGameLength());								echo sprintf("Team size: %s, Game speed: %s<br />\n",$b->getTeamSize(), $b->getGameSpeedText());																$apmString = "<b>APM graphs</b><br />\n";								echo "<table border=\"1\"><tr><th>Player name</th><th>Long name</th><th>Race</th><th>Color</th><th>Team</th><th>Average APM<br />(experimental)</th><th>Winner?</th></tr>\n";								foreach($tmp as $value) {										$wincolor = ($value['won'] == 1)?0x00FF00:0xFF0000;										echo sprintf("<tr><td>%s</td><td>%s</td><td>%s</td><td><font color=\"#%s\">%s</font></td><td>%s</td><td style=\"text-align: center\">%d</td><td style=\"background-color: #%06X; text-align: center\">%d</td></tr>\n",																		$value['sName'],																		$value['lName'],																		$value['race'],																		$value['color'],																		$value['sColor'],																		($value['party'] > 0)?"Team ".$value['party']:"-",																		($value['party'] > 0)?(round($value['apmtotal'] / ($b->getGameLength() / 60))):0,																		((isset($value['won']))?$wincolor:0xFFFFFF),																		(isset($value['won']))?$value['won']:(($value['party'] > 0)?"Unknown":"-")																);										if ($value['party'] > 0) {												$apmFileName = $value['id']."_".md5($name).".png";												createAPMImage($value['apm'],$b->getGameLength(),$apmFileName);												$apmString .= sprintf("%s:<br /><img src=\"$apmFileName\" /><br />\n",$value['sName']);										}								}								echo "</table><br />";								$messages = $b->getMessages();								if (count($messages) > 0) {										echo "<b>Messages:</b><br /><table border=\"1\"><tr><th>Time</th><th>Player</th><th>Target</th><th>Message</th></tr>\n";										foreach ($messages as $val)												echo sprintf("<tr><td>%d sec</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",$val['time'],																		  $val['name'], ($val['target'] == 2)?"Alliance":"All",$val['message']);										echo "</table><br />\n";								}								echo $apmString;																$t = $b->getEvents();								if (isset($sc2_abilityCodes) || (include 'abilitycodes.php')) {										echo "<table border=\"1\"><tr><th>Timecode</th>\n";										$pNum = count($tmp);										foreach ($tmp as $value) {										  if ($value['party'] > 0)												echo sprintf("<th>%s (%s)</th>",$value['sName'],$value['race']);										}										echo "</tr>\n";										foreach ($t as $value) {												echo sprintf("<tr><td>%d sec</td>",$value['t'] / 16);												foreach ($tmp as $value2) {														if ($value2['party'] == 0) continue;														if ($value['p'] == $value2['id'])																echo sprintf("<td>%s</td>",$b->getAbilityString($value['a']));														else																echo "<td></td>";												}												echo "</tr>\n";										}										echo "</table>";								}						}						$end =  microtime_float();						echo sprintf("Time to parse: %d ms.<br />\n",(($end - $start)*1000));				}		}}?>

Link to comment
Share on other sites

Take a look at this. This is the Upload Form for another website:http://www.sc2rc.com/index.php/replay/uploadAnd here's the Result when an Upload is submitted:http://www.sc2rc.com/index.php/replay/show/7761http://www.sc2rc.com/index.php/replay/show/7758http://www.sc2rc.com/index.php/replay/show/7750http://www.sc2rc.com/index.php/replay/show/7749Notice how they are all sent to a unique URL each time a new upload is submitted to the website. Each of the Links contains different information depending on what the Parser had collected. That's what I'm trying to do.
Based on this, I'm not quite sure how you plan on extracting the match information from the uploaded file. Is there some sort of documentation or API available somewhere with information on how you can do this?
Link to comment
Share on other sites

Oh wait, I think I see what's going on. By inserting a the SQL Tables, I'll have two tables being displayed on the same page (Rather than just the one that's generated by the PHP Coding), but then I can move the SQL Table to a different page..?

Link to comment
Share on other sites

Based on this, I'm not quite sure how you plan on extracting the match information from the uploaded file. Is there some sort of documentation or API available somewhere with information on how you can do this?
http://www.mediafire.com/?mtttzytmdiiHere, Go here and download the SC2Replay File I uploaded to MediaFire. Then, goto http://www.sc2x.net/upload_file.php and upload that .SC2Replay File to the website. Watch what happens. I need that submit button to create a unique page to show that information.
Link to comment
Share on other sites

If you want to be able to save this information, then you need to save it in a database. If you only want people to see it after they upload it, but not again, then don't use a database.

Link to comment
Share on other sites

http://www.mediafire.com/?mtttzytmdiiHere, Go here and download the SC2Replay File I uploaded to MediaFire. Then, goto http://www.sc2x.net/upload_file.php and upload that .SC2Replay File to the website. Watch what happens.
nm, i see in the above post you have a function for extracting the information from the replay file. That was my question, how is the actual information being processed, not how does the process work, clearly you submit a file and then information is displayed.
Link to comment
Share on other sites

nm, i see in the above post you have a function for extracting the information from the replay file. That was my question, how is the actual information being processed, not how does the process work, clearly you submit a file and then information is displayed.
I have a couple of other files on the FTP which are tied into that PHP Coding somewhere...http://code.google.com/p/phpsc2replay/source/browse/
Link to comment
Share on other sites

I have a couple of other files on the FTP which are tied into that PHP Coding somewhere...http://code.google.com/p/phpsc2replay/source/browse/
I assume I can ignore the "Create Table" Tutorial from this W3 Tutorial, as I've already created the Tables in phpMyAdmin. I'm just inserting the Tables right? Would I be inserting these Tables below the webform..? And how is it picking up the information this Parser exports? I haven't defined anything for which the Parser needs to store information in those Tables...
Link to comment
Share on other sites

as was mentioned earlier....

... just keep in mind that you've already done the creation in this case. You don't need to create any more tables, and PHP doesn't need to execute any "CREATE" statements either. So, either skip the "MySQL Create" part, or look at it, but don't try to repeat it on your host.
and you're not inserting tables, your inserting rows of data into the table.
Link to comment
Share on other sites

And how is it picking up the information this Parser exports? I haven't defined anything for which the Parser needs to store information in those Tables...
I don't know, that's why I was asking, but then I saw your really long post with all that code and assumed that there was a given process for all this. TBH, you should be concentrating on the basics at this point, I think you're trying to do too much too fast. READ the tutorials, practice creating forms and inserting information into your database, and then displaying it. Practice playing around with phpMyAdmin, learn some of the basic terms, get comfortable with all this before jumping head first into something complicated.
Link to comment
Share on other sites

as was mentioned earlier....and you're not inserting tables, your inserting rows of data into the table.
Right but those Tables are completely empty, aren't they? I haven't defined any means for which the parser needs to send that information to the Tables I've made...
Link to comment
Share on other sites

I'm starting to get the gist of this MySQL stuff, but I think what I'm doing isn't what I'm aiming for.Example:If I have a Form like this:

<form action="insert.php" method="post">First Name: <input type="text" name="first"><br>Last Name: <input type="text" name="last"><br>Phone: <input type="text" name="phone"><br>Mobile: <input type="text" name="mobile"><br>Fax: <input type="text" name="fax"><br>E-mail: <input type="text" name="email"><br>Web: <input type="text" name="web"><br><input type="Submit"></form>

And I have MySQL Commands like this:

<?$username="username";$password="password";$database="your_database";$first=$_POST['first'];$last=$_POST['last'];$phone=$_POST['phone'];$mobile=$_POST['mobile'];$fax=$_POST['fax'];$email=$_POST['email'];$web=$_POST['web'];mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";mysql_query($query);mysql_close();?>

All that's doing is taking the information that I placed into the Text Fields on the webform and inserting it into the Tables I've created in phpMyAdmin, but that doesn't quite work for what I'm doing. I have a Parser which is collecting the information from a File and displaying that information under the webform. (In the wrong location...)

Link to comment
Share on other sites

Right but those Tables are completely empty, aren't they? I haven't defined any means for which the parser needs to send that information to the Tables I've made...
Yes, you'd need to define that, and do it at upload time.But for now, you should probably try to enter some phony data from phpMyAdmin itself, and try to get it with a separate script. You can do the inserts from the list of your tables in phpMyAdmin (just click on the database name on the left). Go there, and in the "Action" group, you should have a link/button/icon/whatever that looks a little like a left arrow going between two bricks. When you hover over it, it should say "Insert". Click it, and it will let you insert a row into the table. Supply some phony data. Leave the "ID" field empty (because it's AUTO_INCREMENT, it should automatically get a different value every time, starting with 1).From that separate PHP script, connect to the DB, and do a select query that retrieves and echoes (or whatever) the row. To only display THAT row (and not all rows), write the ID as part of the "WHERE" in the select query. If you have no idea what that last sentence meant, see the tutorials again, and more precisely, the SELECT and WHERE parts.
Link to comment
Share on other sites

Archived

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


×
×
  • Create New...