Birdmansplace Posted December 27, 2009 Share Posted December 27, 2009 I have been searching for hours over the last day or 2 for find let alone understand how i would write code for calling the last data entered to mysql and then submiting the changed data. I already have code for entering it and code to read it to display from html/php. How would i go about doing that? I know basic php, not so much mysql atm so, with that said much help would be needed. this is part of the code that i have php connecting to mysql to read and then display the contents. include("dbinfo.php"); mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM schedule ORDER BY date DESC"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); So lost....... Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 27, 2009 Author Share Posted December 27, 2009 i guess i could say that i would like code that 1st. calls what to display followed but submit again but over writes the data. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 27, 2009 Author Share Posted December 27, 2009 is there a way using the above code sence its calling for the newest entry by date to delete it? thinking thats going to be by best route atm. Quote Link to comment Share on other sites More sharing options...
optikalefx Posted December 27, 2009 Share Posted December 27, 2009 do you want lastInsertID? <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('mydb'); mysql_query("INSERT INTO mytable (product) values ('kossu')"); printf("Last inserted record has id %d\n", mysql_insert_id()); ?> or if you need it more advanced, check out mysql triggers here is a video i made Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 27, 2009 Author Share Posted December 27, 2009 my form has 153 enterys. Once the submit button has been clicked it saves to mysql. What i am trying to figure out is the best way to edit after submit. Basicly from the "view" page is to be able to change 1 to 153 enterys then submit again but over write what has been saved with out creating a new entry. the only idea i can come up with is manualy changing enterys in phpmyadmin or mate "view" and "form" page together. meaning "view" page calls the info from sql and displays it then while on that page also have "form" code in it so you can submit the changes. Doing it that way to me would create another entery and still would have to go into phpmyadmin and delete the other. What i am making is an online schedule for work and would hate to delete the hole thing if the user while entering made a mistake. I already have delete set up to wipe out the whole table but the manager would like to keep a record for so long to look back on. I just looking for something to edit one entry. Quote Link to comment Share on other sites More sharing options...
optikalefx Posted December 27, 2009 Share Posted December 27, 2009 Sounds like SQL REPLACE statement. It will insert an entry or update the existing in a mysql db. You can also use UPDATE if you want to make a separate SQL call. 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.