Jump to content

ProcalX

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Everything posted by ProcalX

  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>"; } ?>
  5. Thanks for your help but I've sorted it; Work out todays date + 2 days: $twodays = time()+60*60*24*2; This stores the date 2 days ahead of the present day in seconds then we check this against the date stored in the database via the mysql_fetch_array: $eventdate = strtotime("$row[year]-$row[month]-$row[day]"); This converts the day, month and year stored in the database into the same time format (in unix timestamp seconds) Then check against each other using an If statement. I hope this helps anyone else!
  6. The $sql selects all from the BOOKINGS table where the ID matches that of the bookingID, this will select everything within the bookings table subject to these parameters, which includes the columns: day / month / year. The idea here was to insert straight from the mysql_fetch_array the day / month / year straight into the PHP DATE function and store it to $eventdate variable so that the full date of the event is stored from the database into a variable within the script. This may be wrong but I am unsure how to go about this? Can you help?
  7. I have a MYSQL database, within this database is a table that has three columns: day/month/year in this format: 10/10/2010. I am trying to validate a script so that a user cannot cancel a booking if it is 48 hours before the event, or the event has past. This is what I have so far: <?php $bookingid = $_GET["id"]; $date = strtotime(date("Y-m-d", strtotime($date)) . " +2 days"); //todays date +2 days if ($bookingid != "") { //check both events $sql = "SELECT bookings.ID AS bid, events.* FROM bookings,events WHERE bookings.id = $bookingid AND bookings.eventID = events.ID"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $eventdate = date("Y-m-d","$row[year]-$row[month]-$row[day], int mktime ([ int $hour = 0 [, int $minute = 0 [, int $second = 0 [, int $month = $row[month] [, int $day = $row[day] [, int $year = $row[year] [, int $is_dst = -1 ]]]]]]] )"); if ($eventdate < $date) { echo "Event Date: $eventdate <br /><br />"; echo "Todays Date + 2 Days: $date<br /><br />"; $sql = "SELECT * FROM bookings WHERE ID = $bookingid"; $result = mysql_query($sql); $row = mysql_fetch_array($result); if (mysql_num_rows($result)==1) { //Update quantity of tickets for event $mysql = "UPDATE events SET availability = availability + $row[ntickets] WHERE ID = $row[eventID]"; mysql_query($mysql); //Delete booking from bookings table $mysql = "DELETE FROM bookings WHERE ID = $bookingid"; mysql_query($mysql); echo "You have succesfully cancelled booking id: $bookingid"; } } else { echo "You cannot cancel a booking 48 hours before the event."; } } mysql_close($conn); ?> The script runs fine, however it does not validate properly, Event Date shows as: 1970-01-01 and Todays date + 2 days shows as: 172800. Unsure why event date is showing like this, I believe this is the earliest date that unix can handle?
  8. I know that session_start() has to be at the very top of the page and cannot have any white spaces before etc but I can't figure out why I am receiving this error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/though/public_html/test/signup_form.php:1) in /home/though/public_html/test/signup_form.php on line 2 The full code for the page is: <?php session_start(); include "write_templates.php"; write_head("title here etc etc", false); ?> <?php if (isset($_SESSION['xxx'])) { echo "You are already logged in as $_SESSION[xxx], if this is not you, logout."; } else { echo "<form method='post' action='signup.php' name='input' class='style2'>"; echo "<p>"; echo "Username:<br />"; echo "<input type='text' name='username' /><br /><br />"; echo "Password:<br />"; echo "<input type='password' name='password' /><br /><br />"; echo "Name:<br />"; echo "<input type='text' name='name' /><br /><br />"; echo "Date of Birth (DD/MM/YYYY):<br />"; echo "<input type='text' name='dayofbirth' />"; echo "<input type='text' name='monthofbirth' />"; echo "<input type='text' name='yearofbirth' /><br /><br />"; echo "<input type='submit' value='Send' />"; echo "<input type='reset' value='Reset' />"; echo "</p>"; echo "</form>"; } ?> <?php write_footer(); ?> Thanks
  9. Being new to PHP how would I write that into the code? I have put it after the line where I am getting the error and it makes no difference so suspect I am putting it in wrong.
  10. When trying to run $t_result and $a_t_result mysql queries I get errors: $a_result works fine. I get errors at line 17 for $a_t_result and at line 28 for $t_result. I am searching for either: Chemical Brothers (artist) & galvanize (title) together (error @ line 28) or no artist & galvanize (title) together (errors @ line 17) searching for just artist works fine. Error recieved on both lines is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/though/public_html/searchresults.php on line 17 <?php $a = $_POST["artist"]; $t = $_POST["title"]; $conn = mysql_connect("localhost", "abcde", "abcde"); mysql_select_db("abcde"); $a_t_result = mysql_query ("select * from hits where artist='$a' and title='$t'"); $t_result = mysql_query ("select * from hits where title='$t'"); $a_result = mysql_query ("select * from hits where artist='$a'"); if($a !=""&&$t !="") { while($row = mysql_fetch_array($a_t_result)) { echo " Song Title: $row[song] <br/> " ; echo " Artist: $row[artist] <br/> " ; echo " Year: $row[year] <br/> " ; echo " Chart Position: $row[chart] <br/> " ; echo " Searching Artist and Title Worked! " ; } } elseif($t !="") { while($row = mysql_fetch_array($t_result)) { echo " Song Title: $row[song] <br/> " ; echo " Artist: $row[artist] <br/> " ; echo " Year: $row[year] <br/> " ; echo " Chart Position: $row[chart] <br/> " ; echo " Searching Title Only Worked! " ; } } elseif($a !="") { while($row = mysql_fetch_array($a_result)) { echo " Song Title: $row[song] <br/> " ; echo " Artist: $row[artist] <br/> " ; echo " Year: $row[year] <br/> " ; echo " Chart Position: $row[chart] <br/> " ; echo " Searching Artist Only Worked! " ; } } mysql_close($conn); ?> New to PHP, just building the foundations of the script at the moment, integrity will be brought in later on once its working. thanks for your help guys, majorly stumped by this? lol
×
×
  • 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.