Forums

Give help. Get help.

  • # February 19, 2014 at 9:38 pm

    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:

    <?php
    
    //create a database connection
    mysql_connect("localhost","root","root") or die("Error:".mysqlerror());
    //select database
    mysql_select_db("chordcharts");
    
    //create the query
    $result = mysql_query("select * from tunes");
    
    //return the array and loop through each row
    while ($row = mysql_fetch_array($result))
    {
    ?>
    
    <div>&nbsp;&nbsp;&nbsp;<a href=""><?php echo $row['title'];?></a></div>
    
    </ul>
    <?php 
    } 
    ?>
    

    Here’s the code for the list page:

    <?
    $objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
    $objDB = mysql_select_db("chordcharts");
    $strSQL = "SELECT * FROM tunes";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    ?>
    <table width="600" border="1">
      <tr>
        <th width="91"> <div align="center">ID </div></th>
        <th width="91"> <div align="center">Title </div></th>
        <th width="98"> <div align="center">Chords </div></th>
        <th width="198"> <div align="center">Lyrics </div></th>
        <th width="30"> <div align="center">Edit </div></th>
      </tr>
    <?
    while($objResult = mysql_fetch_array($objQuery))
    {
    ?>
      <tr>
        <td><div align="center"><?=$objResult["id"];?></div></td>
        <td><?=$objResult["title"];?></td>
        <td><?=$objResult["chords"];?></td>
        <td><?=$objResult["lyrics"];?></td>
        <td align="center"><a href="light.php?id=<?=$objResult["title"];?>">Edit</a></td>
      </tr>
    <?
    }
    ?>
    </table>
    <?
    mysql_close($objConnect);
    ?>
    

    Thanks for any help and advice.

    # February 20, 2014 at 1:41 pm

    +1 @shaneisme

    You can take a look at the way I used PDO in this Gist https://gist.github.com/alenabdula/9083666 and extract the parts you’re interested.

    Hope that helps

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag