Re: My first question: PHP won't update MySQL

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: My first question: PHP won't update MySQL
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-7962@lists.php.net to get a copy of this message
Timothy: Your code uses the <?php echo"thisstuff" ?> out of place, try this and compare it to what you have: <?php if ($id) { echo "<b>Edit Story:</b><br><br>"; $sql = " SELECT * FROM story WHERE id='$id' "; result = mysql_query($sql); $myrow = mysql_fetch_array($result); $id = $myrow['id']; $title = $myrow['title']; $body = $myrow['body']; $myvar = "<input type=\"hidden\" name=\"id\" value=\"$id\">"; ?> <form method="post" action="name_of_current_script"> <?php echo"$myvar"; ?> </form> If you only have a single result for $id the above code will be fine. If you know there may be more than one then you'll have to tuse a loop: while($myrow = mysql_fetch_array($result)) { $myrow = mysql_fetch_array($result); $id = $myrow['id']; $title = $myrow['title']; $body = $myrow['body']; $myvar = $myvar . "<input type=\"hidden\" name=\"id\" value=\"$id\">"; } <?php echo"$myvar"; ?> HTH ;-) Russ #-------------------------------------------------------# "Believe nothing - consider everything" Russ Michell Anglia Polytechnic University Webteam http://gertrude.sipu.anglia.ac.uk/webteam r.j.michell@anglia.ac.uk +44 (0)1223 363271 ext 2331 www.theruss.com #-------------------------------------------------------#

« previous php.db (#7962) next »