PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 4:18 pm
im using this to send info to the database
Code: Select all
<?php
if ($submit) {
// process form
$db = mysql_connect("localhost", "krunk_gtstat", "gtstat");
mysql_select_db("krunk_gtstat",$db);
$sql = "INSERT INTO stats (username,percent) VALUES ('$username','$percent')";
$result = mysql_query($sql);
} else{
// display form
} // end if
?>
<form method="GET" action="gtthing.php">
<font size=1 face="verdana" color=#000000>
Username:<br>
<input type"text" name="username" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
Games Won<br>
<input type"text" name="value1" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
Games lost by someone reaching 100 mojo<br>
<input type"text" name="value2" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
Games lost by zero<br>
<input type"text" name="value3" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
Games played<br>
<input type"text" name="value4" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
<input type="reset" value="Reset Form" name="reset" style="font-family: verdana; font-size: 8pt; color: #000000">
<input type="submit" value="Submit" name="send" style="font-family: verdana; font-size: 8pt; color: #000000">
</font>
coreycollins
Forum Commoner
Posts: 67 Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan
Post
by coreycollins » Sat Mar 20, 2004 4:21 pm
change stats to stat
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 4:21 pm
lol durh, newbie mistakes by me
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 4:23 pm
still doesnt work, anyway i gotta go and wont be on in a while, thanks for helping
coreycollins
Forum Commoner
Posts: 67 Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan
Post
by coreycollins » Sat Mar 20, 2004 4:26 pm
Your submit php code is never going to be run.
From the looks of it you're doing a get so you're going to have to do something like this:
Code: Select all
if (isset($_GET["action"]))
{
if ($_GET["action"] == "submit")
{
$db = mysql_connect("localhost", "krunk_gtstat", "gtstat");
mysql_select_db("krunk_gtstat",$db);
$sql = "INSERT INTO stats (username,percent) VALUES ('$username','$percent')";
$result = mysql_query($sql);
}
}
Then add this line to your form:
Code: Select all
<input type="hidden" name="action" value="submit">
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Mar 20, 2004 4:27 pm
It requires register_globals to be On (and it's off by default since PHP 4.2.0, and you're running 4.3.3), so check that with a <?php phpinfo() ?> page
edit coreycollins beat me to it
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sat Mar 20, 2004 4:30 pm
and to add on, a lil handy tip for debugging/trouble shooting. will save you grey hairs.
use the mysql_error(), thats what it was made for. ie -
Code: Select all
<?php
$sql = "INSERT INTO stats (username,percent) VALUES ('$username','$percent')" or die (mysql_error());
$result = mysql_query($sql) or die (mysql_error());
?>
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 10:13 pm
nope it doesnt seem to work
i've tried to work on it myself with the help from you guys but i doesnt seem to work
if someone could download the zip and do and look through it and see wut is wrong with it because im just about ready to give up on it
http://www.krunkdesigns.com/gtthing/gtthing.zip
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Mar 20, 2004 10:28 pm
line 16 in gtthing2.php:
Code: Select all
$sql = "INSERT INTO stats (username,percent) VALUES ('$username','$percent')";
But where is $username and $percent comming from?? You don't set those anywhere.....
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Mar 20, 2004 10:34 pm
you are aware that your insert statement will NEVER be called, aren't you??
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Mar 21, 2004 12:28 am
they are set in gtthing.php not in gtthing2.php
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Mar 21, 2004 10:38 am
should the
be in the same file as the
mysql connect code?
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Mar 21, 2004 10:58 am
well, if your going to use the variables in your WHERE clause, dont you think they need to be defined?
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Mar 21, 2004 11:35 am
i have action="gtthing.php"
Code: Select all
<form method="GET" action="gtthing.php">
and the variables are defined in gtthing.php, should that work
coreycollins
Forum Commoner
Posts: 67 Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan
Post
by coreycollins » Sun Mar 21, 2004 11:38 am
On a side note I found another problem with your code. On your form you never close it. After all the form stuff you need a </FORM>.