4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Storing and displaying stats
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Wed Apr 23, 2003 2:23 am (20 years, 12 months ago) Reply with QuoteBack to Top

Could someone write some php for me, what im trying to do is have an html form that someone can enter some baseball stats into and press submit. Then these stats would be saved in a MySQL database. I also would like it so if they went to another web page it would display these stats.
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Wed Apr 23, 2003 5:38 am (20 years, 12 months ago) Reply with QuoteBack to Top

My recommendation is that you learn some simple PHP & SQL. This kind of script is the perfect way to get to grips with it. You read some tutorials, and then try it out yourself. Believe it or not, that's the way I learnt! (and it wasn't even that long ago - I used to stay away from databases Very Happy)

Arrow http://www.phpbuilder.com/columns/jesus19990308.php3
Arrow http://www.blazonry.com/scripting/linksdb/

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Thu Apr 24, 2003 4:25 pm (20 years, 12 months ago) Reply with QuoteBack to Top

This is the way I store the stats to the database. Is this right, I cant tell if it is storing them there.
Code:
<?php
$bating = $_POST[bating];
$usr = "username";
$pwd = "password";
$db = "database";
$host = "localhost";
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
$sql = "INSERT INTO Robinson_Stats (Bating) Values ($bating)";
?>

Also how would I set up the database. If I am storing numbers how would I format it.
Like what would be the type, length/values, attributes, null, default, and extra. Also should I use Primary, Index, Unique, or Fulltext .
I dont have a lot of time and im trying to get this going so any help would be good, and if anyone knows a link to a tutorial or can show me how to retrive and display these variables out of the database I would greatly appriciate it.
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Thu Apr 24, 2003 4:30 pm (20 years, 12 months ago) Reply with QuoteBack to Top

You're nearly there: you're just missing the code to run your SQL query, after $sql = ...., and the code to select the database you want to use. As to what format your columns should have, it depends on the content. How long are your numbers?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
jayant
Team Member



Joined: 07 Jan 2002
Posts: 262
Location: New Delhi, India

PostPosted: Thu Apr 24, 2003 5:19 pm (20 years, 12 months ago) Reply with QuoteBack to Top

Good start.

"You shall overcome... You shall overcome... someday... "

________________________________
Jayant Kumar
Member of the 4WebHelp Team
Nibble Guru - Computing Queries Demystified
GZip/ Page Compression Test
OfflineView User's ProfileFind all posts by jayantSend Personal MessageVisit Poster's WebsiteYahoo MessengerMSN Messenger
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Thu Apr 24, 2003 7:29 pm (20 years, 12 months ago) Reply with QuoteBack to Top

the longest will probably be 5 digits.
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Thu Apr 24, 2003 7:34 pm (20 years, 12 months ago) Reply with QuoteBack to Top

INT(5) would be the appropriate column type then, IMO.

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Thu Apr 24, 2003 9:27 pm (20 years, 12 months ago) Reply with QuoteBack to Top

I found this on the query but I dont think it is put together like i need it to be. It has a lot of things in there and I need help finding out what each one does.
Code:
if ($REQUEST_METHOD=="POST") {

$SQL = " INSERT INTO links ";
$SQL = $SQL . " (category, sitename, siteurl, description) VALUES ";
$SQL = $SQL . " ('$category', '$sitename','$siteurl','$description') ";
$result = mysql_db_query($db,"$SQL",$cid);
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

echo ("New Link Added\n");

}

mysql_close($cid);
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Thu Apr 24, 2003 9:37 pm (20 years, 12 months ago) Reply with QuoteBack to Top

I have a question, this is what my host tripod says
Quote:
Tripod uses a simplified connection method for accessing your database. You do not need any special parameters to access your data. To connect to your MySQL database using a PHP script, use the following code:

$db = mysql_connect()

does this mean i can replace this
Code:
$usr = "username";
$pwd = "password";
$db = "database";
$host = "localhost";
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }

with this
Code:
$db = mysql_connect()
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Thu Apr 24, 2003 9:45 pm (20 years, 12 months ago) Reply with QuoteBack to Top

Ok, I think I got the storing part, here is what I have.
Code:
<?php
$bating = $_POST[bating];
$db = mysql_connect("localhost","username","password");
mysql_select_db("user_uk_db",$db);
$sql = "INSERT INTO Robinson_Stats (Bating) Values ($bating)";
$result = mysql_query("SELECT bating FROM Robinson_Stats")
    or die("Invalid query: " . mysql_error());
?>
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
jayant
Team Member



Joined: 07 Jan 2002
Posts: 262
Location: New Delhi, India

PostPosted: Fri Apr 25, 2003 4:59 am (20 years, 12 months ago) Reply with QuoteBack to Top

You are not not querring the db to insert the new record.
Code:

$sql = "INSERT INTO Robinson_Stats (Bating) Values ($bating)";
$result = mysql_query("SELECT bating FROM Robinson_Stats")
    or die("Invalid query: " . mysql_error());


have following instead:
Code:

$sql = "INSERT INTO Robinson_Stats (Bating) Values ($bating)";
$result = mysql_query($sql)
    or die("Invalid query: " . mysql_error());

$result = mysql_query("SELECT bating FROM Robinson_Stats")
    or die("Invalid query: " . mysql_error());

________________________________
Jayant Kumar
Member of the 4WebHelp Team
Nibble Guru - Computing Queries Demystified
GZip/ Page Compression Test
OfflineView User's ProfileFind all posts by jayantSend Personal MessageVisit Poster's WebsiteYahoo MessengerMSN Messenger
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Fri Apr 25, 2003 2:41 pm (20 years, 12 months ago) Reply with QuoteBack to Top

I got it working, now I have another question. How do I overwrite a row, like if the row bating = 12 and the someone enters 4 it would change the 12 to 4 not put the 4 in with the 12. So the row bating would always have 1 number in it.
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
Darren
Team Member



Joined: 05 Feb 2002
Posts: 549
Location: London

PostPosted: Fri Apr 25, 2003 3:04 pm (20 years, 12 months ago) Reply with QuoteBack to Top

$sql = "UPDATE Robinson_Stats SET Bating = $bating";

I'm sure someone will have a better way but it might give you a clue...
BTW If there is more than one row you need to add a where clause or it will update all rows I believe.
OfflineView User's ProfileFind all posts by DarrenSend Personal MessageVisit Poster's Website
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Fri Apr 25, 2003 5:00 pm (20 years, 12 months ago) Reply with QuoteBack to Top

Is it possible to update multiple in 1 statement, like update bating and singles without having to put
Code:
$sql = "UPDATE Robinson_Stats SET Bating = $bating";
$sql = "UPDATE Robinson_Stats SET singles = $singles";
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Fri Apr 25, 2003 5:03 pm (20 years, 12 months ago) Reply with QuoteBack to Top

Code:
$sql = "UPDATE Robinson_Stats SET Bating = $bating, singles = $singles";

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   


Go to page 1, 2  Next

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.348141 seconds :: 19 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme