PHP - Disable Article Editing If Somebody Is Already Editing It
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 Similar TutorialsHi, 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> 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 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? 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 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; 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 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 !
I need to open a template file change a text var and then save the file as something new. How can I do this? Hello 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. I've been working with PHP for only a few weeks now. I have learned a significant amount by creating a custom web app. I can usually figure things out by massive Googling and trial and error but this one has got me stumped. I have a form for this web app that I'd like to use as a configuration page. It houses all of the settings that the web app needs. On the backend, I'm housing all of this data in a XML file. So far, I've been able to parse the XML file to populate all of the appropriate fields in the HTML form. However, I'm having trouble taking the user's input and saving it back to the same XML. To do this, I have a processconfig.php page as the form's action. In this process.php page, I'm using the elements from the $_POST array to bring over all of the data in the form's fields. I want to take these $_POST array elements and insert them into the same XML that originally populated the form in the first place. With the code below I've been able to get the SimpleXML object to add data to the XML file but it is simply appended to the end with no formatting. As you can see, I've tried to name the form fields the same name as it's POST array element so that I can do the loop but it's not working. Is there an easier way to do this or is there another recommended way to retrieve and store configuration items for a web app? Here's my code: config.xml snippet Code: [Select] <Config> <General> <Logging> <Enabled>No</Enabled> </Logging> <QueryBuybackSites> <Enabled>Yes</Enabled> </QueryBuybackSites> <BuildFBA> <Enabled>No</Enabled> </BuildFBA> <BuildBB> <Enabled>No</Enabled> </BuildBB> <FBARankCutoff> <Value>1000000</Value> </FBARankCutoff> <Amazon0Offer> <DefaultPrice> <Value>47.77</Value> </DefaultPrice> <AutoKeep> <Enabled>Yes</Enabled> </AutoKeep> </Amazon0Offer> </General> </Config> configview.php snippet Code: [Select] <?php //Load all configuration data $configxml = simplexml_load_file('config.xml'); echo '<html> <head> <title>Easy Receive Configuration</title> </head> <body> <form action="processconfig.php" enctype="multipart/form-data" id="emf-form" method="post"> <table bgcolor="#FFFFFF" border="0" cellpadding="2" cellspacing="0" style="text-align: left;"> <tbody> <tr> <td colspan="2" style=""> <font color="#000000" face="Verdana" size="2"><b style="font-size: 20px;">Easy Receive Configuration Settings</b><br /> <label style="font-size: 15px;">This is where you can customize Easy Receive to your personal preferences</label></font> </td> </tr> <tr valign="top"> <td colspan="2" style=""> <hr /> <h3 id="element_0" name="element_0" style="font-size: 14px; padding: 10px 0pt 6px; margin: 14px 0pt; position: static;"> <span style="font-size: 24px;"><font color="#000000" face="Verdana">General Configuration Options</font></span></h3> </td> </tr> <tr valign="top"> <td align="" style=""> <p> <strong>Enable Logging</strong> <input name="General->Logging->Enabled" type="checkbox" ' . htmlify($configxml->General->Logging->Enabled) . ' /></p> </td> </tr> <tr valign="top"> <td align="" style=""> <p> <font color="#000000" face="Verdana" size="2"><strong>Build FBA shipment on the fly</strong> <input name="General->BuildFBA->Enabled" type="checkbox" ' . htmlify($configxml->General->BuildFBA->Enabled) . ' /></font></p> </td> </tr> </tbody> </table> </form></body> </html>'; function htmlify($input) { if ($input == "Yes") return "checked"; else return ""; } ?> processconfig.php snippet Code: [Select] <?php $xmlstring = file_get_contents('config.xml'); $configxml = new SimpleXMLElement($xmlstring); foreach ($_POST as $attrib=>$value){ $configxml->$attrib = $value; } $configxml->asXML('config.xml'); ?> i am currently creating a school portal. there is this page which enables user to create their own website for Computer Education lesson. Every user are able to upload their files and view but the problem is, i need a function for the user to be able to edit it in on the page itself. I have , for example Col 1 Col 2 Col 3 I need to edit each record individually how Can I set this up I am new to php and am learning bits so any help will be appreciated I want to make a file that I can edit from a form. I don't know what type of file I should use, and how I would edit that file. When someone goes to the file I don't want them to be able to see the contents (like a php file holding variables). I also don't want to use .htaccess for this. This file will have things in such as the database connection variables. When someone edits the form, and save it, it will edit the database connection variables to the proper values. Here is the file I have now: Code: [Select] <?php $settings = array(); $settings['db']['host'] = 'xxxx'; $settings['db']['username'] = 'xxxx'; $settings['db']['password'] = 'xxxx'; $settings['db']['database'] = 'xxxx'; ?> Here is an example input field: Code: [Select] <input type="text" name="host" value="<?php echo $settings['db']['host']; ?>" /> What would be the best way to 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 Hi. When i fill in my contact form, it shows a "Message sent successfully" message. Then nothing happens. I think there is something wrong with my hosting but the service provider just can't help with that.
How can i edit these codes to send a mail through smtp?
<?php
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 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 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'); } ?> |