Jump to content

Another form submission driving me mad


Paul_Withers
 Share

Go to solution Solved by Paul_Withers,

Recommended Posts

Hi guys, I got this form so a user can submit a care guide for different species of animal. However the script runs, but the query to SET the species information does not run and the success message is not displayed.  Here is what I have got

<?php

session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');

require( 'database.php' );

include('includes/overall/header.php');

$username = $_SESSION['loggedinuser'];


if	(isset($_POST['username'], $_POST['email'], $_POST['fishtype'], $_POST['speciesCommon'], $_POST['speciesScientific'], $_POST['speciesSynonym'], $_POST['origin'], $_POST['size'], $_POST['environment'], $_POST['waterChemistry'], $_POST['temperature'], $_POST['temperature1'], $_POST['feeding'], $_POST['sexing'], $_POST['compatability'], $_POST['temperament'], $_POST['breeding'], $_POST['comments'], $_POST['reward'], $_POST['username'], $_POST['email'] ) ) {
     
    if( $_POST['fishtype'] == "" )
    {
        include('includes/overall/header.php');
        echo "You must select a species type";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['speciesCommon'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a species type";
        include('includes/overall/footer.php');
    }
  	elseif( $_POST['speciesScientific'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a scientific name";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['speciesSynonym'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a species synonym";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['origin'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the origin of this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['size'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a average size";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['environment'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the type of environment suited to this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['waterChemistry'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the typeif water chemistry required for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['temperature'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a minimum temperature for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['temperature1'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a maximum temperature for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['feeding'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter feeding information for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['sexing'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter sexing information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['compatibility'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter compatibility information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['temperament'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter temperament information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['breeding'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter breeding information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['comments'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter comments for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['compatibility'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select your reward";
        include('includes/overall/footer.php');
    }
    else
    {
    	
        require( 'database.php' );

        $fishtype = mysqli_real_escape_string($con, $_POST['fishtype']);
        $speciesCommon = mysqli_real_escape_string($con, $_POST['speciesCommon']);
        $speciesScientific = mysqli_real_escape_string($con, $_POST['speciesScientific']);
        $speciesSynonym = mysqli_real_escape_string($con, $_POST['speciesSynonym'] );
		$origin = mysqli_real_escape_string($con, $_POST['origin']);
        $size = mysqli_real_escape_string($con, $_POST['size']);
        $environment = mysqli_real_escape_string($con, $_POST['environment']);
        $waterChemistry = mysqli_real_escape_string($con, $_POST['waterChemistry']);
        $temperature = mysqli_real_escape_string($con, $_POST['temperature']);
        $temperature1 = mysqli_real_escape_string($con, $_POST['temperature1']);
        $feeding = mysqli_real_escape_string($con, $_POST['feeding']);
        $sexing = mysqli_real_escape_string($con, $_POST['sexing']);
        $compatibility = mysqli_real_escape_string($con, $_POST['compatibility']);
        $temperament = mysqli_real_escape_string($con, $_POST['temperament']);
        $breeding = mysqli_real_escape_string($con, $_POST['breeding']);
        $comments = mysqli_real_escape_string($con, $_POST['comments']);
        $reward = mysqli_real_escape_string($con, $_POST['reward']);
        $username = mysqli_real_escape_string($con, $_POST['username']);
        $email = mysqli_real_escape_string($con, $_POST['email']);
   

// Define a query to run 
$regCareGuide = "INSERT INTO species( fishtype, speciesCommon, speciesScientific, speciesSynonym, origin, size, environment, waterChemistry, temperature, temperature1, feeding, sexing, compatibility, temperament, breeding, comments ) VALUES (
                        '". $fishtype ."',
                        '". $speciesCommon ."',
                        '". $speciesScientific ."',
                        '". $speciesSynonym ."',
                        '". $origin ."',
                        '". $size ."',
                        '". $environment ."',
                        '". $waterChemistry ."',
                        '". $temperature ."',
                        '". $temperature1 ."',
                        '". $feeding ."',
                        '". $sexing ."',
                        '". $compatability ."',
                        '". $temperament ."',
                        '". $breeding ."',
                        '". $comments ."',
                        '". $reward."'
                        ) WHERE `username` = '$username' AND `email` = '$email'";
		 
// Query the database 
$result = mysqli_query($con, $regCareGuide); 


// Check if the query failed 
if( !$result ) 
{ 
   die('There was a problem executing the query ('.$regCareGuide.'):<br>('.mysqli_errno($con).') '.mysqli_error($con)); 
} 

else { 

	echo 'Your care guide has been submitted and your account has been credited.';
}    
}
}
include('includes/overall/footer.php');
        
// Close the connection 
mysqli_close($con); 
?>

This is pretty much the same as my changepassword.php page but the query is different and this seems to have prevented the script from running correctly.  

 

I have tried different variations on INSERT to add the data to the database but nothing is working,

 

Also an online PHP checker says there is no error in the code.

 

Please help! :)

 

 

Link to comment
Share on other sites

At first glance I don't see nothing wrong. Are you sure you're calling your code inside the else block? So, do an echo command as in the example below, and tell me what you get:

else
    {
    	echo 'call'; exit;
        require( 'database.php' );
............................................
Link to comment
Share on other sites

Hi Jazzman, I chnaged it to this, but still get nothing. Have I implemented this correctly?

<?php

session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');

require( 'database.php' );

include('includes/overall/header.php');

$username = $_SESSION['loggedinuser'];


if	(isset($_POST['username'], $_POST['email'], $_POST['fishtype'], $_POST['speciesCommon'], $_POST['speciesScientific'], $_POST['speciesSynonym'], $_POST['origin'], $_POST['size'], $_POST['environment'], $_POST['waterChemistry'], $_POST['temperature'], $_POST['temperature1'], $_POST['feeding'], $_POST['sexing'], $_POST['compatability'], $_POST['temperament'], $_POST['breeding'], $_POST['comments'], $_POST['reward'] ) ) {
     
    if( $_POST['fishtype'] == "" )
    {
        include('includes/overall/header.php');
        echo "You must select a species type";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['speciesCommon'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a species type";
        include('includes/overall/footer.php');
    }
  	elseif( $_POST['speciesScientific'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a scientific name";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['speciesSynonym'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a species synonym";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['origin'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the origin of this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['size'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a average size";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['environment'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the type of environment suited to this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['waterChemistry'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the typeif water chemistry required for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['temperature'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a minimum temperature for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['temperature1'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a maximum temperature for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['feeding'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter feeding information for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['sexing'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter sexing information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['compatibility'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter compatibility information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['temperament'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter temperament information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['breeding'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter breeding information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['comments'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter comments for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['compatibility'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select your reward";
        include('includes/overall/footer.php');
    }
    else
    {
    	echo 'call'; exit;
        require( 'database.php' );
   
        $fishtype = mysqli_real_escape_string($con, $_POST['fishtype']);
        $speciesCommon = mysqli_real_escape_string($con, $_POST['speciesCommon']);
        $speciesScientific = mysqli_real_escape_string($con, $_POST['speciesScientific']);
        $speciesSynonym = mysqli_real_escape_string($con, $_POST['speciesSynonym'] );
	$origin = mysqli_real_escape_string($con, $_POST['origin']);
        $size = mysqli_real_escape_string($con, $_POST['size']);
        $environment = mysqli_real_escape_string($con, $_POST['environment']);
        $waterChemistry = mysqli_real_escape_string($con, $_POST['waterChemistry']);
        $temperature = mysqli_real_escape_string($con, $_POST['temperature']);
        $temperature1 = mysqli_real_escape_string($con, $_POST['temperature1']);
        $feeding = mysqli_real_escape_string($con, $_POST['feeding']);
        $sexing = mysqli_real_escape_string($con, $_POST['sexing']);
        $compatibility = mysqli_real_escape_string($con, $_POST['compatibility']);
        $temperament = mysqli_real_escape_string($con, $_POST['temperament']);
        $breeding = mysqli_real_escape_string($con, $_POST['breeding']);
        $comments = mysqli_real_escape_string($con, $_POST['comments']);
        $reward = mysqli_real_escape_string($con, $_POST['reward']);
        $username = mysqli_real_escape_string($con, $_POST['username']);
        $email = mysqli_real_escape_string($con, $_POST['email']);
   

// Define a query to run 
$regCareGuide = "INSERT INTO species( fishtype, speciesCommon, speciesScientific, speciesSynonym, origin, size, environment, waterChemistry, temperature, temperature1, feeding, sexing, compatibility, temperament, breeding, comments ) VALUES (
                        '". $fishtype ."',
                        '". $speciesCommon ."',
                        '". $speciesScientific ."',
                        '". $speciesSynonym ."',
                        '". $origin ."',
                        '". $size ."',
                        '". $environment ."',
                        '". $waterChemistry ."',
                        '". $temperature ."',
                        '". $temperature1 ."',
                        '". $feeding ."',
                        '". $sexing ."',
                        '". $compatability ."',
                        '". $temperament ."',
                        '". $breeding ."',
                        '". $comments ."',
                        '". $reward."'
                         WHERE `username` = '$username' AND `email` = '$email')";
		 
// Query the database 
$result = mysqli_query($con, $regCareGuide); 


// Check if the query failed 
if( !$result ) 
{ 
   die('There was a problem executing the query ('.$regCareGuide.'):<br>('.mysqli_errno($con).') '.mysqli_error($con)); 
} 

else { 

	echo 'Your care guide has been submitted and your account credited.';
}    
}
include('includes/overall/footer.php');
}   
// Close the connection 
mysqli_close($con); 
?>

Im confused :(

Edited by Paul_Withers
Link to comment
Share on other sites

Make sure that the url of the action attribute of your submitting form points to this file. I'm guessing you're not submitting the data to this script at all.

 

 

INSERT queries do not have a WHERE clause

 

I completely missed that :tease-01:

Edited by jazzman1
Link to comment
Share on other sites

Hi Jazzman, here is the form

 <?php
session_start();  //this will start the session for the user

error_reporting(E_ALL);
ini_set('display_errors', '1');

include 'includes/overall/header.php';

$username = $_SESSION['loggedinuser'];
//MySqli Select Query
require( 'database.php' );

$results = $con->query("SELECT * FROM user WHERE username = '$username';");
while($row = $results->fetch_array()) {
$username = $row['username'];
$email = $row['email'];

//MySqli Select Query

?>


<form action="submitCareGuideCheck.php" id="fishForm" method="POST">		
<input type="hidden" name="username" value="<?php echo $username ?>">
<input type="hidden" name="email" value="<?php echo $email ?>">
<h2>Care Guide</h2>
<br>
<ul>
<li>Species*:</br>
<select name="fishtype">
    <option value="none">--choose--</option>
    <option value="cichlids"> Cichlids</option>
    <option value="tropical_fish"> Tropical Fish</option>
    <option value="tropical_shrimp"> Tropical Shrimp</option>
    <option value="tropical_frogs"> Tropical Frogs</option>
    <option value="tropical_snails"> Tropical Snails</option>
    <option value="marine_fish"> Marine Fish</option>
    <option value="marine_shrimp"> Marine Shrimp</option>
    <option value="marine_snails"> Marine Snails</option>
</select>
</li>
<li>Common Name*:</br>
<select name="speciesCommon">
   <option value="">--choose one--</option>
</select>
</li>
<li>Scientific Name*:</br>
<select name="speciesScientific">
   <option value="">--choose one--</option>
</select>
</li>

<li>Synonym*:</br>
<select name="speciesSynonym">
	<option value="">--choose one--</option>
</select>
</li>
	

	<li>Origin*:</br>
		<select multiple name="origin">
			<option>--choose one--...</option>
			<option value="North America">North America</option>
			<option value="Central America">Central America</option>
			<option value="South America">South America</option>
			<option value="Caribbean">Caribbean</option>
			<option value="Central Africa">Central Africa</option>
			<option value="East Africa">East Africa</option>
			<option value="West Africa">West Africa</option>
			<option value="Southeast Asia">Southeast Asia</option>
			<option value="India">India</option>
		</select>
	</li>
			
<li>Size*:</br>
		<select name="size">
			<option>Choose...</option>
			<option value="1cm - 3cm">1cm - 3cm</option>
			<option value="3cm - 5cm">3cm - 5cm</option>
			<option value="5cm - 7cm">5cm - 7cm</option>
			<option value="7cm - 9cm">7cm - 9cm</option>
			<option value="9cm - 11cm">9cm - 11cm</option>
			<option value="11cm - 13cm">11cm - 13cm</option>
			<option value="13cm - 15cm">13cm - 15cm</option>
			<option value="15cm - 17cm">15cm - 17cm</option>
			<option value="17cm - 19cm">17cm - 19cm</option>
			<option value="19cm - 21cm">19cm - 21cm</option>
			<option value="21cm - 23cm">21cm - 23cm</option>
			<option value="23cm - 25cm">23cm - 25cm</option>
			<option value="25cm - 27cm">25cm - 27cm</option>
			<option value="27cm - 29cm">27cm - 29cm</option>
			<option value="29cm - 31cm">29cm - 31cm</option>
			<option value="31cm - 33cm">31cm - 33cm</option>
			<option value="33cm - 35cm">33cm - 35cm</option>
			<option value="35cm - 37cm">35cm - 37cm</option>
			<option value="37cm - 39cm">37cm - 39cm</option>
			<option value="39cm - 41cm">39cm - 41cm</option>
			<option value="41cm - 43cm">41cm - 43cm</option>
			<option value="43cm - 45cm">43cm - 45cm</option>
			<option value="45cm - 47cm">45cm - 47cm</option>
			<option value="47cm - 49cm">47cm - 49cm</option>
			<option value="49cm - 51cm">49cm - 51cm</option>
			<option value="51cm - 53cm">51cm - 53cm</option>
			<option value="53cm - 55cm">53cm - 55cm</option>
			<option value="55cm - 57cm">55cm - 57cm</option>
			<option value="57cm - 59cm">57cm - 59cm</option>
			<option value="59cm - 61cm">59cm - 61cm</option>
			<option value="61cm - 63cm">61cm - 63cm</option>
			<option value="63cm - 65cm">63cm - 65cm</option>
			<option value="65cm - 67cm">65cm - 67cm</option>
			<option value="67cm - 69cm">67cm - 69cm</option>
			<option value="69cm - 71cm+">69cm - 71cm+</option>
			
		</select>
	</li>
</ul>
	<h2>Environment</h2>
<ul>	
	<li>Lakes: <input type="checkbox" name="environment" value="Lakes"/>
					
	Ponds: <input type="checkbox" name="environment" value="Ponds"/>
				
	Rivers: <input type="checkbox" name="environment" value="Rivers"/>
					
	Streams: <input type="checkbox" name="environment" value="Streams"/>
						
	Sea: <input type="checkbox" name="environment" value="Sea"/></li>
</ul>

<ul>				
<li>Ph level*:</br>
	<select name="waterChemistry" id="waterChemistry">
		<option>Choose...</option>
		<option value="ph5-">ph5-</option>
		<option value="ph5 - ph6">ph5 - ph6</option>
		<option value="ph6 - ph7">ph6 - ph7</option>
		<option value="ph7 - ph8">ph7 - ph8</option>
		<option value="ph8 - ph9">ph8 - ph9</option>
		<option value="ph9+">ph9+</option>
	</select>
</li>

<li>Temperature*:</br>
	<select name="temperature" id="temperature">
		<option>Choose...</option>
		<option value="-64">-64°</option>
		<option value="65">65°</option>
		<option value="66">66°</option>
		<option value="67">67°</option>
		<option value="68">68°</option>
		<option value="69">69°</option>
		<option value="70">70°</option>
		<option value="71">71°</option>
		<option value="72">72°</option>
		<option value="73">73°</option>
		<option value="74">74°</option>
		<option value="75">75°</option>
		<option value="76">76°</option>
		<option value="77">77°</option>
		<option value="78">78°</option>
		<option value="79">79°</option>
		<option value="80">80°</option>
		<option value="81">81°</option>
		<option value="82">82°</option>
		<option value="83">83°</option>
		<option value="84">84°</option>

	</select>
	to
	<select name="temperature1" id="temperature1">
		<option>Choose...</option>
		<option value="66">66°</option>
		<option value="67">67°</option>
		<option value="68">68°</option>
		<option value="69">69°</option>
		<option value="70">70°</option>
		<option value="71">71°</option>
		<option value="72">72°</option>
		<option value="73">73°</option>
		<option value="74">74°</option>
		<option value="75">75°</option>
		<option value="76">76°</option>
		<option value="77">77°</option>
		<option value="78">78°</option>
		<option value="79">79°</option>
		<option value="80">80°</option>
		<option value="81">81°</option>
		<option value="82">82°</option>
		<option value="83">83°</option>
		<option value="84">84°</option>

	</select>
</li>
			
<li>Temperament*:</br>
	<select name="temperament">
		<option>Choose...</option>
		<option value="peaceful">Peaceful</option>
		<option value="Semi-Aggressive">Semi-Aggressive</option>
		<option value="Aggressive">Aggressive</option>
	</select>
</li>
			
<li>Feeding*:</br>
	<textarea name="feeding"/></textarea>
</li>
			
<li>Sexing*:</br>
	<textarea name="sexing"></textarea>
</li>
			
<li>Compatability*:</br>
	<textarea name="compatibility"></textarea>
</li>
			
		
<li>Breeding*:</br>
	<textarea name="breeding"></textarea>
</li>
			
<li>Comments*:</br>
	<textarea name="comments"></textarea>
</li>
</ul>
<ul>		
<li>Upload Photo:</br>
	<input id="file" type="file" name="uploadPhoto">
</li>
</ul>		
		
<h2>Choose your reward</h2>
<ul>
<li>If you did not upload a photo then choose:</li>
		
<li>A maximum of 10 listings*:
	<input type="radio" name="reward" value="10">
</li>
</ul>

<ul>
<li>If you uploaded a photo, then choose:</li>
			
<li>A maximum of 25 listings*:
	<input type="radio" name="reward" value="25">
</li>
</ul>

<h3>Please Note:</h3>
<p>Selecting a reward which you are not entitled to, will result in your account being suspended</p>
<p>If you chose to have your listings displayed on our homepage, then your reward can take up to 24 hours before being credited to your account.</p>
<ul>
<li>		
<input type="submit" value="Submit Guide"></li>
</ul>
</form>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="species.js"></script>    



<?php
}
 include 'includes/overall/footer.php'; ?>

and here is the script it is posted to, including removing the WHERE clause

<?php

session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');

require( 'database.php' );

include('includes/overall/header.php');

$username = $_SESSION['loggedinuser'];


if	(isset($_POST['username'], $_POST['email'], $_POST['fishtype'], $_POST['speciesCommon'], $_POST['speciesScientific'], $_POST['speciesSynonym'], $_POST['origin'], $_POST['size'], $_POST['environment'], $_POST['waterChemistry'], $_POST['temperature'], $_POST['temperature1'], $_POST['feeding'], $_POST['sexing'], $_POST['compatability'], $_POST['temperament'], $_POST['breeding'], $_POST['comments'], $_POST['reward'] ) ) {
     
    if( $_POST['fishtype'] == "" )
    {
        include('includes/overall/header.php');
        echo "You must select a species type";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['speciesCommon'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a species type";
        include('includes/overall/footer.php');
    }
  	elseif( $_POST['speciesScientific'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a scientific name";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['speciesSynonym'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a species synonym";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['origin'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the origin of this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['size'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a average size";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['environment'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the type of environment suited to this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['waterChemistry'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the typeif water chemistry required for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['temperature'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a minimum temperature for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['temperature1'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a maximum temperature for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['feeding'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter feeding information for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['sexing'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter sexing information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['compatibility'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter compatibility information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['temperament'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter temperament information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['breeding'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter breeding information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['comments'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter comments for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['compatibility'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select your reward";
        include('includes/overall/footer.php');
    }
    else
    {
    	echo 'call'; exit;
        require( 'database.php' );
   
        $fishtype = mysqli_real_escape_string($con, $_POST['fishtype']);
        $speciesCommon = mysqli_real_escape_string($con, $_POST['speciesCommon']);
        $speciesScientific = mysqli_real_escape_string($con, $_POST['speciesScientific']);
        $speciesSynonym = mysqli_real_escape_string($con, $_POST['speciesSynonym'] );
	$origin = mysqli_real_escape_string($con, $_POST['origin']);
        $size = mysqli_real_escape_string($con, $_POST['size']);
        $environment = mysqli_real_escape_string($con, $_POST['environment']);
        $waterChemistry = mysqli_real_escape_string($con, $_POST['waterChemistry']);
        $temperature = mysqli_real_escape_string($con, $_POST['temperature']);
        $temperature1 = mysqli_real_escape_string($con, $_POST['temperature1']);
        $feeding = mysqli_real_escape_string($con, $_POST['feeding']);
        $sexing = mysqli_real_escape_string($con, $_POST['sexing']);
        $compatibility = mysqli_real_escape_string($con, $_POST['compatibility']);
        $temperament = mysqli_real_escape_string($con, $_POST['temperament']);
        $breeding = mysqli_real_escape_string($con, $_POST['breeding']);
        $comments = mysqli_real_escape_string($con, $_POST['comments']);
        $reward = mysqli_real_escape_string($con, $_POST['reward']);
        $username = mysqli_real_escape_string($con, $_POST['username']);
        $email = mysqli_real_escape_string($con, $_POST['email']);
   

// Define a query to run 
$regCareGuide = "INSERT INTO species( fishtype, speciesCommon, speciesScientific, speciesSynonym, origin, size, environment, waterChemistry, temperature, temperature1, feeding, sexing, compatibility, temperament, breeding, comments, username, email ) VALUES (
                        '". $fishtype ."',
                        '". $speciesCommon ."',
                        '". $speciesScientific ."',
                        '". $speciesSynonym ."',
                        '". $origin ."',
                        '". $size ."',
                        '". $environment ."',
                        '". $waterChemistry ."',
                        '". $temperature ."',
                        '". $temperature1 ."',
                        '". $feeding ."',
                        '". $sexing ."',
                        '". $compatability ."',
                        '". $temperament ."',
                        '". $breeding ."',
                        '". $comments ."',
                        '". $reward ."',
                        '". $username ."',
                        '". $email."'
                         )";
		 
// Query the database 
$result = mysqli_query($con, $regCareGuide); 


// Check if the query failed 
if( !$result ) 
{ 
   die('There was a problem executing the query ('.$regCareGuide.'):<br>('.mysqli_errno($con).') '.mysqli_error($con)); 
} 

else { 

	echo 'Your care guide has been submitted and your account credited.';
}    
}
include('includes/overall/footer.php');
}   
// Close the connection 
mysqli_close($con); 
?>
Link to comment
Share on other sites

Then, open up "submitCareGuideCheck.php " file and add the following line as in the example below, submit the form with all data you want to be submitted and post out the result:

<?php

session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');

echo '<pre>'.print_r($_POST,true).'</pre>'; exit;  // this line

require( 'database.php' );

EDIT: Make sure this is the right file with insertion data!

Edited by jazzman1
Link to comment
Share on other sites

Move my code down on your script:

<?php

session_start();

error_reporting(E_ALL);

ini_set('display_errors', '1');

require( 'database.php' );

include('includes/overall/header.php');

$username = $_SESSION['loggedinuser'];

if(isset($_POST['username'], $_POST['email'], $_POST['fishtype'], $_POST['speciesCommon'], $_POST['speciesScientific'], $_POST['speciesSynonym'], $_POST['origin'], $_POST['size'], $_POST['environment'], $_POST['waterChemistry'], $_POST['temperature'], $_POST['temperature1'], $_POST['feeding'], $_POST['sexing'], $_POST['compatability'], $_POST['temperament'], $_POST['breeding'], $_POST['comments'], $_POST['reward'])) {
   
echo '<pre>'.print_r($_POST,true).'</pre>'; // here 

No need to include your database credentials twice, only once on the top of the file is enough!

Edited by jazzman1
Link to comment
Share on other sites

Ok got:

<?php

session_start();

error_reporting(E_ALL);

ini_set('display_errors', '1');

require( 'database.php' );

include('includes/overall/header.php');

$username = $_SESSION['loggedinuser'];

if(isset($_POST['username'], $_POST['email'], $_POST['fishtype'], $_POST['speciesCommon'], $_POST['speciesScientific'], $_POST['speciesSynonym'], $_POST['origin'], $_POST['size'], $_POST['environment'], $_POST['waterChemistry'], $_POST['temperature'], $_POST['temperature1'], $_POST['feeding'], $_POST['sexing'], $_POST['compatability'], $_POST['temperament'], $_POST['breeding'], $_POST['comments'], $_POST['reward'])) {
   
echo '<pre>'.print_r($_POST,true).'</pre>'; // here 
    
    if( $_POST['fishtype'] == "" )
    {
        include('includes/overall/header.php');
        echo "You must select a species type";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['speciesCommon'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a species type";
        include('includes/overall/footer.php');
    }
  	elseif( $_POST['speciesScientific'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a scientific name";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['speciesSynonym'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a species synonym";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['origin'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the origin of this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['size'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a average size";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['environment'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the type of environment suited to this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['waterChemistry'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select the typeif water chemistry required for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['temperature'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a minimum temperature for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['temperature1'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select a maximum temperature for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['temperament'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter temperament information for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['feeding'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter feeding information for this species";
        include('includes/overall/footer.php');
    }
     elseif( $_POST['sexing'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter sexing information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['compatibility'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter compatibility information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['breeding'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter breeding information for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['comments'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must enter comments for this species";
        include('includes/overall/footer.php');
    }
    elseif( $_POST['compatibility'] == "" )
    {
        
        include('includes/overall/header.php');
        echo "You must select your reward";
        include('includes/overall/footer.php');
    }
    else
    {
    	echo 'call'; exit;
   
        $fishtype = mysqli_real_escape_string($con, $_POST['fishtype']);
        $speciesCommon = mysqli_real_escape_string($con, $_POST['speciesCommon']);
        $speciesScientific = mysqli_real_escape_string($con, $_POST['speciesScientific']);
        $speciesSynonym = mysqli_real_escape_string($con, $_POST['speciesSynonym'] );
		$origin = mysqli_real_escape_string($con, $_POST['origin']);
        $size = mysqli_real_escape_string($con, $_POST['size']);
        $environment = mysqli_real_escape_string($con, $_POST['environment']);
        $waterChemistry = mysqli_real_escape_string($con, $_POST['waterChemistry']);
        $temperature = mysqli_real_escape_string($con, $_POST['temperature']);
        $temperature1 = mysqli_real_escape_string($con, $_POST['temperature1']);
        $feeding = mysqli_real_escape_string($con, $_POST['feeding']);
        $sexing = mysqli_real_escape_string($con, $_POST['sexing']);
        $compatibility = mysqli_real_escape_string($con, $_POST['compatibility']);
        $temperament = mysqli_real_escape_string($con, $_POST['temperament']);
        $breeding = mysqli_real_escape_string($con, $_POST['breeding']);
        $comments = mysqli_real_escape_string($con, $_POST['comments']);
        $reward = mysqli_real_escape_string($con, $_POST['reward']);
        $username = mysqli_real_escape_string($con, $_POST['username']);
        $email = mysqli_real_escape_string($con, $_POST['email']);
   

// Define a query to run 
$regCareGuide = "INSERT INTO species( fishtype, speciesCommon, speciesScientific, speciesSynonym, origin, size, environment, waterChemistry, temperature, temperature1, temperament, feeding, sexing, compatibility, breeding, comments, username, email ) VALUES (
                        '". $fishtype ."',
                        '". $speciesCommon ."',
                        '". $speciesScientific ."',
                        '". $speciesSynonym ."',
                        '". $origin ."',
                        '". $size ."',
                        '". $environment ."',
                        '". $waterChemistry ."',
                        '". $temperature ."',
                        '". $temperature1 ."',
                        '". $temperament ."',
                        '". $feeding ."',
                        '". $sexing ."',
                        '". $compatability ."',
                        '". $breeding ."',
                        '". $comments ."',
                        '". $reward ."',
                        '". $username ."',
                        '". $email."'
                         )";
		 
// Query the database 
$result = mysqli_query($con, $regCareGuide); 


// Check if the query failed 
if( !$result ) 
{ 
   die('There was a problem executing the query ('.$regCareGuide.'):<br>('.mysqli_errno($con).') '.mysqli_error($con)); 
} 

else { 

	echo 'Your care guide has been submitted and your account credited.';
}    
}
include('includes/overall/footer.php');
}   
// Close the connection 
mysqli_close($con); 
?>

But no luck???

Link to comment
Share on other sites

some/most of points that were made in one of your earlier threads were to reduce the amount of code you are writing to accomplish any task. it's likely that your giant isset() statement contains a typo and that whole block of code is being skipped over.

 

to repeat one of the recommendations previously given, to detect if your form has been submitted, you only need to test one of the fields you know will always exist in the form using an isset() statement. because isset() won't produce any php errors when you have made a typo in an variable name, php won't help you find mis-typed variables in your current code.

 

edit: and i just proof-read your code and you do have a typo in one of the variables in the isset() statement. i'll let you find it (hint: a programming editor with a spell checker would be of some use.)

 

PLEASE make use of the recommendations made. they will reduce the amount of code needed, which in turn reduces the chance of errors, makes it easier to write your code because you don't have to spend as much time copy/pasting/updating things, makes it easier to see what your code actually is and makes it easier to debug your code.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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