Darim Design Posted April 2, 2008 Share Posted April 2, 2008 Hi, learning php for the first time and the tutorials went smoothly, but I've got a little problem.I'm making a sort of wiki where people can edit a text on one of my pages, just a simple pure text. I've managed to set up a database and a table for it, and sending data to the table and then showing it on a different page works. But what I want is to update the data already in the table and not add a new line of data like the php tutorial does. So how can I do that? (link to the right tutorial would be nice aswell)Also, I would like the text that presently is in the table to be in the box you write in your edit. Pretty much like a wiki. How can I do these two things?I've tried changing 'PUT INTO' to 'UPDATE INTO' but that didn't work :)Any help apreciated! Link to comment Share on other sites More sharing options...
justsomeguy Posted April 2, 2008 Share Posted April 2, 2008 http://www.google.com/search?client=opera&...-8&oe=utf-8 Link to comment Share on other sites More sharing options...
Darim Design Posted April 2, 2008 Author Share Posted April 2, 2008 http://www.google.com/search?client=opera&...-8&oe=utf-8Google is not always my friend, I've already tried him. Link to comment Share on other sites More sharing options...
kv79 Posted April 2, 2008 Share Posted April 2, 2008 I will try to help you but you will need to put your code here .I want to see what did you do until now . Link to comment Share on other sites More sharing options...
justsomeguy Posted April 2, 2008 Share Posted April 2, 2008 The first result from Google is the w3schools tutorial for update.Anyway, what about this:http://dev.mysql.com/doc/refman/5.0/en/update.html Link to comment Share on other sites More sharing options...
kv79 Posted April 2, 2008 Share Posted April 2, 2008 Yes it is true . I just typed in google update mysqlAnd you got all explain with powerful code examples , I just wonder what an easy knowledge for free .And it is very useful . Link to comment Share on other sites More sharing options...
Darim Design Posted April 2, 2008 Author Share Posted April 2, 2008 Yea I've read the w3 tutorial but it just edits it, I want others to be able to edit it. Instead of puting in info like the tutorial does I want it to update something that is already there.Thanks for the other link though, I'll give it a try Link to comment Share on other sites More sharing options...
justsomeguy Posted April 2, 2008 Share Posted April 2, 2008 You're talking about the tutorial for INSERT. There is also a tutorial for UPDATE.http://www.w3schools.com/sql/sql_update.asp Link to comment Share on other sites More sharing options...
Darim Design Posted April 3, 2008 Author Share Posted April 3, 2008 No I've read both insert and update. For the coding I have now it is the same as the tutorial except other names for databases and tables. From input to insert and then it saves in the table, and then it is displayed on another page. What I need is the input to overwrite data already in the table, rather than making a new post like a guest book. The update automatically updates the table, but I want others to be able to do that through the input. What I don't know is the right tags etc to do this. Link to comment Share on other sites More sharing options...
Synook Posted April 3, 2008 Share Posted April 3, 2008 UPDATE is correct. You can capture the form's input in the same way you do for INSERT. For the form, you would use the form tags, <form>, <input>, <textarea>.What code to dyou have currently? Link to comment Share on other sites More sharing options...
Darim Design Posted April 3, 2008 Author Share Posted April 3, 2008 <?php$con = mysql_connect("*******","******","******");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("hyboria", $con);$sql="INSERT INTO vanaheim (Name, Info)VALUES('$_POST[name]','$_POST[info]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con)?> Link to comment Share on other sites More sharing options...
kv79 Posted April 3, 2008 Share Posted April 3, 2008 If you want that other put a message in you database then you should have a public database (for guests ). Of course you need only to construct the design of your guest book .You could use a <form> for updating the database .Hope this can help you , and if do not understand , please let me know . Link to comment Share on other sites More sharing options...
Darim Design Posted April 3, 2008 Author Share Posted April 3, 2008 The database is already public. If you want you can check it out at Input, Insert and Display. Link to comment Share on other sites More sharing options...
kv79 Posted April 3, 2008 Share Posted April 3, 2008 nice Link to comment Share on other sites More sharing options...
Darim Design Posted April 3, 2008 Author Share Posted April 3, 2008 Yea but I don't want it like that. When you submit something I want it to overwrite the things already there, like if you were editing a post. Link to comment Share on other sites More sharing options...
kv79 Posted April 3, 2008 Share Posted April 3, 2008 So you will need to include display file with you submit ,If you do not understand , please let me know, but first i want to see you code until now . Link to comment Share on other sites More sharing options...
Darim Design Posted April 3, 2008 Author Share Posted April 3, 2008 No I don't get it But here's the code..Input: <form action="insert.php" method="post">Name: <input type="text" name="name" />Info: <input type="text" name="info" /><input type="submit" /></form> Insert: <?php$con = mysql_connect("****","****","****");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("hyboria", $con);$sql="INSERT INTO vanaheim (Name, Info)VALUES('$_POST[name]','$_POST[info]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con)?> Display: <?php$con = mysql_connect("****","****","****");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("hyboria", $con);$result = mysql_query("SELECT * FROM vanaheim");echo "<table border='1'><tr><th>Name</th><th>Info</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td>" . $row['Info'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);?> Link to comment Share on other sites More sharing options...
kv79 Posted April 3, 2008 Share Posted April 3, 2008 Insert.php <?php$con = mysql_connect("****","****","****");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("hyboria", $con);$sql="INSERT INTO vanaheim (Name, Info)VALUES('$_POST[name]','$_POST[info]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";include('Display.php'); //I hope that Display.php is in root directory mysql_close($con)?><html><body><form action="insert.php" method="post">Name: <input type="text" name="name" />Info: <input type="text" name="info" /><input type="submit" /></form></body></html> I hope this can help you . Link to comment Share on other sites More sharing options...
Darim Design Posted April 3, 2008 Author Share Posted April 3, 2008 Error: mysql_close(): 1 is not a valid MySQL-Link resource in /home/darimq-design/web/hyboria.darimq-design.com/test/insert.php on line 27And now you can post using the display page, but it still doesn't erase the other posts. Link to comment Share on other sites More sharing options...
kv79 Posted April 3, 2008 Share Posted April 3, 2008 To erase other posts or edit it , like w3school did it you will need to learn more .divs and css are standard , you will need design for your guest book .OR try asking some more experienced programmer . Link to comment Share on other sites More sharing options...
Darim Design Posted April 3, 2008 Author Share Posted April 3, 2008 No no no, it's not a guest book! It's supposed to be a wiki, a really simple one. There is only going to be one piece of info that others can edit. I don't want to use wikimedia and such because it's too big and pointless with all the pictures and buttons etc. I thought I made that clear enough but ohh well Link to comment Share on other sites More sharing options...
justsomeguy Posted April 3, 2008 Share Posted April 3, 2008 When you submit something I want it to overwrite the things already there, like if you were editing a post.What are you trying to edit? If someone types in the same value for "name" then you want to update the record in the database with that name?UPDATE table SET info=$info WHERE name=$nameThat's the specific statement to update, if that's what you want to do. But before you do that you would need to use a SELECT statement to check if a record exists at all with that name, if so then do an update and if not then do an insert. You'll also want to use more fields in your database, you'll at least want an autonumber ID and maybe some other stuff. Wikipedia also keeps track of what changes were made, you might want to do something like that also. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.