scottjcampbell Posted June 13, 2008 Share Posted June 13, 2008 Hi, i have been having this problem for some time now. i think i am being stupid by not knowing but... How do i edit a config file which looks something like this: $title=TITLE!!!; $page=PAGE!!! How do i make a page with text boxes which edit each element seperately? This config file would be placed in a directory called config. THANKS, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 What? Please elaborate. Incoherent questions receive incoherent answers. Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 14, 2008 Author Share Posted June 14, 2008 Sorry if i didnt make myself clear. What i want to do is have a php page which will open a file, lets say called "config.php" and allow me as the administrator to edit the values of this "config" file through various web forms like text boxes. The values would be like: $title = "Welcome to my site"; then on a page i would write something like: <? echo $title; ?> Sorry if this is still unclear but, i want to be able to open a php page and through a text box, edit the value of the $title string. is this possible? Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 15, 2008 Share Posted June 15, 2008 A few ways - through fwrite of a .txt file, or just use a database - its much simpler. Store the $title string as a field somewhere. Quote Link to comment Share on other sites More sharing options...
tapos Posted June 15, 2008 Share Posted June 15, 2008 yes, save the variable names and the values in the database, this will make simple what u want to to. Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 15, 2008 Author Share Posted June 15, 2008 Hi, thanks for the reply. Is it possible for you to post an example of a script which would read and write to my database? Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 15, 2008 Share Posted June 15, 2008 http://www.tizag.com/mysqlTutorial/mysqlquery.php Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 15, 2008 Author Share Posted June 15, 2008 Thanks for that, after a first read of the website, it looks like this is exactly what i want. Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 22, 2008 Author Share Posted June 22, 2008 Hi, i have now sorted out my website to read data from my database which uses phpmyadmin. I was wondering if there was a way to use a website form/text box to edit this database. For example: I have included the following text into my homepage Welcome to my Website I would like to be able to open a page and be able to, via a text box, edit this Welcome to my Website Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 22, 2008 Share Posted June 22, 2008 There is. I remember the first time trying to do this. So think about it. You want a textbox. Well use the html element <textbox> It has the "value" argument (or the equivalent thereof, it goes in between the tags) So what you want to do, is have a form, with an sql lookup, and one variable defined that stores the lookup result of your query, and turn that into the text stored in a field somewhere with "Welcome to my site" or whatever. So have <textbox><?=$message?></textbox> with all the form stuff, and then in your part of the page that handles the POST info, use an UPDATE to update the field value to the variable stored in the POST. If what you read you don't understand, don't worry. Just have a think about it, come up with some code, and we'll help you Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 22, 2008 Author Share Posted June 22, 2008 Hi, i understand how to insert the text from the sql table into the textbox, i am assuming i would just use an echo like i have on my homepage into the value field of the textbox. I still dont understand how i would make this update my sql tables? Could you post an example? Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 22, 2008 Share Posted June 22, 2008 Yes, just echo....never mind. Lets start again. Okay, I assume you understand HTML, if not google "html textbox". Learn to walk before you can run. Secondly, where you would have default text, echo your text. then upon submitting, update your table. I told you, you post me some code, and ill help you out. If you are REALLY stuck, say so, and then I will help you with my own code. But the whole point of these forums is to help people with their phproblems, let them understand their mistakes so they don't make them again. If I just post you code, you won't understand it, and you won't have gained anything. So, why don't you try come up with something first, If you are really well and truly stuck, then Ill post my own code. Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 23, 2008 Author Share Posted June 23, 2008 Hi, i have been trying this for a while now, i have googled alot aswell i still cant find anything that will do this. I have experimented with some codes and edited them, but none of them do anything. Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 23, 2008 Share Posted June 23, 2008 Okay, lets start then. First of all, you need your database connect stuff, and a table, with a row, and a column. Good. I assume you have the above. If not, check out the Tizag MySQL tutorial and set that up. You shouldn't need any help there. You only need one row technically, but we may as well have two in case you have other messages. In phpMYAdmin Either do this manually, or for speed, just use this as a query, by clicking "SQL" in the top menu bar, and copy and pasting this, while inside your desired databse. CREATE TABLE `messages` ( `message_id` INT NOT NULL AUTO_INCREMENT , `message` TEXT NOT NULL , PRIMARY KEY ( `message_id` ) ) Once you have done that, a table should appear. Good. Now inside SQL once again (or do it manually if you wish), insert your row, containing your message. INSERT INTO `messages` ( `message_id` , `message` ) VALUES ( NULL , 'Welcome to my homepage!' ); It should appear. Fantastic. Now we are ready for the php bit. You can either use this (have it in your .htaccess admin area. If you don't have an admin area, make one >_>) or you use the code given to adapt to your needs. <?php // Make your MySQL Connection mysql_connect("localhost", "username", "password") or die(mysql_error()); // Put your info in here, or use an include file if you have one mysql_select_db("mydatabase") or die(mysql_error()); // Now we see if the message has been updated or not from the page to follow, and do so if it has // Has jeff been set? if (isset($_POST['jeff'])){ // Yup... // Give the updated message to the variable "jeff" $jeff = $_POST['jeff']; // Update mah message mysql_query("UPDATE messages SET message='$jeff' WHERE message_id='1'"); } // Now we create your lookup info, to get the message to do stuff with $sql = mysql_query("SELECT * FROM messages WHERE message_id='1'") or die(mysql_error()); // The above is saying, pull the info from the table messages, where the data in the first column equals one. // There is only one record that meets that criteria, so it will have our message somewhere. // This filters the results into an array so we can use it $row = mysql_fetch_array($sql); // Creates a string containing our message to output $message = $row['message']; // Now we have some html stuff ?> <title>Message Updater</title> <body bgcolor="pink"> <h1>My awesome message updater page thingy</h1><br><br> <form action="" method="POST"> <textarea cols="125" rows="40" name="jeff"><?=$message?></textarea> <br> <input type="submit" value="Submit!"> </form> </body> Note: the <?=$message?> SHOULD work, you should have quick tags enabled, but if it doesn't just switch it to a normal echo. Well that should work. Where you want to output your message, use a lookup, and echo it. You can work out how to do that from the code given. I hope you understand this, as It should help you. If you want to view a working version of this, you can see it at http://awesomealpha.com/test5.php I literally made it as I was making this post. Enjoy - Mark Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 23, 2008 Share Posted June 23, 2008 Your welcome. Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 23, 2008 Author Share Posted June 23, 2008 Thanks for the help. I have had a play around with the example you added and it is exactly what i wanted to do. I looked at the scripts you uploaded, which work, and un surprisingly they look nothing like mine and the functions are completely different. Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 24, 2008 Author Share Posted June 24, 2008 Hi, thanks for all of the help, by the way, i just wanted to say, i am not just leaving it to the forums to make my entire website for me, i really only post when i really struggle with someting. I have been attempting this for some time. The script on the previous page of this topic works perfect (providing you only want to edit one thing.) There are two things i am confused about; 1) Is it possible to insert multiple fileds from one table into the page, e.g: The structure has 4 fileds: ID, NAME, HREF and ICON The Actual Database has the following inside it, (this is one row), home, Home, home.php, icon.ico. There are more but i dont think it would be worth uploading them... When i click submit, it only changed the Home option, and if i dont do anything to the Home, it simply clears the field making it blank. 2) Is it possible to use a variable when selecting the table, i have managed to do it for the Column/Row (Sorry, Can't Remember which way) The code i have used is: ..$edit = $_GET['edit']; $table = $_GET['table'];.. and later on in the page: mysql_query("UPDATE $table SET $edit='$value'"); I dont think this code is bad, later on it says: $sql = mysql_query("SELECT * FROM $table") or die(mysql_error()); This is where my problem is, i have found this is the problem because i changed the $table to welcome_msg as this is the table i want to edit. Sorry if this is really long and confusing, but i am really struggling with this and i would bevery grateful for any help with either of the problems i have. Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 24, 2008 Share Posted June 24, 2008 First, the script I made you will work for a lot of messages (if you read my comment). It is a database, and supports many rows, as databases tend to do so. All it needs is drop down list or something, and a variable for the id based on that. When i click submit, it only changed the Home option, and if i dont do anything to the Home, it simply clears the field making it blank. - what ???. I don't understand any of your first point. What home option where? Display what where? Is this some thrid party script your are referring to? Please explain a little clearer. Your second point, what exactly is the problem? What should it be doing, and what is doing? Paste your whole code, and google it first. Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 24, 2008 Author Share Posted June 24, 2008 Sorry, i am really bad for explaining things. For the first code, i have multiple rows in one table, and home just happens to be inside one of them. (sorry, i really dont know how to explain). Here's a screenshot of my tables: (Will be removed after topic solved) Here is where i output this table by the way: I wanted to make a page where you can edit each element (Name, HREF, Icon, Target) for all of them. When i did this, it only updated one of the filelds after pressing submit, the field was home, the first one show. For my second problem, here is the whole script: <?php include($_SERVER['DOCUMENT_ROOT'].'/include/session.php'); include($_SERVER['DOCUMENT_ROOT'].'/include/ip.php'); $edit = $_GET['edit']; $table = $_GET['table']; if (isset($_POST['value'])){ $value = $_POST['value']; mysql_query("UPDATE $table SET $edit='$value'"); } $sql = mysql_query("SELECT * FROM $table") or die(mysql_error()); $row = mysql_fetch_array($sql); $message = $row['$edit']; ?> <form action="" method="POST"> <textarea cols="50" rows="5" name="value"><? echo $row[$edit]; ?></textarea> <br> <input type="submit" value="Submit!"> </form> but i am getting an error on the line which says: $sql = mysql_query("SELECT * FROM $table") or die(mysql_error()); If that makes any sense, Thanks, SCOTT CAMPBELL Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 24, 2008 Share Posted June 24, 2008 First of all, post the bloody error. Is this your script or is it third party? - Please answer. post all your script (for the first problem), else I cant help you. Also, what is in your address bar when you try to do edit your stuff? (excluding the domain if you wish, just the bit after the .com or whatever) Click what where? Please, explain everything, post all your code. Let me see what you see. The errors. Im not physcic, and I cant spoon-feed you. Quote Link to comment Share on other sites More sharing options...
scottjcampbell Posted June 24, 2008 Author Share Posted June 24, 2008 Sorry,i really am not good at explaining... Problem 1: This is the script you posted yesterday Full code: <?php mysql_connect("localhost", "hidden", "hidden") or die(mysql_error()); // Put your info in here, or use an include file if you have one mysql_select_db("login") or die(mysql_error()); if (isset($_POST['value'])){ $value = $_POST['value']; mysql_query("UPDATE navigation SET Name='$value' WHERE ID='home'"); } $sql = mysql_query("SELECT * FROM navigation WHERE ID='home'") or die(mysql_error()); $row = mysql_fetch_array($sql); $message = $row['Name']; ?> <form action="" method="POST"> <input name="value" value="<?=$message?>"></input> <input type="submit" value="Submit!"> </form> <? if (isset($_POST['value'])){ $value = $_POST['value']; mysql_query("UPDATE navigation SET Name='$value' WHERE ID='games'"); } $sql = mysql_query("SELECT * FROM navigation WHERE ID='games'") or die(mysql_error()); $row = mysql_fetch_array($sql); $message = $row['Name']; ?> <form action="" method="POST"> <input name="value" value="<?=$message?>"></input> <input type="submit" value="Submit!"> </form> And when you click the top submit button, it makes the value of the top box the value of the bottom and vicer versa. And for the second problem, my address bar would go like "page.php?edit=welcome_message&table=messages" but i get the error: Error follows: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 24, 2008 Share Posted June 24, 2008 Your mysql error, is pretty generic - google the answer. We have a pretty strong view about mysql errors - there is nothing special about them. Google the error, and youl find the answer. Just read your code. Secondly, with regards to your modified, code, you have named both input boxes "value" thus changing one changes them both. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.