display problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

display problem

Post by Think Pink »

hello.I have a question.
I have something like this :

Code: Select all

<?php
<table>
<tr>
<td>
<form name="test" action="<? $PHP_SELF; ?>" method="post">
test1<br>
<input type="text" name="test1"><br>
test2<br>
<input type="text" name="test2"><br>

<input type="submit" name="add">
</form>
</td>
</tr>

<tr>
 <td>
  <?php
   bla bla bla
    
    if(isset($_POST['add']))	{
     $sql = "select.....
     ...
         if (mysql_num_rows($result) != 0) {
            print "This allready exists";
            exit;
         }
         $sql = "INSERT ...
         .....
            print "Added succesfully";
            exit;
   }
  ?>
 </td>
</tr>

<tr>
 <td>Some thext very important </td>
</tr>
</table>
?>
after the form is submitted the page reloads and it tels me if the input is allready in the $db or not. If it is, or not the execution stops and the problem is that the text that is after the script it doesn't appear anymore. The script has to be in that position because the message it prints out belongs to some fields I have there.

Question :
How can I make that the info the script prints out appear in the position I want, and in the same time the info after the script appear where I want it on the page (after the info the script prints)?

This is how I want it to be
Short version


input 1
input 2
submit button
message script prints out
information after the script. a picture or whatever
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Re: display problem

Post by Buddha443556 »

Do the processing first.

Code: Select all

<?php
   bla bla bla
  
$message = "";  
    if(isset($_POST['add']))	{
     $sql = "select.....
     ...
         if (mysql_num_rows($result) != 0) {
            $message = "This allready exists";
         }
         $sql = "INSERT ...
         .....
            $message = "Added succesfully";
   }
  ?>

<table>
<tr>
<td>
<form name="test" action="<? $PHP_SELF; ?>" method="post">
test1<br>
<input type="text" name="test1"><br>
test2<br>
<input type="text" name="test2"><br>

<input type="submit" name="add">
</form>
</td>
</tr>

<tr>
 <td>

  <?php echo $message; ?>

 </td>
</tr>

<tr>
 <td>Some thext very important </td>
</tr>
</table>
?>
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Post by Think Pink »

thx, is working, but now it inserts the data in the db even if the data is allready entered.

but I inserted an "else" and works great.
Post Reply