/    Sign up×
Community /Pin to ProfileBookmark

fatal error…

ok, ive got 2 question, first is the upload script i tried to modify it to be able to upload say word docs as well so i changed:

[code=php]
@getimagesize($_FILES[$fieldname][‘tmp_name’])
or error(‘only image uploads are allowed’, $uploadForm);
[/code]

to

[code=php]
if($_FILES[$fieldname][‘tmp_name’] == “application/msword” || $_FILES[$fieldname][‘tmp_name’] == “image/jpeg”){
// rest of upload script
}else{
error(“Incorrect file type. Only MS word documents and jpeg’s can be uploaded”);
}
?>
[/code]

and when i tried to upload a jpeg it gave me this nice little message:

[quote]

Fatal error: Call to undefined function: error() in C:Program FilesxampphtdocsFile Upload Sitemember-upload.process.php on line 127

[/quote]

which happens to be this line:

[code=php]error(“Incorrect file type. Only MS word documents and jpeg’s can be uploaded”);[/code]

any suggestions on what i can do to make it work, also its originally bokeh’s script so i can post the full thing, but only a few things have changed, a few sql statements and it worked fine before i tried to change it to verifying the two types.

now my second question is im calling an array from a databse that has like 3 different fields, username, createdate, email, access. im tryin to count how many rows are in the array. but i cant seem to do it. ive tried “sizeof” and “count”. is there a special way i need to call it out of the database or something?

any help on either question would rock, ill also keep fiddling with it.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 05.2006 — The "TMP_NAME" element of the files array is the pathname of the temporary location of the uploaded file. It's not going to equal either of those mime types, unless you run it through some other function to determine the mime type.

Also, as there's no PHP function called error(), you might want to use trigger_error() instead.
Copy linkTweet thisAlerts:
@welshauthorMar 05.2006 — wut type of function could i use to determine the mime type?
Copy linkTweet thisAlerts:
@welshauthorMar 05.2006 — nevermind, found the answer in the php manual, but any clue how to count arrays?
Copy linkTweet thisAlerts:
@NogDogMar 05.2006 — nevermind, found the answer in the php manual, but any clue how to count arrays?[/QUOTE]
Do you meant like the [url=http://www.php.net/count]count()[/url] function?
Copy linkTweet thisAlerts:
@welshauthorMar 05.2006 — that didnt work, ive tried
[code=php]
include("database.inc");
$connection = mysql_connect($host,$user,$password)
or die ('Couldnt connect: '.$connection.' - Error: '.mysql_error());
$db = mysql_select_db($database, $connection)
or die ('Couldnt select database: '.$db.' - Error: '.mysql_error());
$sql = "SELECT loginName,createDate,email,access FROM members";
$result = mysql_query($sql)
or die ('Couldnt execute query: '.$sql.' - Error: '.mysql_error());
$array = mysql_fetch_array($result) or die(mysql_error());
$count = count($array);
[/code]

odds are im probally not doing something right, but there are two rows in that array yet it shows 1 or 8 depending if i do '$array' or $array.
Copy linkTweet thisAlerts:
@NogDogMar 05.2006 — mysql_fetch_array() returns one result row, with each column in that result being an array element, so if count($array) is 8, then that means 8 columns were retrieved by the query. If you want to know how many rows, just do [b]mysql_num_rows($result)[/b] (where $result is the return value from mysql_query()).

The most common idiom used is to just do a while loop of mysql_fetches:
[code=php]
$result = mysql_query($query) or die("Query failed: $query - " . mysql_error());
if(mysql_num_rows($result))
{
echo "<table>n";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
foreach($row as $value)
{
echo "<td>$value</td>";
}
echo "</tr>n";
}
echo "<table>n";
}
else
{
echo "<p>ERROR: no rows returned by query.</p>n";
}
[/code]
×

Success!

Help @welsh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...