Jump to content

More form problems..help


Immortal55

Recommended Posts

When A user clicks on an edit link for a certain story in profile.php, it takes them to writingforms.php. When writing forms is loaded I want it to load in the info from the DB into the text fields and you can edit it that way. The fields are not loading the info into them how come?

profile.php code snippet:
[code]
<? //journal call
    $db = mysql_select_db('studiocommunity', $conn)
                or die("Unable to access user information in database, try again later.");
    $sql = mysql_query('select * from user_writings where user = "' . $_REQUEST['user'] . '"order by id desc') or die(mysql_error());
    
    while($row = mysql_fetch_assoc($sql)) {
    stripslashes(extract($row));
    echo "<a href='writings.php?id=$id'>" . $title . " - " . date("F d, Y", $date) . "</a> ";
    if($HTTP_SESSION_VARS['valid_user'] == $_REQUEST['user'])
    {    echo " - [<a href='writingforms.php'>edit</a>] [delete]<br>";
    }
    }
?>
[/code]

and writingforms.php
[code]
<?
    session_start();
    
    include ('dbconnect.php');
  
function get_writing_record($id)
{
  $conn = db_connect();
  $db = mysql_select_db('studiocommunity', $conn)
                or die("Unable to access user information in database, try again later.");
  $sql = "select * from user_writings where id = '" . $_REQUEST['id'] . "'";
  $result = mysql_query($sql, $conn);
  return(mysql_fetch_array($result));
}

    
    if (isset($HTTP_GET_VARS['id']))
        $w = get_writing_record($HTTP_GET_VARS['id']);
        
?>

    <center>
    <form action="writingsubmit.php" method="post">
    <input type="hidden" name="writing" value="<? print $HTTP_GET_VARS['id']; ?>">
    <table>
    <tr><td align="center">Title</td></tr>
    <tr><td><input size="40" name="title" value="<? print $w['title']; ?>"></td></tr>
    <tr><td align="center">Writing Text - Can contain HTML text</td></tr>
    <tr><td><textarea cols="40" rows="7" name="writing_text" wrap="virtual">
            <? print $w['writing']; ?>
            </textarea></td></tr>
    <tr><td align="center"><input type="submit" value="Submit"></td></tr>
    </table>
    </form>
    </center>
[/code]


I cannot figure out what is wrong, help please.
Link to comment
Share on other sites

1.) After you do your initial SQL query and INSIDE the While loop do: var_dump($row); This will show you everything (if anything at all) that is being returned from your query. If you get nothing or NULL then your query is bombing or trying to SELECT rows that aren't there - in otherwords comb through your query syntax and make sure it is right. I noticed your WHERE filter is comming from $_REQUEST. Make sure that $_REQUEST is being populated like you think it is.

2.) Once you have established that your query is returning proper and/or expected results - then it's simply a matter of setting your <INPUT>'s value to the appropriate element in the $row array.

EX: echo "<input type=\"text\" name=\"my field\" id=\"my field\" value=\"$_row[my_element]\">";

Also, mind your quote delimination if your echo'ing HTML via PHP

I noticed that your populating the HTML value's with a $w array. According to your code/forum post, if I were trying to populate the HTML value's with the database results, I would use the $row array.
Link to comment
Share on other sites

I realized that I was not populating my $_REQUEST like I thought I was. The link to the edit was just writingforms.php, not writingforms.php?id=. I think that was my problem, although I cannot try it right now. Would you reccoment I get rid of the $w array and just use the $row function?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.