Jump to content

[SOLVED] posting from the form problem ! ???


nita

Recommended Posts

Hi,

i have a problem with the posting from the form.

I have recommendation form with captcha, wich i think there is no problem with. Once i press submit, php take action in another if else condition with out passing variable, i quite can figure it out why is like this. Take a look the code, please ....

 

if(isset($_GET['cat'])) // when looking at selected category
{
}   //problematic submit goes here ...
else if(isset($_POST['submit'])||isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed
{
}
else  //when looking at the root of the aplication
{
   $myemail = "[email protected]";
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $messagehtml = str_replace("\r", '<br/>', $message);
    $thanks = "
    <p align='left' class='info2'><span class='info2'>
    Thank you !. Your recomendation has sucessfuly been sent!<br>
    <br></span></p>";
        
$subject = "New Movie Recomendation from $Name";
$messagetoemail = "New movie recomendation.
Name: $name
E-mail: $email
Recomendation: $messagehtml
";

if($_POST['submitform'])   // problematic submit expected to start here....
{
    $yourcode=$_POST['yourcode'];
   $thevalue1=$_POST['thevalue'];
   if($yourcode=$thevalue1)
   {

mail($myemail,$subject,$messagetoemail,$name);

mysql_query ("INSERT INTO moviesreco (id, name, email, message) 
              VALUES ('', '$name', '$email', '$messagehtml')");

echo "$thanks";
   }
   else
   {
      echo "You verification code is not right. Please go back and try again.";
   }
}
else
{
//this is recomandation form
echo "
<table width='100%'  border='0' cellspacing='0' cellpadding='10'>
  <tr>
    <td>

<form action='$PHP_SELF' method='post'>
  <table width='444' align='left' class='info4'>
    <tr>
      <td valign='top' align='right'><b>Name:</b></td>
      <td valign='top'>
        <input name='name' size='30'>
      </td>
    </tr>
    <tr>
      <td valign='top' align='right'><b>E-mail:</b></td>
      <td valign='top'>
        <input name='email' size='30'>
      </td>
    </tr>
    <tr>
      <td valign='top' align='right'><b>Recomendation:</b></td>
      <td valign='top'>
        <textarea name='message' rows='10' cols='30'></textarea>
      </td>
    </tr>
    <tr>
<td>";
$im = ImageCreate(60, 20);  //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
$md5 = md5(microtime() * mktime()); 
$string = substr($md5,0,5);
$verification = $string;
$thevalue= $string;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 10, 3, $verification, $white);
Imagejpeg($im, "inc/verify.jpeg");
ImageDestroy($im);
echo "
<img src='inc/verify.jpeg' border='0'>
<input type='hidden' value='$thevalue' name='thevalue'>
</td>
    <td>
    <input type='text' name='yourcode' size='5' maxlength='5'>
    </td>
    </tr>
    <td valign='top' align='right'></td>
      <td valign='top' align='left'>
        <input class='button1' type='submit' value='Send' name='submitform'>
        <input class='button1' type='reset' value='Reset' name='reset'>
      </td>
    </tr>
  </table>
</form>
</td>
  </tr>
</table><br>";
}

// some more code 


 

I need some help on this one, please !!!

 

thank you in advance.

 

Nita

Link to comment
https://forums.phpfreaks.com/topic/56437-solved-posting-from-the-form-problem/
Share on other sites

i fixed the code i bit but sill no results

 

new code..

 


if(isset($_GET['cat'])) // when looking at selected category
{
}   //problematic submit goes here ...
else if(isset($_POST['submit'])||isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed
{
}
else  //when looking at the root of the aplication
{

// some code

if($_POST['submitform'])   // problematic submit expected to start here....
{
    $yourcode=$_POST['yourcode'];
   $thevalue1=$_POST['thevalue'];
   if($yourcode=$thevalue1)
   {

mail($myemail,$subject,$messagetoemail,$name);

mysql_query ("INSERT INTO moviesreco (id, name, email, message) 
              VALUES ('', '$name', '$email', '$messagehtml')");

echo "$thanks";
   }
   else
   {
      echo "You verification code is not right. Please go back and try again.";
   }
}
else
{
//this is recomandation form
echo "
<form action='$PHP_SELF' method='post'>
        <input name='name' size='30'>
         <input name='email' size='30'>
       <textarea name='message' rows='10' cols='30'></textarea>
";
$im = ImageCreate(60, 20);  //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
$md5 = md5(microtime() * mktime()); 
$string = substr($md5,0,5);
$verification = $string;
$thevalue= $string;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 10, 3, $verification, $white);
Imagejpeg($im, "inc/verify.jpeg");
ImageDestroy($im);

echo "
<img src='inc/verify.jpeg' border='0'>
<input type='hidden' value='$thevalue' name='thevalue'>
    <input type='text' name='yourcode' size='5' maxlength='5'>
      <input class='button1' type='submit' value='Send' name='submitform'>
        <input class='button1' type='reset' value='Reset' name='reset'>
     </form>
";
}

// some more code 

}

i spotted a bug but doesn't bring any difference to action taken by php after submiting form ....

php is taking action as if i will use search form,

 

bug

if($yourcode==$thevalue1) // fixed

 

search form code

<form method='post' action='movies.php'>
<input class='input1' type='text' name='search' size=15 maxlength=50>
<input class='button1' type='Submit' name='Submit' value='Search'
</form>

 

what is wrong, and why my recomendation form i taking action as search form, without passing variable too.

 

need some help, please

 

nita

there is a bit of improvment now, i manage to get form to right if else condition.

But still have a problem couse at the time browser displying me automaticly that i have sent recomendation.

is not showing form any more.  I dont understand why ?

 

if(!isset($_POST['submitform'])) 

{
    
   $myemail = "[email protected]";
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $messagehtml = str_replace("\r", '<br/>', $message);
    $thanks = "
    <p align='left' class='info2'><span class='info2'>
    Thank you !. Your recomendation has sucessfuly been sent!<br>
    <br></span></p>";
        
$subject = "New Movie Recomendation from $Name";
$messagetoemail = "Hi Kris. You recived a new movie recomendation.
Name: $name
E-mail: $email
Recomendation: $messagehtml
";
$yourcode=$_POST['yourcode'];
   $thevalue1=$_POST['thevalue1'];
   
   if($yourcode==$thevalue1)
   {
echo "$thanks";

   }
   else
   {
      echo "You verification code is not right. Please go back and try again.";
   }

}

else

{


<form action='$PHP_SELF' method='post'>
        <input name='name' size='30'>
        <input name='email' size='30'>
        <textarea name='message' rows='10' cols='30'></textarea>
$im = ImageCreate(60, 20);  //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
$md5 = md5(microtime() * mktime()); 
$string = substr($md5,0,5);
$verification = $string;
$thevalue= $string;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 10, 3, $verification, $white);
Imagejpeg($im, "inc/verify.jpeg");
ImageDestroy($im);
<img src='inc/verify.jpeg' border='0'>
<input type='hidden' value='$thevalue' name='thevalue1'>
    <input type='text' name='yourcode' size='5' maxlength='5'>
        <input class='button1' type='submit' value='Send' name='submitform'>
        <input class='button1' type='reset' value='Reset' name='reset'>
</form>
}
any ideas ??

 

any ideas ??

 

thanks

 

nita

Problem - when i press submit button php is taking action as if i will press submit button of search form.... and goes to search else if part of code

 

Current code.

 

if(isset($_GET['cat'])) // when looking at selected category of movies
{

}
// when i press submit button on the recomendation form php goes here

else if(isset($_POST['submit'])||isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed
{

}

else  //when looking at the root of the aplication

{

if ($_POST['submitform'])

{

   $myemail = "[email protected]";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$messagehtml = str_replace("\r", '<br/>', $message);
$thanks = "
<p align='left' class='info2'><span class='info2'>
Thank you !. Your recomendation has sucessfuly been sent!<br>
<br></span></p>";

$subject = "New Movie Recomendation from $Name";
$messagetoemail = "Hi Kris. You recived a new movie recomendation.
Name: $name
E-mail: $email
Recomendation: $messagehtml
";
$yourcode=$_POST['yourcode'];
   $thevalue1=$_POST['thevalue1'];
   
   if($yourcode==$thevalue1)
   {
echo "$thanks";

   }
   else
   {
      echo "You verification code is not right. Please go back and try again.";
   }

}

else

{
// recomendation form
<form action='movies.php' method='post'>
        <input name='name' size='30'>
        <input name='email' size='30'>
        <textarea name='message' rows='10' cols='30'></textarea>
$im = ImageCreate(60, 20);  //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
$md5 = md5(microtime() * mktime()); 
$string = substr($md5,0,5);
$verification = $string;
$thevalue= $string;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 10, 3, $verification, $white);
Imagejpeg($im, "inc/verify.jpeg");
ImageDestroy($im);
<img src='inc/verify.jpeg' border='0'>
<input type='hidden' value='$thevalue' name='thevalue1'>
<input type='text' name='yourcode' size='5' maxlength='5'>
        <input class='button1' type='submit' value='Send' name='submitform'>
        <input class='button1' type='reset' value='Reset' name='reset'>
}
}

 

i'm well stuck on this.

i have to say that once i keep this recomendation seaperate ( not beetween

else { } ) is working with no problem,

 

i don't understand why php is moving to search part of the code...

 

i need some help ....

 

nita

 

yes is posting to it self ..

 

entire code is quite long .. and containg a lot of not connected with the problem information.

i trimmed it a bit foem html css.

 

 


<?
include "connectdb.php";

if(isset($_GET['cat'])) // when looking at selected category of movies
{
			$result = mysql_query("SELECT * FROM moviescat ORDER BY cat") or die(mysql_error());
			while($row = mysql_fetch_array( $result )) 
{
echo "<span class='links1'><A href='movies.php?cat=$row[cat]'>$row[cat]</a></span><br>";
}

<form method='post' action='movies.php'>
<input class='input1' type='text' name='search' size=15 maxlength=50>
<input class='button1' type='Submit' name='Submit' value='Search'
</form>
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
$max_results = 10;
$from = (($page * $max_results) - $max_results); 

$cat=$_GET['cat'];
	$result = mysql_query("SELECT * FROM movies WHERE cat='$cat' ORDER BY name LIMIT $from, $max_results") or die(mysql_error());
echo "
<span class='info1'>";
echo $cat;
echo "</span><hr noshade size='1' color='#FF6600'></td></tr>";
echo "

while($row=mysql_fetch_array($result))
	{
include "movies_display_rec.php";
}


$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM movies WHERE cat='$cat' ORDER BY name"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks

echo "
<table width='0' border='0' cellspacing='0' cellpadding='3' align='center'>
   <tr>";
// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "
<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?cat=$cat&page=$prev\">Previous</a></td>
  	<td width='2'></td>
";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "<td class='nav'>$i</td>
	<td width='2'></td>";
        } else {
            echo "<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?cat=$cat&page=$i\">$i</a></td>
		<td width='2'></td>";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?cat=$cat&page=$next\">Next</a><td>";
}
echo "</tr>
</table>";

}

else if(isset($_POST['submit'])||isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed
{
			$result = mysql_query("SELECT * FROM moviescat ORDER BY cat") or die(mysql_error());
			while($row = mysql_fetch_array( $result )) 
{
echo "<span class='links1'><A href='movies.php?cat=$row[cat]'>$row[cat]</a></span><br>";
}
echo "	
<form method='post' action='movies.php'>
<input class='input1' type='text' name='search' size=15 maxlength=50>
<input class='button1' type='Submit' name='Submit' value='Search'
</form>

$PHP_SELF = $_SERVER['HTTP_REFERER'];


if (isset($_GET['search'])) //if this is set then a pagination link has been clicked
{
	$search = $_GET['search']; //use this as the search string
} 
else
{
	$search=$_POST['search']; //otherwise use this 
}

$minchar = 2;
if (strlen($search) < $minchar)
{
	echo	"<span class='info1'>Search must be longer than 2 characters.</span>
} 
else 
	{	
	if(!isset($_GET['page'])){
    	$page = 1;
	} else {
    	$page = $_GET['page'];
	}
	$max_results = 10;
	$from = (($page * $max_results) - $max_results); 

	$result = mysql_query("SELECT * FROM movies WHERE name LIKE '%$search%' 
    OR cast LIKE '%$search%' OR director LIKE '%$search%' 
    OR year LIKE '%$search%' OR production LIKE '%$search%'
    OR genere LIKE '%$search%' OR language LIKE '%$search%' ORDER BY name LIMIT $from, $max_results");

    $numrows=mysql_num_rows($result);
    if ($numrows == 0)
  	    {
  	          echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
		echo "<p><span class='info1'>Sorry, your search returned 0 results</span></p>
	}
    else 
    {
		        while($row=mysql_fetch_array($result))
        {	
       	        include "movies_display_rec.php";
        }
    
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM movies WHERE name LIKE '%$search%' 
    OR cast LIKE '%$search%' OR director LIKE '%$search%' 
    OR year LIKE '%$search%' OR production LIKE '%$search%'
    OR genere LIKE '%$search%' OR language LIKE '%$search%' ORDER BY name"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
echo "<tr><td>";
// Build Page Number Hyperlinks
echo "
<table width='0' border='0' cellspacing='0' cellpadding='3' align='center'>
   <tr>";
   
   
// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "
<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?search=$search&page=$prev\">Previous</a></td>
  	<td width='2'></td>
";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "<td class='nav'>$i</td>
	<td width='2'></td>";
        } else {			
            echo "<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?search=$search&page=$i\">$i</a></td>
		<td width='2'></td>";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);		
    echo "<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?search=$search&page=$next\">Next</a><td>";
}
}

else  //when looking at the root of the aplication

{


			$result = mysql_query("SELECT * FROM moviescat ORDER BY cat") or die(mysql_error());
			while($row = mysql_fetch_array( $result )) 
{
echo "<span class='links1'><A href='movies.php?cat=$row[cat]'>$row[cat]</a></span><br>";
}

<form method='post' action='movies.php'>
<input class='input1' type='text' name='search' size=15 maxlength=50>
<input class='button1' type='Submit' name='Submit' value='Search'
</form>

$result = mysql_query("SELECT * FROM movies WHERE id='300'") or die(mysql_error());  
  while($row = mysql_fetch_array( $result )) {

  include "movies_display_rec.php";
	}
<span class='info2'>Recommend me your favorite movie !</span><br><hr noshade size='1'  width='690' color='#FF6600'>";


if ($_POST['submitform'])

{

   $myemail = "[email protected]";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$messagehtml = str_replace("\r", '<br/>', $message);
$thanks = "
<p align='left' class='info2'><span class='info2'>
Thank you !. Your recomendation has sucessfuly been sent!<br>
<br></span></p>";

$subject = "New Movie Recomendation from $Name";
$messagetoemail = "Hi Kris. You recived a new movie recomendation.
Name: $name
E-mail: $email
Recomendation: $messagehtml
";
$yourcode=$_POST['yourcode'];
   $thevalue1=$_POST['thevalue1'];
   
   if($yourcode==$thevalue1)
   {
echo "$thanks";

   }
   else
   {
      echo "You verification code is not right. Please go back and try again.";
   }

}

else

{

//this is recomandation form
echo "
<table width='100%'  border='0' cellspacing='0' cellpadding='10'>
  <tr>
    <td>

<form action='$PHP_SELF' method='post'>
  <table width='444' align='left' class='info4'>
    <tr>
      <td valign='top' align='right'><b>Name:</b></td>
      <td valign='top'>
        <input name='name' size='30'>
      </td>
    </tr>
    <tr>
      <td valign='top' align='right'><b>E-mail:</b></td>
      <td valign='top'>
        <input name='email' size='30'>
      </td>
    </tr>
    <tr>
      <td valign='top' align='right'><b>Recomendation:</b></td>
      <td valign='top'>
        <textarea name='message' rows='10' cols='30'></textarea>
      </td>
    </tr>
    <tr>
<td>";
$im = ImageCreate(60, 20);  //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
$md5 = md5(microtime() * mktime()); 
$string = substr($md5,0,5);
$verification = $string;
$thevalue= $string;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 10, 3, $verification, $white);
Imagejpeg($im, "inc/verify.jpeg");
ImageDestroy($im);
echo "
<img src='inc/verify.jpeg' border='0'>
<input type='hidden' value='$thevalue' name='thevalue1'>
</td>
<td>
<input type='text' name='yourcode' size='5' maxlength='5'>
</td>
</tr>
<td valign='top' align='right'></td>
      <td valign='top' align='left'>
        <input class='button1' type='submit' value='Send' name='submitform'>
        <input class='button1' type='reset' value='Reset' name='reset'>
      </td>

    </tr>
  </table>
</form>
</td>
  </tr>
</table><br>";
}
echo "
</td>
</tr>
<tr>
<td valign='top'>

}

?>

 

take a look at

www.nita-on-line.com/movies.php

and test recomendation form

 

thank you

 

nita

 

i had altered some code .. so this is latest version of the scrip i worked out, no changes in results,

still, once submit button pressed php is moving to search else if part of the code (as if i press submit button on search form)

 

go to http://www.nita-on-line.com/movies.php

and test recomendation form, and see what is happenig your self ... please

 

i test it without any other if else stament and its ok ....

go to http://www.nita-on-line.com/test.php

 

I have no qlue why, i suspect some mistake in if else structre of the application, i need some suggestions ....

 

thank you a lot in advance

 

nita

 

 

if(isset($_GET['cat'])) // when looking at selected category of movies 
{ 

// display by chosen category 

} 

// so when i press submit button on my recomendation form php is 
// moving to this else if .. why? 

else if(isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed 
{ 

// some code (display results when search button pressed) 
// code for search form below ... 
<form method='post' action='movies.php'> 
        <input class='input1' type='text' name='search' size=15 maxlength=50> 
        <input class='button1' type='submit' name='submit' value='Search' 
        </form> 


} 

else  //when looking at the root of the aplication 

{ 

// some code 

if (isset($_POST['submitreco'])) 

{ 
        
        $myemail = "[email protected]"; 
        $name = $_POST['name']; 
        $email = $_POST['email']; 
        $message = $_POST['message']; 
        $messagehtml = str_replace("\r", '<br/>', $message); 
        $thanks = " 
        <p align='left' class='info2'><span class='info2'> 
        Thank you !. Your recomendation has sucessfuly been sent!<br> 
        <br></span></p>"; 
        $subject = "New Movie Recomendation from $Name"; 
        $messagetoemail = "Hi Kris. You recived a new movie recomendation. 
        Name: $name 
        E-mail: $email 
        Recomendation: $messagehtml 
        "; 
        $yourcode=$_POST['yourcode']; 
   $thevalue1=$_POST['thevalue1']; 
    
   if($yourcode==$thevalue1) 
   { 
        echo "$thanks"; 

   } 
   else 
   { 
      echo "You verification code is not right. Please go back and try again."; 
   } 
} 

else 

{ 
$PHP_SELF = $_SERVER['PHP_SELF']; 
//this is recomandation form 
echo " 
<table width='100%'  border='0' cellspacing='0' cellpadding='10'> 
  <tr> 
    <td> 

<form action='$PHP_SELF' method='post'> 
  <table width='444' align='left' class='info4'> 
    <tr> 
      <td valign='top' align='right'><b>Name:</b></td> 
      <td valign='top'> 
        <input name='name' size='30'> 
      </td> 
    </tr> 
    <tr> 
      <td valign='top' align='right'><b>E-mail:</b></td> 
      <td valign='top'> 
        <input name='email' size='30'> 
      </td> 
    </tr> 
    <tr> 
      <td valign='top' align='right'><b>Recomendation:</b></td> 
      <td valign='top'> 
        <textarea name='message' rows='10' cols='30'></textarea> 
      </td> 
    </tr> 
    <tr> 
<td>"; 
$im = ImageCreate(60, 20);  //create image 
$white = ImageColorAllocate($im, 0,0, 0); 
$black = ImageColorAllocate($im, 120, 200, 68); 
$md5 = md5(microtime() * mktime()); 
$string = substr($md5,0,5); 
$verification = $string; 
$thevalue= $string; 
ImageFill($im, 0, 0, $black); 
ImageString($im, 4, 10, 3, $verification, $white); 
Imagejpeg($im, "inc/verify.jpeg"); 
ImageDestroy($im); 
echo " 
<img src='inc/verify.jpeg' border='0'> 
<input type='hidden' value='$thevalue' name='thevalue1'> 
</td> 
        <td> 
        <input type='text' name='yourcode' size='5' maxlength='5'> 
        </td> 
        </tr> 
        <td valign='top' align='right'></td> 
      <td valign='top' align='left'> 
        <input class='button1' type='submit' value='Send' name='submitreco'> 
        <input class='button1' type='reset' value='Reset' name='reset'> 
      </td> 
        
    </tr> 
  </table> 
</form> 
</td> 
  </tr> 
</table><br>"; 
} 
}    

this is where php is expected to start after submit on recomendation form

if (isset($_POST['submitreco'])) 

 

instead is going to

 


else if(isset($_POST['search'])||isset($_GET['search']))

 

i think that maybe a problem, solutinon - i dont have on

 

can you help ??

 

thanks

 

nita

> - closing tag to input was missing

 

 

fixed code

 

else if(isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed 
{ 
<form method='post' action='movies.php'> 
        <input class='input1' type='text' name='search' size=15 maxlength=50> 
        <input class='button1' type='submit' name='submit' value='Search' > // here i found the bug
        </form> 


} 

 

thanks a lot for help and sugestions ...

 

nita

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.