Jump to content

APD1993

Members
  • Posts

    55
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

APD1993's Achievements

Member

Member (2/5)

0

Reputation

  1. I'm trying to implement a simple submit button within a PHP script so that when it is clicked, the user goes back to the homepage. However, at the moment my coding does not work. Any ideas on how to solve this? My code at the moment is: <?php //Creating a variable that essentially is used to make sure that the file being created by the user will be named based on what they entered into the text box called filename that collected the Client's Surname they gave in the fileupload.html page and that the new, user created file will be stored in the RCM3 folder and will be stored in an HTML format $filename="C:/xampp/htdocs/RCM3/".$_POST['filename'].".html"; //Getting the car accident information from the text box named info on the fileupload.html page and using it as the content for the user created file $info=$_POST['info']; //Opening the file (by using the fopen function) and giving append and write permissions for the file $file=fopen($filename, 'a+w'); //Putting in the user created file name and the accident details into the new file by using the fputs function fputs($file, $info); //Closing the file and ending the editing of the file name and file contents by using the fclose function fclose($file); ?> <html><head><title>Creating An Accident Report Form</title></head> <body> <?php //Using an IF statement so that if the file has successfully been created, the file details (name, filepath and file size) will be displayed to the user, as well as a submit button that takes the user back to the RCM Homepage--> if(file_exists($filename)){ $file_length=filesize($filename); $msg = "<p>File created: $filename<br>"; $msg.="File size: $file_length bytes<br></p>"; //INSERT SUBMIT BUTTON HERE $msg.="<form action="Congrats.html" method="post" input type="submit" value="Go back to RCM Homepage"></form> echo ($msg); } //If the file does not exist, then an error message will appear telling the user that file was not able to be created. A submit button will also be in place so that the user can go back to the RCM Homepage if they so choose else { echo("Unable to create file"); } ?> </body> </html> Any help is appreciated!
  2. That's the thing though, the files are being created dynamically, so I can't really check for a specific filename at that point
  3. I just checked, and it does seem to be adding them to the folder. The thing that's confusing me now then is why it's saying that the file cannot be created when it has been created.
  4. Whereabouts would I place that code? I'm not sure that it's a permission issue either
  5. No luck for me when I tried that (used it in place of fputs)
  6. Hello, I am currently working on a basic content management system, one that allows for the user to enter in a file name in a text box and the contents of the file in another text box (fileupload.html). I would like it to be working so that when I click to submit this information, a file is created and stored in a folder on my computer called RCM3 by going through the fileupload.php script. However, whenever I try to create a file (e.g. enter a name and the contents in the text boxes), I get shown the "Unable to create file" message. The coding for my fileupload.html form is as follows: <html><head><title>File Uploader Page</title></head> <body> <h3>File Uploader</h3> <form action="fileupload.php" method="post" enctype="multipart/form-data"> File Name:<br> <input type="text" size="45" name="filename"><br> Extra Information:<br> <input type="text" name="info"> <input type="submit" value="Create File"> </form> </body> </html> And my coding for fileupload.php at the moment is: <?php $filename=$_POST['filename']; $info=$_POST['info']; $file=fopen("C:/xampp/htdocs/RCM3/".$filename, "w"); fputs($file, $info); fclose($file); ?> <html><head><title>Creating A File</title></head> <body> <?php if(file_exists($filename)){ $file_length=filesize($filename); $msg="File created: $filename"; $msg.="File size:$file_length bytes"; echo($msg); } else { echo("Unable to create file"); } ?> </body> </html> Any help is appreciated.
  7. I am creating a form that collects the details of users and then any errors cause for the error log to have errors noted and added to it. Part of my coding is this: else if (is_numeric($name)||is_int($name) && is_numeric($surname)||is_int($surname)) { echo "It seems that you have entered numerical values for the First Name and Surname fields. This has been added to the error log.<br><br>"; error_log("<br><br><b><u>Presence Error</b></u><br>The user has entered numerical values for First Name and Surname fields!<br>First Name entered: " . $name . "<br>Surname entered: " . $surname . "<br>Age entered: " . $age . "<br>Number Of Complete Weeks Since Accident entered: " . $weeks . "<br>Time that form was submitted: " . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if (is_numeric($name)||is_int($name)) { echo "It seems that you have entered a numerical value for the First Name field. This has been added to the error log.<br><br>"; error_log("<br><br><b><u>Presence Error</b></u><br>The user has entered a numerical value for First Name fields!<br>First Name entered: " . $name . "<br>Surname entered: " . $surname . "<br>Age entered: " . $age . "<br>Number Of Complete Weeks Since Accident entered: " . $weeks . "<br>Time that form was submitted: " . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if (is_numeric($surname)||is_int($surname)) { echo "It seems that you have entered a numerical value for the Surname field. This has been added to the error log.<br><br>"; error_log("<br><br><b><u>Presence Error</b></u><br>The user has entered a numerical value for the Surname field!<br>First Name entered: " . $name . "<br>Surname entered: " . $surname . "<br>Age entered: " . $age . "<br>Number Of Complete Weeks Since Accident entered: " . $weeks . "<br>Time that form was submitted: " . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } so that if a user enters in numerical values when letters need to be entered, then this gets added to the error log. However, even if I enter in a suitable surname (i.e. Jones), the first path (where both the first name and surname are detected as being numerical) runs when I want the path where only the first name contains just digits to be run. Any idea how to fix this? Any help is appreciated! Thanks!
  8. It's something that I'd want to use, yes BTW, I tried the coding and I have it like this: <html><head><title>Validating Car Accident Report Form Details</title></head> <?php $_POST = array_map('trim', $_POST); $name=$_POST["name"]; $surname=$_POST["surname"]; $age=$_POST["age"]; $weeks=$_POST["weeks"]; $subtime = strftime('%c'); $pass = "The details uploaded are fine<br><br>"; if (!empty($name) && !empty($surname) && !empty($age) && !empty($weeks)) { echo "It seems that you have not entered a value for the Name, Surname, Age or Weeks fields. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has not entered any values", 3, "C:/xampp/htdocs/errorlog.txt"); } else if (($age<18)&& ($weeks<=1)) { echo "It seems that you have entered an invalid age and number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has entered an age that is below 18 and the number of weeks since the accident is equal to or under 1 week!<br>Age entered:" . $age . "<br>Number Of Weeks Since Accident entered:" . $weeks . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($age<18) { echo "It seems that you have entered an invalid age. This has been added to the error log.<br><br>"; error_log("<b><u>Age Error</b></u><br>The user has entered an age that is below 18!<br>Age entered:" . $age . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($weeks<=1) { echo "It seems that you have entered an invalid age number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Week Error</b></u><br>The user has entered a number of weeks since the accident that is equal to or under 1 week!<br>Number Of Weeks Since Accident entered:" . $weeks . "<br> Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else { echo $pass; } echo "Car Accident Report Form details have been sent<br>"; echo "<a href='readlog.php'>Read Error Log</a>" ?> </html> And I left all of the fields blank, but I'm presented with this error message: It seems that you have entered an invalid age and number of weeks since the accident. This has been added to the error log. When I want it to display the first error message. Any idea why this is happening? EDIT: Ah, I got rid of the "!" marks since they were being used for "is not"
  9. ...added to an error log? Currently, my coding is as follows: Form to gather data: <html><head><title>Car Accident Report Form</title></head> <form action="errorlog.php" method="post"> First Name: <br><input type="text" name="name"><br> Surname:<br> <input type="text" name="surname"><br> Age: <br><input type="text" name="age"><br> Weeks Since Accident: <br><input type="text" name="weeks"><br> <input type="submit" value="Submit"> </form> Coding for error log: <html><head><title>Validating Car Accident Report Form Details</title></head> <?php $name=$_POST["name"]; $surname=$_POST["surname"]; $age=$_POST["age"]; $weeks=$_POST["weeks"]; $subtime = strftime('%c'); $pass = "The details uploaded are fine<br><br>"; if ((((trim($name)="" && trim($surname)="" && trim($age)="" && trim($weeks)="")))) { echo "It seems that you have not entered a value for the Name, Surname, Age or Weeks fields. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has not entered any values", 3, "C:/xampp/htdocs/errorlog.txt"); } if (($age<18)&& ($weeks<=1)) { echo "It seems that you have entered an invalid age and number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has entered an age that is below 18 and the number of weeks since the accident is equal to or under 1 week!<br>Age entered:" . $age . "<br>Number Of Weeks Since Accident entered:" . $weeks . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($age<18) { echo "It seems that you have entered an invalid age. This has been added to the error log.<br><br>"; error_log("<b><u>Age Error</b></u><br>The user has entered an age that is below 18!<br>Age entered:" . $age . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($weeks<=1) { echo "It seems that you have entered an invalid age number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Week Error</b></u><br>The user has entered a number of weeks since the accident that is equal to or under 1 week!<br>Number Of Weeks Since Accident entered:" . $weeks . "<br> Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else { echo $pass; } echo "Car Accident Report Form details have been sent<br>"; echo "<a href='readlog.php'>Read Error Log</a>" ?> </html> How can I get it so that if a user presses the space bar in a field, then the trim function sees that there's no white space and then this gets added to the error log? Any help is appreciated!
  10. Hi, I want to be able to add a primary key to a table through altering the table. At the moment, I am using coding such as: USE test3; ALTER table users ->ADD primary key (uname); But I get told: No database selected Does anyone know how to fix this? Any help is appreciated
  11. I think I'm getting closer now, the script is now in two different scripts and the redirecting seems to work. However, the problem now is that anything entered into the boxes will cause for the user to be redirected, rather than when the correct username + password combination is entered. My loginform3.html coding is: <html><head><title>Login form</title></head> <body> <form action = "loginscr.php" method = "post"> Username <input type = "text" name = "username" size = "8"> Password <input type = "password" name = "password" size = "8"> <input type = "submit" value="Login"> </form> </body> </html> And my loginscr.php coding is this: <?php $name = $_POST['username']; $pass = $_POST['password']; $squname = "root"; $sqpword = ""; $conn = @mysql_connect("localhost", $squname, $sqpword) or die ("Err: Conn"); $rs = mysql_select_db("test3", $conn) or die ("Err: Db"); $name = @mysql_real_escape_string(trim($name)); $pass = @mysql_real_escape_string(trim($pass)); $sql = "select * from users"; $rs = mysql_query($sql, $conn); // If you have more than one result, that's also a problem while ($row = mysql_fetch_array($rs)) { if (mysql_num_rows($rs)>=1) { // You might want to set some session variables here, too. header('Location:congrats.php'); } else { echo "Invalid username and password combination"; } } ?></body> </html> If anyone could help me with this issue, I would be very thankful
  12. Thank you for the follow up reply, but alas, it is not redirecting me on correct username + password input:( I think my code is now as the way that you suggested: <html><head><title>Multi-User Log In Form</title></head> <body> <?php $self = ''; $name = $_POST['username']; $pass = $_POST['password']; ?> <form action = "<?php echo $self; ?>" method = "post"> Username <input type = "text" name = "username" size = "8"> Password <input type = "password" name = "password" size = "8"> <input type = "submit" value="Submit"> </form> <?php $conn = mysql_connect("localhost", "root", "") or die ("Err: Conn"); $rs = mysql_select_db("test3", $conn) or die ("Err: Db"); $name = mysql_real_escape_string(trim($name)); $pass = mysql_real_escape_string(trim($pass)); $sql = "select * from users where name='$name' and pass='$pass'"; $rs = mysql_query($sql, $conn); if (mysql_num_rows($rs) >=1) { header('Location:congrats.php'); } else { echo "Invalid username and password combination"; } ?></body> </html> Again, thanks for the help that you've provided me with
×
×
  • 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.