
APD1993
Members-
Posts
55 -
Joined
-
Last visited
Never
Everything posted by APD1993
-
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!
-
How to get files to be created by users and uploaded to a folder?
APD1993 replied to APD1993's topic in PHP Coding Help
That's the thing though, the files are being created dynamically, so I can't really check for a specific filename at that point -
How to get files to be created by users and uploaded to a folder?
APD1993 replied to APD1993's topic in PHP Coding Help
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. -
How to get files to be created by users and uploaded to a folder?
APD1993 replied to APD1993's topic in PHP Coding Help
I got bool(true) -
How to get files to be created by users and uploaded to a folder?
APD1993 replied to APD1993's topic in PHP Coding Help
Whereabouts would I place that code? I'm not sure that it's a permission issue either -
How to get files to be created by users and uploaded to a folder?
APD1993 replied to APD1993's topic in PHP Coding Help
No luck for me when I tried that (used it in place of fputs) -
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.
-
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!
-
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"
-
...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!
-
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
-
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
-
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
-
I seem to be getting closer, but it still will not redirect on successful input :/ My code now reads as follows: <html><head><title>Multi-User Log In Form</title></head> <body> <?php $self = $_SERVER['PHP_SELF']; $username = $_POST['username']; $password = $_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> I am also getting a couple of messages appearing such as: Notice: Undefined variable: name in C:\xampp\htdocs\loginform2.php on line 16 Notice: Undefined variable: pass in C:\xampp\htdocs\loginform2.php on line 17 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\loginform2.php on line 20 :/ Thanks for the help so far, though
-
I am currently creating a multi-user login system, and I have created the database in MySQL, but the problem is that my PHP script is not working as expected. I would like it so that if the user enters in a correct username + password combination, then they are redirected to a webpage called "congrats.php" for example. However, with my current PHP code, if I include a redirection instruction based on the correct input, then when I run the script, then the user is instantly taken to the congrats.php page without filling in any login details. I'm quite sure that the database has been connected to, as due to the layout of my script at the moment, the text that reads "You did it!" appears 4 times, the same number of rows in my MySQL database. My PHP coding for this is: <html><head><title>Multi-User Log In Form</title></head> <body> <?php $self = $_SERVER['PHP_SELF']; $username = $_POST['username']; $password = $_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"); $sql = "select * from users"; $rs = mysql_query($sql, $conn); while ($row = mysql_fetch_array($rs)) { $name = $row["uname"]; $pass = $row["pword"]; if ($username = $name && $password = $pass) { //CODE FOR REDIRECTION SHOULD GO HERE //header("location:congrats.php"); echo "You did it!"; } else { echo "Invalid username and password combination"; } } ?></body> </html> Any help in trying to get it so that my PHP script will redirect only if a correct username + password combination is entered would be greatly appreciated
-
How to get the time the file was last modifed at in a PHP script
APD1993 replied to APD1993's topic in PHP Coding Help
Does anyone know how to try to fix this error? -
I do believe that there is a way that you can subtract a certain number of days that may be useful if your computer was to stay at the same time consistently. If the date was changed again, you may need to modify the script
-
It seems that you are asking two different questions here. In terms of setting the Timezone, maybe this website will help http://php.net/manual/en/timezones.php
-
How to get the time the file was last modifed at in a PHP script
APD1993 replied to APD1993's topic in PHP Coding Help
I got this error message: Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\viewfile3.php on line 13 When I used this code: <html><head> <title>RCM File List</title> <link rel="stylesheet" type="text/css" a href="/rcm/stylesheet.css"> </head> <body> <h1>Files in RCM Directory</h1> <?php $dir="C:/xampp/htdocs/rcm/*txt"; $filename='C:/xampp/htdocs/rcm/denman2.txt'; if (file_exists($filename)) { foreach(glob($dir) as $file) { $list = "<li><a href='readfile2.php'>Filename: $file</a></li><p>$filename was last changed on: " . date("F d Y H:i:s, filetime($filename));<br>"; } } ?> <ul> <?php echo $list; ?> </ul> </body> </html> -
How can I add button based hyperlinks to this particular PHP script?
APD1993 replied to APD1993's topic in PHP Coding Help
That seems to have done the job! Thanks -
I've heard about a function that does so, but I did not have much luck implementing it. Is is possible for me to get the time my file was modified in this script? <html><head> <title>RCM File List</title> <link rel="stylesheet" type="text/css" a href="/rcm/stylesheet.css"> </head> <body> <h1>Files in RCM Directory</h1> <?php $dir="C:/xampp/htdocs/rcm/*txt"; foreach(glob($dir) as $file) { $list = "<li><a href='readfile2.php'>Filename: $file</a></li><br>"; } ?> <ul> <?php echo $list; ?> </ul> </body> </html>
-
How can I add button based hyperlinks to this particular PHP script?
APD1993 replied to APD1993's topic in PHP Coding Help
So is there a way of fixing this issue then? -
I have a PHP script that has hyperlinks on that allow for the user to go to different pages, and I have managed to mainly get the hyperlinks to be button based ones, except on one of the pages, an error message appears, reading: Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\congrats.php on line 58 However, I do not see what the problem is. My congrats.php script is: <!--Here, I am creating a header and title (for the webpage) with the use of the <head> and <title> HTML tags. The title given to the webpage is Login Details. I then am using the </title> and </head> HTML tags in order to stop the creation of the title and header of the webpage--> <head><title>Login Details</title> <link rel="stylesheet" type="text/css" a href="/rcm/stylesheet.css"> </head> <!--Here, I am starting a PHP script--> <?php //Here, I am creating two variables called $loginname and $loginpassword that are being assigned the values of what is entered into and posted from the text box called name and the password box called pass in the loginform.php webpage $loginname=$_POST['name']; $loginpassword=$_POST['pass']; //Here, an IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname and the $loginpassword variables is empty (i.e. the 'name' text box and the 'pass' password box on the loginform.php page are both left empty), then the echo keyword is being used to help write a string to inform the user that they have not entered in a username or a password and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script if (empty($loginname) && empty($loginpassword)) { echo "You have not entered in a username or password"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch of the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname variable is empty (i.e. the 'name' text box on the loginform.php page is left empty), then the echo keyword is being used to help write a string to inform the user that they have not entered in a username and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script elseif (empty($loginname)) { echo "You have not entered in a username"; echo "<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch of the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginpassword variable is empty (i.e. the 'pass' password box on the loginform.php page is left empty), then the echo keyword is being used to help write a string to inform the user that they have not entered in a password and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script elseif(empty($loginpassword)) { echo "You have not entered in a password"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch to the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname and the $loginpassword variables is incorrect (i.e. the 'name' text box and the 'pass' password box on the loginform.php page are both left incorrectly filled in), then the echo keyword is being used to help write a string to inform the user that they have not entered in a correct username and password and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script elseif (($loginname != "mrjones")&& ($loginpassword != "January")) { echo "You have entered an incorrect username and password"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch to the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname variable is incorrect and the value assigned to the $loginpassword variable is ccorrect (i.e. the 'name' text box on the loginform.php page was filled in incorrectly and the 'pass' password box on the loginform.php page was filled in correctly), then the echo keyword is being used to help write a string to inform the user that they have not entered in a correct username and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script else if (($loginname !="mrjones") && ($loginpassword == "January")) { echo "You have entered in an incorrect username"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch to the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname variable is incorrect and the value assigned to the $loginpassword variable is ccorrect (i.e. the 'name' text box on the loginform.php page was filled in correctly and the 'pass' password box on the loginform.php page was filled in incorrectly), then the echo keyword is being used to help write a string to inform the user that they have not entered in a correct password and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script elseif (($loginname =="mrjones") && ($loginpassword != "January")) { echo "You have entered in an incorrect password"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an else branch to the IF statement is being created so as to essentially state that if all of the other branches of the IF statement above are passed through, then it means that the user managed to successfully log on and the echo keyword is being used to help write a string congratulating the user that they managed to log in and a link is provided for them to log off and go back to the loginform.php page and the exit function with no arguments in the parameters is being used to exit the script else { echo "<h1>Log In Successful!</h1>"; <form action="amendfile2.php" method="post"> <input type="submit" value="Amend to file"> </form> <form action="viewfile3.php" method="post"> <input type="submit" value="View Web Blog"> </form> <form action="loginform.php" method="post"> <input type="submit" value="Click here to go to the Log In Screen"> </form> } //Here, the PHP script is being ended ?> Any help is appreciated!