I’m working on a project that has a form page, a list page, and a print page. I’m having trouble passing data between them. The form page inserts a record into mySQL, and adds the record title to the left side of the page. I don’t know how to use the title as a link to display the record in the form. The list page displays the records, with an edit link after each record. I can’t seem to get data to populate the form when the edit link is selected. I have code for updating and deleting a record, but I need to get the record back into the form to do that. It should be obvious that I am new at this, but I’m learning.
Here’s the code on the form page for listing the titles:
//create a database connection
mysql_connect("localhost","root","root") or die("Error:".mysqlerror());
//create the query
$result = mysql_query("select * from tunes");
//return the array and loop through each row
while ($row = mysql_fetch_array($result))
<div> <a href=""><?php echo $row['title'];?></a></div>
This reply has been reported for inappropriate content.
OK – Johnny 5 need more input:
1st – if you have a record in SQL, there’s no need to pass it from one page to another really. You can just look up the data when you need it and display it.
2nd – could you narrow down precisely what the issue is? If you give me a narrow view of where the problem is, I’ll be happy to help.
Typically speaking, when you SELECT data, you’ll get it back as an associative array (if you declare it at the time, or you set the defaults to do so). So you’ll want to do some reading up on foreach loops and how to master that. That might be all you need to populate the form.
DRY – don’t repeat yourself. Working with server-side code, you definitely have no excuses for not using include, require, et al. Once you get the basics down of using simple includes to store functions like database lookups, you can start looking into object oriented PHP which has gotten so much better over the last few releases. Decent overview: http://www.killerphp.com/tutorials/object-oriented-php/