Jump to content

Is it possible to...


jtwillis

Recommended Posts

I have an idea...my boss wants me to make him a form where his son can enter all of his golf tourny stats. My idea was to make the form in php, then when it's submitted it gets posted to a page, seperated by tourny names. Also, I was needing to have the avg's of all his scores. How exactly would I go about doing this?

Link to comment
https://forums.phpfreaks.com/topic/155028-is-it-possible-to/
Share on other sites

It's probably easier for you if you toy abit with some simple data-pulling and inserting data. Try and look at this:

 

the html:

<?
//Require the function file so we have acces to the WriteGolf() function.
require_once("somefunctionfile.php");
?>
<form method='post' action='somefunctionfile.php'>
Tournament: <input type='text' name='tournament' /><br />
Points: <input type='text' name='points' /><br />
<input type='submit' name='submit' />
</form>
<br /><br /><br />
<?
//Writing out the data-base information.
GolfWrite();
?>

 

Then the php(the file: somefunctionfile.php):

if($_POST['submit'])
{
     //Check if either of the form-fields were empty, if any are, then return with an error message and kill the script.
     if(empty($_POST['tournament']) or empty($_POST['points']))
     {
           print "Error: either the tournament and/or point field was empty.";
           die;
     }
     //Set 2 variables from the posted information
     $tournament = $_POST['tournament'];
     $points = $_POST['points'];
     
     //Insert the typed information into your database
     mysql_query("INSERT INTO yourTable (tournament, points) VALUES ('$tournaments', '$points')");
     header("location: index.php");
}

function GolfWrite()
{
      //Pull the data out from the database
     $q = mysql_query("SELECT * FROM yourTable");
     //Here we have a while loop - while we have rows within the array of $q print the information below
     while($row = mysql_fetch_array($q))
     {
          //Printing out the data
          print "In Tournament: <b>". $row['tournament'] ."</b> - Boss' son got: <b>". $row['points'] ."</b> points<br />";
     }
}

 

probably better or easier ways to do it, but this should give you the basic idea of how input/output from a database works.

 

Link to comment
https://forums.phpfreaks.com/topic/155028-is-it-possible-to/#findComment-815404
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.