Jump to content

ProcalX

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ProcalX's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm trying to use a php / mysql file upload using the $_FILE global but am having issues. Here is my code: <?php session_start(); include "functions.php"; write_head(); ?> <?php /* Array to hold error data when user fails to enter variables into required boxes */ $errors = array(); if (isset($_POST['submit']) && $_POST['submit']) { /* Get all posted data & protect against sql injection */ $isadmin = htmlentities($_POST["membertype"], ENT_QUOTES); $username = htmlentities($_POST["username"], ENT_QUOTES); $password = htmlentities($_POST["password"], ENT_QUOTES); $firstname = htmlentities($_POST["firstname"], ENT_QUOTES); $surname = htmlentities($_POST["surname"], ENT_QUOTES); $email = htmlentities($_POST["email"], ENT_QUOTES); $day = htmlentities($_POST["dayofbirth"], ENT_QUOTES); $month = htmlentities($_POST["monthofbirth"], ENT_QUOTES); $year = htmlentities($_POST["yearofbirth"], ENT_QUOTES); $shirtnumber = htmlentities($_POST["shirtnumber"], ENT_QUOTES); $position = htmlentities($_POST["playerposition"], ENT_QUOTES); $subteam = htmlentities($_POST["subteam"], ENT_QUOTES); $height = htmlentities($_POST["height"], ENT_QUOTES); $weight = htmlentities($_POST["weight"], ENT_QUOTES); //$pic= htmlentities($_POST['image'], ENT_QUOTES); /* Variable Check */ if (empty($_POST["membertype"])) { array_push($errors, 'Error: You did not submit a usertype.'); } if (empty($_POST["username"])) { array_push($errors, 'Error: You did not submit a username.'); } if (empty($_POST["password"])) { array_push($errors, 'Error: You did not submit a password.'); } if (empty($_POST["firstname"])) { array_push($errors, 'Error: You did not submit a user name.'); } if (empty($_POST["surname"])) { array_push($errors, 'Error: You did not submit a user surname.'); } if (empty($_POST["dayofbirth"])) { array_push($errors, 'Error: You did not submit a day of birth.'); } if (empty($_POST["monthofbirth"])) { array_push($errors, 'Error: You did not submit a month of birth.'); } if (empty($_POST["yearofbirth"])) { array_push($errors, 'Error: You did not submit a year of birth.'); } if (empty($_POST["playerposition"])) { array_push($errors, 'Error: You did not submit a user position.'); } if (empty($_POST["subteam"])) { array_push($errors, 'Error: You did not submit a member team.'); } if (empty($_POST["height"])) { array_push($errors, 'Error: You did not submit a member height.'); } if (empty($_POST["weight"])) { array_push($errors, 'Error: You did not submit a member weight.'); } //if (empty($_POST['image'])) { array_push($errors, 'Error: You did not submit a member picture.'); } foreach($errors as $e) { echo $e; echo "<br />\n"; } if (sizeof($errors) == 0) { //This is the directory where images will be saved $target = "images/profiles"; $target = $target . basename($_FILES['image']['username']); //This gets all the other information from the form $name=$_POST['username']; $pic=($_FILES['image']['username']); $check1 = mysql_query("SELECT * FROM rh_users WHERE username='$username'"); if (mysql_num_rows($check1)>0) { echo "The username '$username' already exists, choose an alternative."; } else { mysql_query("INSERT INTO rh_users (id,isadmin,username,password,firstname,surname,email,day,month,year,posts,joined,number,position,subteam,height,weight,image) VALUES ('','$isadmin','$username','$password','$firstname','$surname','$email','$day','$month','$year','0',NOW(),'$shirtnumber','$position','$subteam','$height','$weight','$pic')"); /* Write photo to the server */ if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { /* Check */ echo "The file ". basename( $_FILES['uploadedfile']['username']). " has been uploaded, and your information has been added to the directory."; echo "Registration succesful. <a href='admin_cp.php'>Click here to return to the Admin Control Panel</a>."; } else { echo "Sorry, there was a problem uploading your file."; } } } } else { echo "You have not submitted data into all the fields, all fields are required for user registration."; } ?> <?php write_footer(); ?> I am receiving these errors: Notice: Undefined index: username in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 56 Notice: Undefined index: username in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 60 Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 71 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php509A.tmp' to 'images/profiles' in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 71 Sorry, there was a problem uploading your file.
  2. I have tried this: //This is the directory where images will be saved $target = "images/profiles"; $target = $target . basename($_FILES['image']['username']); //This gets all the other information from the form $name=$_POST['username']; $pic=($_FILES['image']['username']); $check1 = mysql_query("SELECT * FROM rh_users WHERE username='$username'"); if (mysql_num_rows($check1)>0) { echo "The username '$username' already exists, choose an alternative."; } else { mysql_query("INSERT INTO rh_users (id,isadmin,username,password,firstname,surname,email,day,month,year,posts,joined,number,position,subteam,height,weight,image) VALUES ('','$isadmin','$username','$password','$firstname','$surname','$email','$day','$month','$year','0',NOW(),'$shirtnumber','$position','$subteam','$height','$weight','$pic')"); /* Write photo to the server */ if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { /* Check */ echo "The file ". basename( $_FILES['uploadedfile']['username']). " has been uploaded, and your information has been added to the directory."; echo "Registration succesful. <a href='admin_cp.php'>Click here to return to the Admin Control Panel</a>."; } else { echo "Sorry, there was a problem uploading your file."; } } But recieve errors: Notice: Undefined index: username in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 56 Notice: Undefined index: username in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 60 Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 71 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpD6CA.tmp' to 'images/profiles' in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 71 Sorry, there was a problem uploading your file.
  3. Hi all, creating a MYSQL, PHP & XHTML site designed to support local rugby clubs. Just putting the final touches to the functionality now so thanks for your help so far. I would like to provide site administrators with the ability to assign photos to a members profile when initially registering their account, I have no experience of dealing with what presumably will be a function that will upload a photo to a location and then linking it some how to data in the database. Thanks for your help, Tom
  4. Morning all, I'm trying to query a user table and am receiving errors. In the mysql statement I am trying to SELECT all data from the table that matches the username of the person logged in. The error I am receiving is this: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\123\myaccount.php The database query is written correctly, if I am logged in as the user Admin then I recieve this message as well: Unknown column 'Admin' in 'where clause' from the or die(mysql_error());. In the database the username is: admin but I can login using Admin, is this an issue of upper and lowercase? The PHP code is below: <?php require_once('connect.php'); $query = mysql_query("SELECT * FROM user WHERE username = $_SESSION[gatekeeper]"); while ($row = mysql_fetch_array($query) or die(mysql_error())); { echo"<div class='BlockContent'>"; echo" <table id='UserList'>"; echo" <tr>"; echo" <th>My Account</th>"; echo" </tr>"; echo" <tr>"; echo" <td id='left'>"; echo" </td>"; echo" </tr>"; echo" </table>"; echo"</div>"; } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.