PHP - Need Help With Php Editing Files
the files are created upon registration. just i get this error..
Warning: include(1) [function.include]: failed to open stream: No such file or directory in /home/bob/public_html/mysite/profiles/write.php on line 129 Warning: include(1) [function.include]: failed to open stream: No such file or directory in /home/bob/public_html/mysite/profiles/write.php on line 129 Warning: include() [function.include]: Failed opening '1' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/bob/public_html/mysite/profiles/write.php on line 129 Code: [Select] $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) $filename = "/home/bob/public_html/mysite/profiles/profileinfo/$username.info.php" or exit("Unable to open file!"); $handle = fopen($filename, 'w')or die; $content = "<b>Firstname: </b>$firstname <br> <b> Lastname: </b> $lastname <p> <b> Birthday: </b>$day $month $year <br> <b> Location: </b> $location"; fwrite($handle, $content)or die; fclose($handle); } $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) include ("/home/bob/public_html/mysite/profiles/profileinfo/$username.info.php")or die; Similar TutorialsHello I have the following code from php websites
$myfile = fopen("/config.php", "a+") or die("Unable to open file!"); while(!feof($myfile)) { echo fgets($myfile) . "<br>"; $txt = "Mickey Mouse\n"; fwrite($myfile, $txt); }inside config.php is <?php define('script_path', 'files'); ?>How can I replace files with another value? any help would be great thanks. Hi guys, im logging activity on my site to text files using; Code: [Select] date_default_timezone_set('GMT'); $LogFileLocation = "xxxxxxxx.log"; $fh = fopen($_SERVER['DOCUMENT_ROOT'].$LogFileLocation,'at'); fwrite($fh,date('d.M.Y H:i:s')."\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REQUEST_URI']."\n"); fclose($fh); This is write something like; [date] [time] [ip address] [folder accessed] I then post it like; Code: [Select] <? $fn = "xxxxxxxxxx.log"; print htmlspecialchars(implode("",file($fn))); ?> That works fine but what i want to be able to do is read/edit the text files, so the main things i need to add is; The ability to clear the log (using password for confirmation) not sure how to go about this because i don't know how to edit the text file <input name="password" type="text"> <input type="submit" value="Clear Log?"> I also need a script to read the log and alert me an ip address that isn't mine is found, maybe something like if (an ip that isn't mine == yes) echo "an unknown ip accessed something" Also lets say i have a script that checks if a name exists, how can i use a text file containing a list of names to be read by a script if (name exists in text file) echo "name exists" else echo "name doesn't exist" All these questions are similar in the fact i need to understand how to open and read text files for specific entries, hope you understand, thanks for any help. Hey guys, im new hear so im not shore how things work. Iv got a project where we are ment to alow users to record a bug fault in a computer, currently i have a page that looks like ths: <?php if (empty($_POST['bug_ID'])) echo "<p>You must enter a BUG ID number</p>"; else { $bugID = addslashes($_POST['bug_ID']); $name = addslashes($_POST['bug_name']); umask(0007); if (!file_exists("../../data/lab05")) mkdir("../../data/lab05", 02777); $lab05 = fopen("../../data/lab05/". "$bugID.txt", "a"); if (is_writable("../../data/lab05/NewBug.txt")) { if (fwrite($lab05, $bugID . ", " . $name . "\n")) echo "<p>Thank you entering a new bug</p>"; else echo "<p>Cannot add bug</p>"; } else echo "<p>Cannot write to the file.</p>"; fclose($lab05); } ?> this code runs fine however I also need to write a sperate page that allows for users to search and up date bugs recorded, I want them to search using the bug_ID field and we are ment to use the fgets method but am unshore, anyhelp would be much apricated. thank you So i have this CMS that is used by lots of users and generally they do have rights to edit each others article. So now i'm thinking how can i at least warn them that somebody else is already editing it. Just that. maybe with sessions? but what happens when a user just closes the windows, will it destroy it. i taught about storing the value to mySQL but again what if the user closes the windows and so on. i never did this and i could use a boost. thanks guys So far I have managed to create an upload process which uploads a picture, updates the database on file location and then tries to upload the db a 2nd time to update the Thumbnails file location (i tried updating the thumbnails location in one go and for some reason this causes failure) But the main problem is that it doesn't upload some files Here is my upload.php <?php include 'dbconnect.php'; $statusMsg = ''; $Title = $conn -> real_escape_string($_POST['Title']) ; $BodyText = $conn -> real_escape_string($_POST['ThreadBody']) ; // File upload path $targetDir = "upload/"; $fileName = basename($_FILES["file"]["name"]); $targetFilePath = $targetDir . $fileName; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); $Thumbnail = "upload/Thumbnails/'$fileName'"; if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf', "webm", "mp4"); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $conn->query("INSERT into Threads (Title, ThreadBody, filename) VALUES ('$Title', '$BodyText', '$fileName')"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; $targetFilePathArg = escapeshellarg($targetFilePath); $output=null; $retval=null; //exec("convert $targetFilePathArg -resize 300x200 ./upload/Thumbnails/'$fileName'", $output, $retval); exec("convert $targetFilePathArg -resize 200x200 $Thumbnail", $output, $retval); echo "REturned with status $retval and output:\n" ; if ($retval == null) { echo "Retval is null\n" ; echo "Thumbnail equals $Thumbnail\n" ; } }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, mp4, webm & PDF files are allowed to upload.'; } }else{ $statusMsg = 'Please select a file to upload.'; } //Update SQL db by setting the thumbnail column to equal $Thumbnail $update = $conn->query("update Threads set thumbnail = '$Thumbnail' where filename = '$fileName'"); if($update){ $statusMsg = "Updated the thumbnail to sql correctly."; echo $statusMsg ; } else { echo "\n Failed to update Thumbnail. Thumbnail equals $Thumbnail" ; } // Display status message echo $statusMsg; ?> And this does work on most files however it is not working on a 9.9mb png file which is named "test.png" I tested on another 3.3 mb gif file and that failed too? For some reason it returns the following Updated the thumbnail to sql correctly.Updated the thumbnail to sql correctly. Whereas on the files it works on it returns REturned with status 0 and output: Retval is null Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif' Failed to update Thumbnail. Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif'The file rainbow-trh-stache.gif has been uploaded successfully. Any idea on why this is? Hello I have a simple question about file handling... Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs, and put the content of their file into an array? Like this: array: [SomePath/test.php] = "All In this php file is being read by a new smart function!"; [SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";and so on, until no further files exists in that rootdir. All my attempts went totally crazy and none of them works... therefore i need to ask you for help. Do you have any ideas how to do this? If so, how can I be able to do it? Thanks in Advance, pros I am using WPSQT plugin in my blog site .I code some files in PHP also.how to add that files in plugin files.
I'm not sure how to put in a tab when editing php with php $fh = fopen(MYBB_ROOT.'/member.php', "r") or cperror("Could not open file!"); //OPEN FILE $data = fread($fh, filesize(MYBB_ROOT.'/member.php')) or cperror("Could not read file!"); //MAKE TEMPORARY STRING fclose($fh); //CLOSE FILE AGAIN $newdata = preg_replace('#'.preg_quote('eval("\$online_status = \"".$templates->get("member_profile_online")."\";"); if(is_super_admin($memprofile[\'uid\'])){ eval("\$online_status = \"".$templates->get("unknownlocation")."\";"); }').'#','\t\teval("\\\\$online_status = \"".$templates->get("member_profile_online")."\";");',$data); //REPLACE IN STRING $fw = fopen(MYBB_ROOT.'/member.php', "w") or cperror('Could not open file!'); //OPEN FILE AGAIN $fb = fwrite($fw, $newdata) or cperror('Could not write to file'); //WRITE STRING TO FILE fclose($fw); //CLOSE FILE AGAIN } I need to tab that line twice so it lines up in the file, i've tried putting \t in twice but that doesn't work and just gives this error Fatal error: Call to undefined function teval() in /Applications/XAMPP/xamppfiles/htdocs/member.php on line 1621 So, how to you put tabs in? Thanks Hi, I want to post a simple comments box at the bottom of one of my web pages that will send the data from 4 different inputs, named "email," "name," "comments," and "telephone," to my email. Can someone look at my php code and see what is wrong? The website code box works great if I enter in all the fields, however if the email box is not filled out and you click the submit button, it displays "Invalid email address enteredThank you for your message, we will be in touch shortly" How do I get rid of "Thank you for your message, we will be in touch shortly" Also, it sends the email even if the ['Name'] tag is not filled out, I not sure how to make it required. By the way, I'm new to php, so sorry if this is a little hard to understand. Link to website: http://www.raysmasonryconcrete.com/contact.html Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Send Data Form</title> </head> <body> <?php if(!$_POST) exit; $email = $_POST['Email']; $name = $_POST['Name']; $telephone = $_POST['Telephone']; $comments = $_POST['Comments']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('Name','Email','Telephone','Comments'); $required = array('Name','Email','Telephone','Comments'); $your_email = "*****"; $email_subject = "Message From the HDS Builders Website:"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'Name' && $key != 'Comments' && $key != 'Telephone') { if( empty($_POST[$value]) ) { echo 'Please go back and complete all fields, thank you.'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } } $headers = "From: $email\r\n"."Reply-To: $email\r\n".'X-Mailer: PHP/' . phpversion(); if(@mail($your_email, $email_subject, $email_content, $headers)) { echo 'Thank you for your message, we will be in touch shortly'; } else { echo 'ERROR!'; } ?> </body> </html> Hi I have a list created using php and mysql linked together. I have an edit and a delete button which edits and deletes data on the database. When I click edit it brings up current information and I can change it, which is fine. But I click to edit it in the database it changes all the records I have in the database!!! Instead of the specific record!!!! Could anybody please help!!!! Hello The code shown below creates a new endpoint to the "my-account" section on my wordpress website. basically it displays the products a user purchased from our site. I just want to EXCLUDE a certain product category to be shown in this endpoint ! i hope you can help me achieve this !
One more question for the day. I'm trying to figure out the best way to run about this. Right now I have it set up so that two or more content pages CAN NOT have the same name or shortname as it performs checks to verify that there aren't both on my add new and edit pages. Now problem here is that say I'm on the edit form and I'm editing a content page with its dropdowns and what not in the form. Now I'm thinking what would be the next course of option because what if I only want to change one dropdown but still keep the same name and shortname. When I submit it, its going to kickback my response that it can't be saved because there's already a page in there with that name and shortname even though I didn't change it. Any suggestions? Hey guys! I ran into another problem, i am looking to create a system so my users can go edit their accounts such as: Password, Age and Info and so on. but im am totally blank so i need some kind of tutorial to get started, or maybe help if anyone got time for that. Thanks Hi everyone I am using this code which is an example from a website Code: [Select] <?php $file_handle = fopen("myfile", "rb"); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('=', $line_of_text); print $parts[0] . $parts[1]. "<BR>"; } fclose($file_handle); ?> Which does what it is meant to, however what I am trying to do is put all the input into a form, so values can be changed. How do I separate each part? Eg the 1st line of the files reads isactive = true, how would I grab this so I can put it back to the file later as isactive = false? Not all the options are true/false, most are just strings or ints. Thanks I need to open a template file change a text var and then save the file as something new. How can I do this? Hey, Currently i have a chat room which calls my database quite frequently... so im thinking i can lower the heavy load from my server by taking it off MYSQL methods and using PHP read/write/delete methods of a text file. Now i have two issues with this... first one is: Code: [Select] <?php $myFile = "chatlist.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $Message.'<br/>'; fwrite($fh, $stringData); fclose($fh); ?> This writes the most recent line, how ever the next line that gets sent overwrites so theres only ever one line in the txt file =/ Secondly how on earth do you delete a specific line from the file efficiently ? Say for example a line which broke the rules some how like spam was posted etc. Hope you get shed light on this. Thanks Hello all, I am new to php coding and have a couple of problems with editing records in my database! I have two files below one test.php and edit.php. In the test.php the code outputs the records into a table. The problem is with the edit link as when it is selected I wish to be able to edit a record by a form, which is on edit.php. I am trying bring up the movie's information on the form to be edited. Currently on the form i get; Quote Movie: movie Gen Genre Year: year Any ideas how I can edit the record and then return to the test.php page? Code: [Select] test.php <html> <body style="background-color:#669999;"> <table width="490"border=0><tr> <td colspan="2" style="background-color:#FFA500;"> <div id="header" <h3 style="color:black">This is my first web-page! Below is a database of some of my favourite movies! </h3> </td> </tr> <?php //connecting to server $con = mysql_connect("localhost","root","NYOXAkly"); if (!$con) { die('could not connect: ' . mysql_error()); } //selecting movie database mysql_select_db("my_mov",$con); //Check if add button is active, start this if(isset($_REQUEST['add'])) { echo "<meta http-equiv=\"refresh\"content=\"0;URL=form.php\">"; } $result = mysql_query("SELECT * FROM Films ORDER BY filmID"); ?> <!-------------------------------creating table------------------------------------------------------------------------------------> <table width="490" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <form name="test1" method="post" action="test.php"> <table width="490" border="10" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"><tr> <td bgcolor="#FFFFFF"></td> <td align="center" colspan="6" bgcolor="#FFFFFF">Movie Database</td></tr> <td align="center" bgcolor="#FFFFFF">filmID</td> <td align="center" bgcolor="#FFFFFF">Movie</td> <td align="center" bgcolor="#FFFFFF">Genre</td> <td align="center" bgcolor="#FFFFFF">Year</td> <td align="center" bgcolor="#FFFFFF">Edit</td> <td align="center" bgcolor="#FFFFFF">Delete</td> </tr> <?php while($rows=mysql_fetch_array($result)) { ?> <tr> </td> <td bgcolor="#FFFFFF"><? echo $rows['filmID']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['movie']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['genre']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['year']; ?></td> <td bgcolor="#FFFFFF"> <a href="edit.php?filmID=<?php echo 'filmID';?>">Edit</a> <td bgcolor="#FFFFFF"> <a href="delete.php?filmID=<?php echo 'filmID';?>">Delete</a> </td> </tr> <?php } echo print_r(error_get_last()); mysql_close(); ?> <!--add button--> <tr> <td colspan="15" align="left" bgcolor="#FFFFFF"> <input name='add' type="submit" filmID="add" value="Add A New Record" action="form.php?"> </td> </tr> </table> </form> <br/> By C.M.D.W <br/> <?php echo date("Y/m/d") . "<br />"; ?> </body> </html> Code: [Select] edit.php <html> <body style="background-color:#669999;"> <!------------------Creates a form ----------------------> <br /> <form action="" method="post"> <fieldset> <legend>Enter your movies into database here!</legend> Movie: <input type ="text" name="movie" value="<?php echo 'movie';?>"> <br /> Gen <input type ="text" name="genre" value="<?php echo 'genre';?>"/> <br /> Year: <input type ="text" name="year" value="<?php echo 'year';?>"/> <br /> <input type="submit" name="name" value="Submit" /> </fieldset> </form> <?php //connecting to server $con = mysql_connect("localhost","root","NYOXAkly"); if (!$con) { die('could not connect: ' . mysql_error()); } //selecting movie database mysql_select_db("my_mov",$con); if (isset($_POST['submit'])) { // confirm that the 'id' value is a valid integer if (is_numeric($_POST['filmID'])) // get form data $filmID = $_POST['filmID']; $movie = mysql_real_escape_string(htmlspecialchars($_POST['movie'])); $genre = mysql_real_escape_string(htmlspecialchars($_POST['genre'])); $year = mysql_real_escape_string(htmlspecialchars($_POST['year'])); // check that fields are filled in if ($movie == '' || $genre == '' || $year == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; } else { // save the data to the database } mysql_query("UPDATE players SET movie='$movie', genre='$genre', year='$year' WHERE filmID='$filmID'") or die(mysql_error()); // once saved, redirect back to the view page header("Location: test.php"); } } if (isset($_GET['filmID']) && is_numeric($_GET['filmID']) && $_GET['filmID'] > 0) { // query db $id = $_GET['filmID']; $result = mysql_query("SELECT * FROM Films WHERE filmID=$FilmID") or die(mysql_error()); $row = mysql_fetch_array($result); // check that the 'id' matches up with a row in the databse if($row) { // get data from db $movie = $row['movie']; $genre = $row['genre']; $year = $row['year']; }} ?> <br/> <br/> <a href="test.php">Return To Home Page</a> <br/> <br/> By C.M.D.W <br/> <?php echo date("Y/m/d") . "<br />"; ?> </body> </html> Thanks Chris I have an email form that can have comma separated email addresses. I need to modify my code such that initially if the form does not contain any value, it should let me add email addresses to it. When I enter the web page next time it should display and let me edit the existing email addresses. Here is my code below. Right now it does not insert anything the first time. Code: [Select] <? error_reporting(E_ALL & ~E_NOTICE); $conn = mysql_connect('localhost','test','*****') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('test',$conn) or trigger_error("SQL", E_USER_ERROR); //$sql=mysql_query("SELECT * from new_database") or die(mysql_error()); $getemail=mysql_query("SELECT * from email") or die(mysql_error()); if(mysql_num_rows($getemail) > 0) { while($getemail_results=mysql_fetch_assoc($getemail)) { $getemailadd=$getemail_results['email']; } } else { $getemailadd=''; } if (!isset($_POST['submit'])) { ?> <b>ADDING A Email</b><br> <form action="<?php echo $PHP_SELF;?>" method="post"> Email:<br> <input type="text" size ="80" name="email" value="<?PHP if(isset($getemailadd)){ echo $getemailadd; } ?>" /><br> <input type="submit" name="submit" value="submit" /> </form> <? } else { // Get values from form $email=$_POST['email']; //$sql=mysql_query("INSERT into email(email)VALUES('$email')") or die (mysql_error()); $sql=mysql_query("UPDATE email SET email='$email'") or die (mysql_error()); header('Location: index.php'); } ?> Hey guys im fairly good with php dont do much struggling apart from now. I decided to make an app that helps the user install itself by checking certain files are writable if there is an installation directory etc etc. But i have come to the point where i want the user to change the username/passwords to access his/her database. i have them pre-defined like so: define('DB_USER','myUsername'); these are stored in includes/config.inc.php I know how to grab data from a user submitted form wither by post/get how would i go about changing these values depending on what the user inputs. So say i capture someones db username like so. $username = $_POST['db_username']; how would i change what ever is stored in the $username variable to replace whats in the define? Thanks guys hope this makes sense |