Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Everything posted by Nodral

  1. Either that, or if it's needed in more than one place assign it to a $_SESSION variable when it gets returned to submitAction.php. Just make sure you session_start(); at the beginning of all your scripts which require the variables.
  2. You could create the $list array using id as the key then before you output it, use the array_reverse function.
  3. Ask them for $900. You can then negotiate and if you have to drop a couple of hundred dollars you'll still get what you want. Sounds like you need a business partner to run the monetary side while you bash your keyboard!!!
  4. Or you can create a file which checks if the user has the correct permissions of the various files and just include it at the start of each file. Dirty I know, but it works!!! <edit>Sorry, posted that at the same time. Great minds thing alike!!</edit>
  5. The best way is to factor that in. Nobody's perfect!! I don't actually work in coding but in my day to day job I occasionally make errors which I have to correct, however I don't get my wages docked because of these errors. You'll never get your code right first time, hence the phrase debugging!!! you always have to factor some time in for debugging and UAT testing before you will produce the desired results for a client.
  6. Try asking your question in an understandable way? What are you trying to acheive? What errors are you getting? What would the desired result be?
  7. Warning: move_uploaded_file(localhost/tmp/user_import.csv) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\Documents\AI24\Web\skooch\pfp\uploadFile.php on line 11 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\php4283.tmp' to 'localhost/tmp/user_import.csv' in D:\Documents\AI24\Web\skooch\pfp\uploadFile.php on line 11
  8. This works fine if I save it in the same directory, or move up a level or 2 using ../ etc. However, as soon as I add the tmp directory it falls over. This directory was manually created about 30 seconds before running the script. It is to mirror the structure I will have when I move to my live server. even the absolute path of $filename='localhost/tmp/user_import.csv'; fails
  9. Tried this and got the following errors $filename="../../../tmp/user_import.csv"; Warning: move_uploaded_file(../../../tmp/user_import.csv) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\Documents\AI24\Web\skooch\pfp\uploadFile.php on line 11 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\php427D.tmp' to '../../../tmp/user_import.csv' in D:\Documents\AI24\Web\skooch\pfp\uploadFile.php on line 11
  10. Hi I'm desperately going round in circles here trying to work out a save path for a file. Here is my structure. localhost/dir1/dir2/files I need to save in localhost/tmp What file path do I set $filename as? move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "$filename"
  11. Hi The explode thing is due to the format of the information in the csv file, the information as actuall saved as "SURNAME,FIRSTNAME",NUMBER in 2 columns. So first I have to break it apart and format it in a usable way, there's also trailing spaces etc and the number needs to be a 5 digit number, but there are some which have the zeros included and some without. Good call tho!!
  12. This is fairly straightforward to set up, however you'll struggle to get someone to spend the time writing all the code for you. I'd advise either reading the various tutorials on the web about CMS (content management systems) and have a blast at building your own, or advertise on the freelance board if you're able to pay someone to do it (or looking for someone requiring a bit of experience) There's loads of good tutorials out there, just google for php CMS tutorials and you should be able to get going fairly soon. Alternatively, if you PM me we can discuss rates lol
  13. Will you be looking to actually run the courses online? Are you just looking for a registration and user database?
  14. Ok I've tried this and it's not giving me the correct response. Because the user could be uploading a file which does affect a row before the sql statement falls over, thorpe's code will not work. Again with AyKay's code, it is possible to upload part of a file before the code falls over so this is not great either. Please see my code below. I want to upload a full csv (possibly a few hundred lines) but only if every line is correct. Is this possible, or do I need to serously rejig things? I'd also like to be able to detect the headers of the columns in the file and check these match prior to upload as currently I'm manually deleting the headers so they don't get uploaded as a record. Any ideas to this? <?php session_start(); include_once('connect.php'); include_once('functions.php'); include('is_logged_in.php'); $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $filename="users\user_import.csv"; if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "$filename")){ //read csv file and sort names out. $handle=fopen("$filename",r); $user=file($filename); foreach($user as $value){ $value=str_replace('"','',$value); //echo $value . "<br>"; $user_upload=explode(",",$value); $surname_upload=cleanInput(ucfirst(strtolower(trim($user_upload[0])))); $firstname_upload=cleanInput(strtolower($user_upload[1])); $firstname_upload=cleanInput(ucfirst(trim($firstname_upload))); $user_upload[2]=cleanInput(trim($user_upload[2])); $ed_upload=cleanInput(str_pad($user_upload[2], 5 , "0", STR_PAD_LEFT)); $password=md5(cleanInput(strtolower($surname_upload))); //insert into user table $sql="INSERT INTO pfp_user (ed, firstname, lastname, role, complete, password) VALUES ('$ed_upload', '$firstname_upload', '$surname_upload', 'user', 'no', '$password')"; $result = mysql_query($sql) ; if (!$sql){ $_SESSION['output']='<div class="warning">There is an error with your csv file<br>Please check and try again</div>'; fclose($handle); unlink($filename); $extra = 'admin_users.php'; header("Location: http://$host$uri/$extra"); } else { $_SESSION['output']='<div class="pagetext">Users Successfully Uploaded</div>'; fclose($handle); unlink($filename); $extra = 'admin_users.php'; header("Location: http://$host$uri/$extra"); } } }else { $extra = 'admin_users.php'; header("Location: http://$host$uri/$extra"); } ?>
  15. Sorry, I think we both posted at the same time. Great answer, just implementing now.
  16. I have the 'or die' statement in my code at the moment which is fine for testing the sql processing. However I now need something to prevent a user trying to upload an incorrect csv file, which at the moment would throw out a 'die' error. eg if my column names are name, DOB, phone number and someone tries to upload a csv which has 6 columns I want to simply output a message saying "There is a problem with your csv file, please check and retry" However at the moment I get the Warning and blah blah about sql errors which my users will panic about.
  17. And if this returns as 0 then it's fallen over, however if this is 1 or more then run the INSERT statement?
  18. Hi All I'm using a script to upload details from a csv file into a DB, however for security, I want to prevent an incorrect file being uploaded. How can I use the mysql_query($sql) function to decide whether to continue with the script? for exampl, if the function runs correctly then do one thing, however if the query falls over, do something else. I know you can use or die, however I'm not sure how to use this other than output a message.
  19. No worries, just pulling your leg. Twice the information is better than none!!
  20. I'm sure that's what I just said (except the $_SESSION bit) !! lol
  21. Change the form method to POST and also the variables to $_POST[]. You must change them both or they will not work.
  22. This would be possible, but you'd need to be able to generate the page and save it somewhere for future uses. If you imagine 10 users on 10 different systems trying to access the same page, each time someone requested the page you would need to refer back to what the 1st user did. As each page was called, the script would run and select another random selection. The easiest way to do this, would be to use a DB. So the 1st user accesses the page and $random is set to John You would then write this into a DB table with columns for the page and each random word. page_id | word1 | word2 | word3 | .................................................... You would then need to run a script in the following order each time the page was accessed [*]Is there an entry for the page in the DB table? If so, SELECT the relevant information [*]If no entry for the page, run random function [*]Once random function has been run, INSERT values into DB table for next view of page Hope this makes sense
  23. Hi, This indicates a problem with your SQL statement where you run your SELECT statement. The mysql_num_rows commandon line 19 is failing due to an error with the SELECT statement and sending an output to the browser, thus creting the further error when you try to send the header on line 30. Check your table name, is this correct? Try just running the SQL statement on your command line to ensure that it is working and hardcode your username and password in rather than using variables. Eventually you'll find the error and be able to correct it.
  24. Hi You could use something along these lines <?php $random=rand(0, array_count($name1)); echo $name1[$random]; ?>
×
×
  • 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.