Jump to content


Photo

More form problems..help


  • Please log in to reply
3 replies to this topic

#1 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 22 March 2006 - 03:22 AM

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:
<? //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>";
    }
    }
?> 

and writingforms.php
<?
    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>


I cannot figure out what is wrong, help please.

#2 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 22 March 2006 - 03:34 AM

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.
Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#3 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 23 March 2006 - 12:52 AM

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?

#4 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 23 March 2006 - 02:54 PM

Hmmm, alright, Yeah my idea did not work....Can anyone look over my scripts again and see if they cant find out what is wrong?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users