Script 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

Post Reply
deancast
Forum Newbie
Posts: 2
Joined: Thu Jul 21, 2011 7:03 pm

Script Error

Post by deancast »

I have a client that has a website one of my ex developers designed. It has an admin page for them to add a user name and pw and creates a directory so they can upload there campgrounds to display for sale.

This developer has been gone for several years now and I am having an issue with his admin.php file he created.
Here is the error I get when I try to add a new user:
You are user admin.
Warning: Variable passed to each() is not an array or object in /srv/httpd/www/campgroundsforsale.com/htdocs/admin.php on line 154
New user was created successfully

However it does not add the new user.
The following is the code for that area

<p>Please fill out the following form to create new user:</p>
<?php
makeForm(Array(0, "", "", "", Array()));
break;
case "fileuser":
$viewerID = $_REQUEST{'viewerID'};
if ($viewerID){
//delete this user first
$query="DELETE FROM Perms WHERE ViewerID=$viewerID";
mysql_query($query);
$query="DELETE FROM Viewers WHERE ViewerID=$viewerID";
mysql_query($query);
}
ini_set(magic_quotes_gpc, 1);
$userID = $_REQUEST{'userID'};
$userPass = $_REQUEST{'userPass'};
$userDesc = $_REQUEST{'userDesc'};
$query="INSERT INTO Viewers (ViewerUname, ViewerPass, ViewerDesc) VALUES
('$userID', '$userPass', '$userDesc')";
mysql_query($query);
$viewerID=mysql_insert_id();
$campID = $_REQUEST{'campID'};
$query="INSERT INTO Perms (ViewerID, CampNumber) VALUES ($viewerID, $num)";
while(list($oy, $num) = each($campID)){
mysql_query($query);
}
echo "<p>New user was created successfully.</p><hr>";
makeMenu();
break;

THE BOLD SECTION IN RED IS LINE 154. I HAVE NO CLUE ABOUT PHP SO ANY HELP OR SUGGESTIONS IS GREATLY APPRECIATED.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Script Error

Post by social_experiment »

Code: Select all

<?php
$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');

reset($fruit);
while (list($key, $val) = each($fruit)) {
    echo "$key => $val\n";
}
?> 
#
$campID = $_REQUEST{'campID'};
The example above is from the php manual and illustrates how each() works in conjunction with list(). The value of $campID is not an array (as stated in the error message).
The form submitted to create the user, to which url does it go? (action="page.php") Can you paste the code that creates that form
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
deancast
Forum Newbie
Posts: 2
Joined: Thu Jul 21, 2011 7:03 pm

Re: Script Error

Post by deancast »

<html>
<head>
<title>Administration interface for Campgroundsforsale.com</title>
</head>
<body bgcolor="whitesmoke" text="navy">
<h2>Administering users</h2>
<hr>
You are user <b>admin</b>. <p>Please fill out the following form to create new user:</p>
<form method="post" action="/admin.php">
<input type="hidden" name="MOD" value="fileuser">
<input type="hidden" name="viewerID" value="0">
<table border="0" width="50%">
<tr>
<td>Username:</td><td><input name="userID" maxlength="10"
value=""></td>
</tr>
<tr>
<td>Password:</td><td><input name="userPass" maxlength="10"
value=""></td>
</tr>
<tr>
<td>Brief description (e.g. name):</td><td><input name="userDesc"
value=""></td>
</tr>
<tr>
<th colspan="2">Allow access to these campgrounds:</th>
</tr>
<tr>
<td colspan="2">
<input type='checkbox' name='campID[]' value='297'>&nbsp;297,
<input type='checkbox' name='campID[]' value='999'>&nbsp;999,
<input type='checkbox' name='campID[]' value='240'>&nbsp;240,
<input type='checkbox' name='campID[]' value='241'>&nbsp;241,
<input type='checkbox' name='campID[]' value='242'>&nbsp;242,
<input type='checkbox' name='campID[]' value='243'>&nbsp;243,
<input type='checkbox' name='campID[]' value='901'>&nbsp;901,
<input type='checkbox' name='campID[]' value='902'>&nbsp;902,
<input type='checkbox' name='campID[]' value='903'>&nbsp;903,
<input type='checkbox' name='campID[]' value='244'>&nbsp;244,
<input type='checkbox' name='campID[]' value='245'>&nbsp;245,
<input type='checkbox' name='campID[]' value='246'>&nbsp;246,
<input type='checkbox' name='campID[]' value='247'>&nbsp;247,
<input type='checkbox' name='campID[]' value='249'>&nbsp;249,
<input type='checkbox' name='campID[]' value='248'>&nbsp;248,
<input type='checkbox' name='campID[]' value='250'>&nbsp;250,
<input type='checkbox' name='campID[]' value='251'>&nbsp;251,
<input type='checkbox' name='campID[]' value='252'>&nbsp;252,
<input type='checkbox' name='campID[]' value='253'>&nbsp;253,
<input type='checkbox' name='campID[]' value='255'>&nbsp;255,
<input type='checkbox' name='campID[]' value='254'>&nbsp;254,
<input type='checkbox' name='campID[]' value='256'>&nbsp;256,
<input type='checkbox' name='campID[]' value='257'>&nbsp;257,
<input type='checkbox' name='campID[]' value='258'>&nbsp;258,
<input type='checkbox' name='campID[]' value='259'>&nbsp;259,
<input type='checkbox' name='campID[]' value='260'>&nbsp;260,
<input type='checkbox' name='campID[]' value='_vti_cnf'>&nbsp;_vti_cnf,
<input type='checkbox' name='campID[]' value='261'>&nbsp;261,
<input type='checkbox' name='campID[]' value='263'>&nbsp;263,
<input type='checkbox' name='campID[]' value='265'>&nbsp;265,
<input type='checkbox' name='campID[]' value='264'>&nbsp;264,
<input type='checkbox' name='campID[]' value='262'>&nbsp;262,
<input type='checkbox' name='campID[]' value='268'>&nbsp;268,
<input type='checkbox' name='campID[]' value='267'>&nbsp;267,
<input type='checkbox' name='campID[]' value='266'>&nbsp;266,
<input type='checkbox' name='campID[]' value='270'>&nbsp;270,
<input type='checkbox' name='campID[]' value='269'>&nbsp;269,
<input type='checkbox' name='campID[]' value='271'>&nbsp;271,
<input type='checkbox' name='campID[]' value='272'>&nbsp;272,
<input type='checkbox' name='campID[]' value='273'>&nbsp;273,
<input type='checkbox' name='campID[]' value='275'>&nbsp;275,
<input type='checkbox' name='campID[]' value='274'>&nbsp;274,
<input type='checkbox' name='campID[]' value='276'>&nbsp;276,
<input type='checkbox' name='campID[]' value='278'>&nbsp;278,
<input type='checkbox' name='campID[]' value='277'>&nbsp;277,
<input type='checkbox' name='campID[]' value='279'>&nbsp;279,
<input type='checkbox' name='campID[]' value='282'>&nbsp;282,
<input type='checkbox' name='campID[]' value='281'>&nbsp;281,
<input type='checkbox' name='campID[]' value='283'>&nbsp;283,
<input type='checkbox' name='campID[]' value='284'>&nbsp;284,
<input type='checkbox' name='campID[]' value='280'>&nbsp;280,
<input type='checkbox' name='campID[]' value='285'>&nbsp;285,
<input type='checkbox' name='campID[]' value='286'>&nbsp;286,
<input type='checkbox' name='campID[]' value='287'>&nbsp;287,
<input type='checkbox' name='campID[]' value='288'>&nbsp;288,
<input type='checkbox' name='campID[]' value='289'>&nbsp;289,
<input type='checkbox' name='campID[]' value='291'>&nbsp;291,
<input type='checkbox' name='campID[]' value='292'>&nbsp;292,
<input type='checkbox' name='campID[]' value='293'>&nbsp;293,
<input type='checkbox' name='campID[]' value='295'>&nbsp;295,
<input type='checkbox' name='campID[]' value='296'>&nbsp;296,
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="File this user >>"></td>
</tr>
</table>
</form>
<hr>
<p><small><a href="/admin.php">Return to main menu</a><br>For support
contact <a href="mailto:dean@corpdatas.net">dean@corpdatas.net</a></small></p>
</body>
</html>
Post Reply