Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User input script fails. each user belongs to one our more groups.

Status
Not open for further replies.

LordGarfield

IS-IT--Management
Joined
Jul 31, 2003
Messages
112
Location
BE
Hi all,

I post my source code here


This one works.
********user_i.php*********************
<html>
<body>
<table>
<form method=&quot;post&quot; action=&quot;user_o.php&quot;>
<tr>
<td>GEBRUIKERSNAAM:</td><td><input type=&quot;text&quot; name=&quot;unaam&quot;></td>
</tr>
<tr>
<td>NAAM:</td><td><input type=&quot;text&quot; name=&quot;anaam&quot;></td>
</tr>
<tr>
<td>VOORNAAM:</td><td><input type=&quot;text&quot; name=&quot;vnaam&quot;></td>
</tr>
<tr>
<td>PASWOORD:</td><td><input type=&quot;password&quot; name=&quot;paswoord&quot;></td>
</tr>
<tr>
<td>PASWOORD NOGMAALS:</td><td><input type=&quot;password&quot; name=&quot;paswoordc&quot;></td>
</tr>

<tr>
<td colspan=2>IS LID VAN</td>
</tr>

<?php
$con = mysql_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;);
mysql_select_db(&quot;rcomdb&quot;);
$rec = mysql_query(&quot;select * from groups&quot;);
$i=1;
while (list($id, $gnaam) = mysql_fetch_row($rec))
{
echo &quot;<tr><td>&quot; . $gnaam . &quot;</td><td><input type='checkbox' name='groep[]' value='&quot; . $id . &quot;'></td></tr>&quot;;
$i=$i + 1;
}
?>
<tr>
<td>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Toevoegen&quot;>
</td>
</tr>
</form>
</table>
</body>
</html>
****************end user_i.php***********************
This one has the error's
***************user_o.php**********************

<?php
$unaam = $_POST['unaam'];
$paswoord = $_POST['paswoord'];
$paswoordc = $_POST['paswoordc'];
$anaam = $_POST['anaam'];
$vnaam = $_POST['vnaam'];
echo $unaam . $paswoord . $anaam . $vnaam;
if ($unaam <> '' && $paswoord <> '' && $anaam <> '' && $vnaam <> '')
{

if ($paswoord == $paswoordc)
{

$db = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
mysql_select_db (&quot;rcomdb&quot;);
$sql = &quot;select usern from users where usern = &quot;. $unaam;
$result1 = mysql_query($sql);
if (mysql_num_rows($result1)>0)
{
echo 'Gebruiker bestaat reeds';
}
else
{
$sql = &quot;insert into users (usern, userp, naam, vnaam) values (&quot; .$unaam. &quot;,&quot; .$paswoord. &quot;,&quot; .$anaam. &quot;,&quot; .$vnaam. &quot;)&quot;;
$result2 = mysql_query($sql);
echo 'Gebruiker Toegevoegd';
$result3 = mysql_query(&quot;select userid from users where usern = $unaam&quot;);
$userid = mysql_fetch_row($result3);
$result4 = mysql_query(&quot;select groupid from groups&quot;);
$tot_row = mysql_num_rows($result4);
for ($i=0; $i < $tot_row; $i++)
{
$groupid = $_POST['groep'][$i];
$result5 = mysql_query(&quot;insert into usergroup (userid, groupid) values ( $userid, $groupid)&quot;);
}
}
mysql_close();
}
else
{
echo 'Paswoorden komen niet overeen.';
}
}
else
{
echo 'U moet alle velden invullen.';
}
?>

*****************end user_o.php*********************

And I shall post the php myadmin exports of the tables that are used.

CREATE TABLE `users` (
`userid` int(11) NOT NULL auto_increment,
`usern` varchar(100) NOT NULL default '',
`userp` varchar(100) NOT NULL default '',
`naam` varchar(100) NOT NULL default '',
`vnaam` varchar(100) NOT NULL default '',
PRIMARY KEY (`userid`)
) TYPE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2;


CREATE TABLE `groups` (
`groupid` int(11) NOT NULL auto_increment,
`naam` varchar(100) NOT NULL default '',
PRIMARY KEY (`groupid`)
) TYPE=MyISAM CHARSET=latin1 AUTO_INCREMENT=4 ;

INSERT INTO `groups` VALUES (1, 'Administratie');
INSERT INTO `groups` VALUES (2, 'Opvoeders');
INSERT INTO `groups` VALUES (3, 'Onderhoud');

CREATE TABLE `usergroup` (
`ugid` int(11) NOT NULL auto_increment,
`userid` int(11) NOT NULL default '0',
`groupid` int(11) NOT NULL default '0',
PRIMARY KEY (`ugid`)
) TYPE=MyISAM CHARSET=latin1 AUTO_INCREMENT=1 ;

The database is called rcomdb

When I execute this script I get this output

testtesttesttest
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\inetpub\ on line 18
Gebruiker Toegevoegd
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\inetpub\ on line 28

Notice: Undefined offset: 2 in c:\inetpub\ on line 33

Notice: Undefined offset: 3 in c:\inetpub\ on line 33


Also there is no user created in the database so it seems that even the insert into is failed but it gave not an error.

can anyone helping me??

I installed PHP 4.3.3.3 and MySQL 4.1 on IIS (Standard version on winXP pro I think it is 5)

Tank you so much.
 
I would write the queries like this

Code:
$sql = &quot;select usern from users where usern = '$unaam'&quot;;

$sql = &quot;insert into users (usern, userp, naam, vnaam) values ('$unaam','$paswoord','$anaam','$vnaam')&quot;;
            $result2 = mysql_query($sql);

            $result3 = mysql_query(&quot;select userid from users where usern = '$unaam'&quot;);

don't know if that will solve all your problems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top