MySQL Error

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

User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post 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>
coreycollins
Forum Commoner
Posts: 67
Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan

Post by coreycollins »

change stats to stat
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

lol durh, newbie mistakes by me
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

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 »

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;
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 ;)
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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());
?>
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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.....
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

you are aware that your insert statement will NEVER be called, aren't you??
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

they are set in gtthing.php not in gtthing2.php
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

should the

Code: Select all

$username,$percent
be in the same file as the
mysql connect code?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

well, if your going to use the variables in your WHERE clause, dont you think they need to be defined?

:D
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post 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
coreycollins
Forum Commoner
Posts: 67
Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan

Post 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>.
Post Reply