php - If content exists in database, provide form to update it - else provide form to add new row -


it's going wrong. need output form onto website 1 of 2 things:

  1. if user has content in database, provide form posts self update existing content.

  2. if user not have content in database, provide form let user add information database.

the forms should submit keep coding tidy. i'm getting right mess. i'll show have far, i'm getting in muddle.

//look in db see if content exists, if set variable     $result = mysql_query(             "select * tbl_profiles              user_id = $who         ");      while($row = mysql_fetch_array($result))          {              $profiletext = $row['text'];              }  // check if user has content in db          $result = mysql_query(         "select * tbl_profiles user_id='$who'");      if(mysql_fetch_array($result) !== false){         echo          '<form action="../edit/indexupdate.php" method="post" name="edit">                 comments:<br />                 <textarea name="updatedtext" id="comments">' .                 $profiletext .'                 </textarea><br />                 <input type="submit" value="submit" />             </form>'         ;}     else{         $profiletext = $row['text'];         echo          "<form action='../edit/index.php' method='post' name='add'>                 comments:<br />                 <textarea name='comments' id='comments'>" .                 $profiletext                  ."</textarea><br />                 <input type='submit' value='submit' />             </form>"         ;}?> 

you've pretty got functionality there, needs tidying up.

try this:

<?php //look in db see if content exists, if set variable $profiletext=""; if($result = mysql_query("select * tbl_profiles user_id = $who")) {     while($row = mysql_fetch_array($result))         {          $profiletext .= $row['text'];          }     ?>     <form action="../edit/indexupdate.php" method="post" name="edit">             comments:<br />             <textarea name="updatedtext" id="comments">             <?php echo $profiletext; ?>             </textarea><br />             <input type="submit" value="submit" />     </form>     <?php } else {     ?>      <form action='../edit/index.php' method='post' name='add'>             comments:<br />             <textarea name='comments' id='comments'>             <?php echo $profiletext; ?>              </textarea><br />             <input type='submit' value='submit' />      </form> <?php     } ?> 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -