954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php error HELP!!!

Hey, i have recievied Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /u3.bristol/s20/ad999/public_html/register.php on line 63, i was wondering what the problem could be, i really need help as my dissertation deadline is coming soon.


<?php # Script 12.6 - register.php
// This is the registration page for the site.

// Set the page title and include the HTML header.
$page_title = 'Register';
include ('includes/headerlogin.html');

if (isset($_POST['submit'])) { // Handle the form.

require_once ('../mysql_connect1.php'); // Connect to the database.

// Check for a first name.
if (eregi ("^[[:alpha:].' -]{2,15}$", stripslashes(trim($_POST['first_name'])))) {
$fn = escape_data($_POST['first_name']);
} else {
$fn = FALSE;
echo 'Please enter your first name!


';
}

// Check for a last name.
if (eregi ("^[[:alpha:].' -]{2,30}$", stripslashes(trim($_POST['last_name'])))) {
$ln = escape_data($_POST['last_name']);
} else {
$ln = FALSE;
echo 'Please enter your last name!


';
}

// Check for an email address.
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) {
$e = escape_data($_POST['email']);
} else {
$e = FALSE;
echo 'Please enter a valid email address!


';
}

// Check for a username.
if (eregi ("^[[:alnum:]_]{4,20}$", stripslashes(trim($_POST['username'])))) {
$u = escape_data($_POST['username']);
} else {
$u = FALSE;
echo 'Please enter a valid username!


';
}

// Check for a password and match against the confirmed password.
if (eregi ("^[[:alnum:]]{4,20}$", stripslashes(trim($_POST['password1'])))) {
if ($_POST['password1'] == $_POST['password2']) {
$p = escape_data($_POST['password1']);
} else {
$p = FALSE;
echo 'Your password did not match the confirmed password!


';
}
} else {
$p = FALSE;
echo 'Please enter a valid password!


';
}

if ($fn && $ln && $e && $u && $p) { // If everything's OK.

// Make sure the username is available.
$query = "SELECT user_id FROM users WHERE username='$u'";
$result = @mysql_query ($query);

if (mysql_num_rows($result) == 0) { // Available.

// Add the user.
$query = "INSERT INTO users (username, first_name, last_name, email, password, registration_date) VALUES ('$u', '$fn', '$ln', '$e', PASSWORD('$p'), NOW() )";
$result = @mysql_query ($query); // Run the query.

if ($result) { // If it ran OK.

// Send an email, if desired.
echo 'Thank you for registering!';
include ('includes/footer.html'); // Include the HTML footer.
exit();

} else { // If it did not run OK.
// Send a message to the error log, if desired.
echo 'You could not be registered due to a system error. We apologize for any inconvenience.


';
}

} else { // The username is not available.
echo 'That username is already taken.


';
}

mysql_close(); // Close the database connection.

} else { // If one of the data tests failed.
echo 'Please try again.


';
}

}// End of the main Submit conditional.
?>

Register

First Name:

Last Name:

Email Address:

User Name: Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.

Password: Use only letters and numbers. Must be between 4 and 20 characters long.

Confirm Password:





<?php // Include the HTML footer.
include ('includes/footerlogin.html');
?>

bebuuk
Newbie Poster
4 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

I'd change the line above from

$result = @mysql_query ($query);

to

$result = @mysql_query ($query) or die(mysql_error() . '
'.$query);

and see if there is a problem with the query - like no database connection or something.

sarahk
Junior Poster
144 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
 

the result i got from one of the other forms after copying and pasted what u wrote was this:

"Unknown column 'upload_date' in 'field list'
SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description, DATE_FORMAT(upload_date, '%M %e, %Y') AS d FROM uploads ORDER BY upload_date DESC"

Just wanted to confirm if the database connection was fine, but the fields in the column are wrong

Many thanks again

you have been of great help

bebuuk
Newbie Poster
4 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

Hey everyone

i keep getting this error, everything else seems to be fine, but i can't find out what the solution is to this problem( i also keep getting this error when i want to add_file or add_url):-

Fatal error: Cannot redeclare escape_data() (previously declared in ../mysql_connect.php:36) in /u3.bristol/s20/ad999/public_html/add_file.php on line 13

this is the mysql_connect statement i wrote


<?php # Script 12.4 - mysql_connect.php

// This file contains the database access information. This file also establishes a connection to MySQL and selects the database.

// Set the database access information as constants.
DEFINE ('DB_USER', 'ad999');
DEFINE ('DB_PASSWORD', '040045022');
DEFINE ('DB_HOST', 'vega.soi.city.ac.uk');
DEFINE ('DB_NAME', 'ad999');

if ($dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) { // Make the connnection.

if (!mysql_select_db (DB_NAME)) { // If it can't select the database.

// Handle the error.
my_error_handler (mysql_errno(), 'Could not select the database: ' . mysql_error());

// Print a message to the user, include the footer, and kill the script.
echo 'The site is currently experiencing technical difficulties. We apologize for any inconvenience.


';
include_once ('includes/footer.html');
exit();

} // End of mysql_select_db IF.

} else { // If it couldn't connect to MySQL.

// Print a message to the user, include the footer, and kill the script.
my_error_handler (mysql_errno(), 'Could not connect to the database: ' . mysql_error());
echo 'The site is currently experiencing technical difficulties. We apologize for any inconvenience.


';
include_once ('includes/footer.html');
exit();

} // End of $dbc IF.

// Function for escaping and trimming form data.
function escape_data ($data) { //<---THIS IS THE PROBLEM
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string (trim ($data), $dbc);
} // End of escape_data() function.
?>

and heres the add_file.php.

<?php # Script 11.7 - add_file.php
// This page allows users to upload files to the server.

// Set the page title and include the HTML header.
$page_title = 'Upload a File';
include ('includes/header.html');

if (isset($_POST['submit'])) { // Handle the form.

require_once ('../mysql_connect.php'); // Connect to the database.

// Function for escaping and trimming form data.
function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string (trim ($data), $dbc);
} // End of escape_data() function.

// Check for a description (not required).
if (!empty($_POST['description'])) {
$d = escape_data($_POST['description']);
} else {
$d = '';
}

// Add the record to the database.
$query = "INSERT INTO uploads (file_name, file_size, file_type, description, upload_date) VALUES ('{$_FILES['upload']['name']}', {$_FILES['upload']['size']}, '{$_FILES['upload']['type']}', '$d', NOW())";
$result = @mysql_query ($query);

if ($result) {

// Create the file name.
$extension = explode ('.', $_FILES['upload']['name']);
$uid = mysql_insert_id(); // Upload ID
$filename = $uid . '.' . $extension[1];

// Move the file over.
if (move_uploaded_file($_FILES['upload']['tmp_name'], "../uploads/$filename")) {
echo 'The file has been uploaded!


';
} else {
echo 'The file could not be moved.


';

// Remove the record from the database.
$query = "DELETE FROM uploads WHERE upload_id = $uid";
$result = @mysql_query ($query);
}

} else { // If the query did not run OK.
echo 'Your submission could not be processed due to a system error. We apologize for any inconvenience.


';
}

mysql_close(); // Close the database connection.

} // End of the main Submit conditional.
?>

Fill out the form to upload a file:

File:

Description:

<?php
include ('includes/footer.html'); // Include the HTML footer.
?>

Many Thanks again

Mandip Panesar

bebuuk
Newbie Poster
4 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

You are including or requiring add_file.php more than once

use include_once() or require_once() to prevent the file from redeclaring the functions.

sarahk
Junior Poster
144 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
 

This is giving me a headache and i am sure it giving you guys it aswell, i keep recieving Warning: move_uploaded_file(../uploads/11): failed to open stream: Permission denied in /u3.bristol/s20/ad999/public_html/add_file.php on line 48, i am working from home and transferring my .php scripts to the university server, i don't know if this could be the case!!

<?php # Script 12.8 - add_file.php
// This page allows users to upload files to the server.

// Set the page title and include the HTML header.
$page_title = 'Upload a File';
include ('./includes/header.html');

function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string (trim ($data), $dbc);
} // End of escape_data() function.

$counter = 3; // Number of files to allow for.

if (isset($_POST['submitted'])) { // Handle the form.

require_once ('../mysql_connect.php'); // Connect to the database.

for ($i = 0; $i < $counter; $i++) { // Handle each uploaded file.

// Create index names to refer to the proper upload and description.
$filename = 'upload' . $i;
$description = 'description' . $i;

// Check for a file.
if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) {

// Check for a description (not required).
if (!empty($_POST[$description])) {
$d = "'" . escape_data($_POST[$description]) . "'";
} else {
$d = 'NULL';
}

// Add the record to the database.
$query = "INSERT INTO uploads (file_name, file_size, file_type, description) VALUES ('{$_FILES[$filename]['name']}', {$_FILES[$filename]['size']}, '{$_FILES[$filename]['type']}', $d)";
$result = mysql_query ($query);

if ($result) {

// Return the upload_id from the database.
$upload_id = mysql_insert_id();

// Move the file over.
if (move_uploaded_file($_FILES[$filename]['tmp_name'], "../uploads/$upload_id")) { <----THIS IS THE PROBLEM

echo 'File number ' . ($i + 1) . ' has been uploaded!


';

} else { // File could not be moved.

echo 'File number ' . ($i + 1) . ' could not be moved.


';

// Remove the record from the database.
$query = "DELETE FROM uploads WHERE upload_id = $upload_id";
$result = mysql_query ($query);

// Add more detailed error reporting, if desired.

}

} else { // If the query did not run OK.
echo 'Your submission could not be processed due to a system error. We apologize for any inconvenience.


';
// Print the query and invoke the mysql_error() function to debug.
}

} // End of if (isset($the_file)...

} // End of FOR loop.

mysql_close(); // Close the database connection.

} // End of the main Submit conditional.
?>

Fill out the form to upload a file:


<?php // Create the inputs.
for ($i = 0; $i < $counter; $i++) {
echo 'File:

Description:



';
}
?>


<?php
include ('./includes/footer.html');
?>

many thanks again

i owe you one!

bebuuk
Newbie Poster
4 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You