Page 3 of 5

Posted: Sat Mar 20, 2004 4:18 pm
by bawla
im using this to send info to the database

Code: Select all

<?php



if ($submit) &#123;

  // 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);


&#125; else&#123;



  // display form







&#125; // 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>

Posted: Sat Mar 20, 2004 4:21 pm
by coreycollins
change stats to stat

Posted: Sat Mar 20, 2004 4:21 pm
by bawla
lol durh, newbie mistakes by me

Posted: Sat Mar 20, 2004 4:23 pm
by bawla
still doesnt work, anyway i gotta go and wont be on in a while, thanks for helping

Posted: Sat Mar 20, 2004 4:26 pm
by coreycollins
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

&lt;input type="hidden" name="action" value="submit"&gt;

Posted: Sat Mar 20, 2004 4:27 pm
by markl999
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 ;)

Posted: Sat Mar 20, 2004 4:30 pm
by tim
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());
?>

Posted: Sat Mar 20, 2004 10:13 pm
by bawla
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

Posted: Sat Mar 20, 2004 10:28 pm
by Illusionist
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.....

Posted: Sat Mar 20, 2004 10:34 pm
by Illusionist
you are aware that your insert statement will NEVER be called, aren't you??

Posted: Sun Mar 21, 2004 12:28 am
by bawla
they are set in gtthing.php not in gtthing2.php

Posted: Sun Mar 21, 2004 10:38 am
by bawla
should the

Code: Select all

$username,$percent
be in the same file as the
mysql connect code?

Posted: Sun Mar 21, 2004 10:58 am
by tim
well, if your going to use the variables in your WHERE clause, dont you think they need to be defined?

:D

Posted: Sun Mar 21, 2004 11:35 am
by bawla
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

Posted: Sun Mar 21, 2004 11:38 am
by coreycollins
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>.