Forum Moderators: coopster

Message Too Old, No Replies

Big PHP problem, can't figure it out

Need assistance figuring out a problem with my code.

         

Rex_Fenris

5:56 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Ok... I'm having a big problem here. For the user system I'm making for the organization I work for... in the admin section, the administrator inputs the information for a user and submits it and that data gets added to the database. The problem I'm encountering... the user gets added to the database successfully, however, in addition to that, a blank row is added to the DB with only a randomly generated password, creation date, and modification date.

I've spent about 2 hours looking over my code with the other IT guy at the office and for the life of me can't figure out why its adding the extra row to the database every time I try to add a new user.

This is my first time working with PHP and MySQL, so I'm sort of learning as I go here. Any suggestions or anything else not relating to this problem would also be greatly appreciated.

Thanks :)

[edited by: coopster at 6:00 pm (utc) on June 16, 2005]
[edit reason] no urls per TOS [webmasterworld.com] [/edit]

Rex_Fenris

6:31 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Ok... trying to post as little code as possible here... I figure this is the file where the problem is. Again, same problem as above.

<?php

require("sb_admin_header.php");
dbconnect_admin();

if ($error == 0)
{
$Email = $_POST['Email'];
$Password = passgen();
$NameFirst = $_POST['NameFirst'];
$NameLast = $_POST['NameLast'];
$NameMI = $_POST['NameMI'];
$NameSuffix = $_POST['NameSuffix'];
$Address1 = $_POST['Address1'];
$Address2 = $_POST['Address2'];
$City = $_POST['City'];
$StateProv = $_POST['StateProv'];
$ZipPostal = $_POST['ZipPostal'];
$Country = $_POST['Country'];
$CountryOther = $_POST['CountryOther'];
$PhoneHome = $_POST['PhoneHome'];
$PhoneWork = $_POST['PhoneWork'];
$PhoneCell = $_POST['PhoneCell'];
$Fax = $_POST['Fax'];
$Website = $_POST['Website'];
$Blog = $_POST['Blog'];
$DateCreated = $DateTime;
$DateModified = $DateTime;
$CommentsUser = $_POST['CommentsUser'];
$Registration = $_POST['Registration'];
$Kit = $_POST['Kit'];
$Engine = $_POST['Engine'];
$Prop = $_POST['Prop'];
$GearType = $_POST['GearType'];
$BuildStatus = $_POST['BuildStatus'];
$BuildHours = $_POST['BuildHours'];
$DateFirstFlight = $_POST['DateFirstFlight'];
$FlightHours = $_POST['FlightHours'];
$EmptyWeight = $_POST['EmptyWeight'];
$CruiseSpeed = $_POST['CruiseSpeed'];
$CommentsPlane = $_POST['CommentsPlane'];
$OfferStarClub = $_POST['OfferStarClub'];
$StarClubAccomodations = $_POST['StarClubAccomodations'];
$NearestAirport = $_POST['NearestAirport'];
$NearestAirportCode = $_POST['NearestAirportCode'];
$RunwayLenght = $_POST['RunwayLength'];
$RunwayInfo = $_POST['RunwayInfo'];
$DistanceFromAirport = $_POST['DistanceFromAirport'];
$CommentsStarClub = $_POST['CommentsStarClub'];

$error = 9;

mysql_query("
INSERT INTO userinfo VALUES (
'',
'$Email',
'$Password',
'$NameFirst',
'$NameLast',
'$NameMI',
'$NameSuffix',
'$Address1',
'$Address2',
'$City',
'$StateProv',
'$ZipPostal',
'$Country',
'$CountryOther',
'$PhoneHome',
'$PhoneWork',
'$PhoneCell',
'$Fax',
'$Website',
'$Blog',
'$DateCreated',
'$DateModified',
'$CommentsUser',
'$Registration',
'$Kit',
'$Engine',
'$Prop',
'$GearType',
'$BuildStatus',
'$BuildHours',
'$DateFirstFlight',
'$FlightHours',
'$EmptyWeight',
'$CruiseSpeed',
'$CommentsPlane',
'$OfferStarClub',
'$StarClubAccomodations',
'$NearestAirport',
'$NearestAirportCode',
'$RunwayLenght',
'$RunwayInfo',
'$DistanceFromAirport',
'$CommentsStarClub'
)");

if (mysql_affected_rows() == 1)
{
print("
<P ID=\"head1\">StarBase Administration</P>
<P ID=\"head2\">Add User - <FONT COLOR=\"#00DD00\">Success</FONT></P>
<P><A HREF=\"index.php\">StarBase Administration Index</A></P>
<HR>
<P><B>User $NameLast, $NameFirst $NameMI - $Email has been added to the StarBase.</B></P>
<P><A HREF=\"adduser.php\">Add another user</A></P>
");

mail_adduser($Email, $Password, $NameFirst, $NameLast);

} else {

$db_error = mysql_error();

print("
<P ID=\"head1\">StarBase Administration</P>
<P ID=\"head2\">Add User - <FONT COLOR=\"#FF0000\">Failure</FONT></P>
<HR>
<P><B>The following error occurred while attempting to add the user to the database:</B><BR>$db_error.</P>
<P><A HREF=\"adduser.php\">Return to the previous page</A></P>
<P><A HREF=\"index.php\">StarBase Administration Index</A></P>
");

}

} else {

print("
<P ID=\"head1\">StarBase Administration</P>
<P ID=\"head2\">Add User - <FONT COLOR=\"#FF0000\">Failure</FONT></P>
<HR>
<P><B>The following error occurred while attempting to add the user to the database:</B><BR>Text overflow error. The 10,000 character maximum limit for a text box was exceeded.</P>
<P><A HREF=\"adduser.php\">Return to the previous page</A></P>
<P><A HREF=\"index.php\">StarBase Administration Index</A></P>
");

}

require("sb_admin_footer.php");

?>

coopersita

6:46 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Is the first blank item (right before email) in your insert for the primary key?

INSERT INTO userinfo VALUES (
'',
'$Email',

Is that key generated successfully? Or is the stuff you mentioned being created there? Is the phantom row at the beginning or the end of your rows?

Rex_Fenris

6:50 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Is the first blank item (right before email) in your insert for the primary key?
INSERT INTO userinfo VALUES (
'',
'$Email',

Is that key generated successfully? Or is the stuff you mentioned being created there? Is the phantom row at the beginning or the end of your rows?

Yes, that's the UID (user ID number) field in the database. Autoincrement and primary key and such. The phantom fields have their own unique UID number which is 1 greater than the UID of the row that was actually supposed to be added. They are added at the end.

coopster

7:13 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How about exiting the script right before the INSERT statement to see if any rows were added?

And then, if no extra rows were added, move the exit [php.net] statement right after the INSERT (and right directly before the mysql_affected_rows() function and check the table again. If there are no extra rows, then you have at least narrowed it down to something further on in your code, possibly a later include() or something.