im trying to create a page when you enter data review it and deside if you want to go back and edit it or save it.

When i click on the edit bar the forms should be filed with the previous data. but for some reason its not working. it must be my lack of understanding of php of course can someone help me.

in this code i was trying just to get the title to come back before i tried any other.

Can someone please hlep me

<!-- This file creates new publications -->

<?php
//include("../include/connect.inc.php");



?>

<html>
	<head>

<title>Seagrant</title>

</head>

<body>

<!-- All data is checked for accuracy before saving it in this section -->
<?php
if($_POST["submit"])
{ 

	$title = $_POST["title"];
	$auther = $_POST["auther"];
	$description = $_POST["description"];
	$publication = $_POST["publication"];
	$date = $_POST["date"];
	$abstract = $_POST["abstract"];
	$keywords = $_POST["keywords"];
	$affiliation = $_POST["affiliation"];

	echo "<p><b>Title</b>: " . $title . "</p>";
	echo "<p><b>Auther</b>: " . $auther . "</p>";
	echo "<b>Description</b>: " . $description . "</p>";
	echo "<p><b>Publication</b>: " . $publication . "</p>";
	echo "<p><b>Date</b>: " . $date . "</p>";
	echo "<p><b>Abstract</b>: " . $abstract . "</p>";
	echo "<p><b>keywords</b>: " . $keywords . "</p>";
	echo "<p><b>affiliation</b>: " . $affiliation . "</p>";

	?>
	<form>
		<p><input type="button" onClick ="window.location='publications.php'" value="Edit" /></p>
		<p><input type="button" onClick ="window.location='publications.php?status=save'" value="Save" /></p>

	</form>
	<?php


}elseif($_GET["status"] == "save"){

	mysql_query('" . $title . "', '" . $auther . "', '" . $publication . "', '" . $date . "',	'" . $abstract . "',
			'" . $keywords . "', '" . $affiliation . "');

			echo "Have added the publication to the database.";				
}else{

	?>



 <!--- All data for the publication is entered in this section --->

<form action ="" method = "POST">
	<p>Title: <input type="text" name ="title" value="<?php echo $title; ?>"/></p>
	<p>Auther: <input type="text" name="auther" /></p>
	Description: 
	<p><textarea name="description" cols ="50" rows="10"></textarea></p>
	<p>Publication: <input type="text" name="publication" /></p>
	<p>Date(MM/DD/YYYY): <input type="text" name="date" /></p>
	<p>Abstract: <input type="text" name="abstract" /></p>
	<p>Keywords: <input type="text" name="keywords" /></p>
	<p>Affiliation: <input type="text" name="affiliation" /></p>
	<p><input type="submit" name="submit" value="Submit" /></p>
</form>

<?php
}
?>
</body>
</html>








    Looking at your code, the best thing i would suggest would be to split your code into two pages. The code gets too complicated when you add the edit logic also to it.

    1. Page with the form where the user enters data and clicks submit.

    2. Display the clients data with the edit and save options. If save is clicked save the data to the database, if edit is clicked display data for client to edit (to make it easy use a different form for edit).

      Change

      <?php echo $title; ?>

      to

      <?php echo isset($_POST['title']); ?>

      and the same for the other fields you want to re-display.

        your edit part is not working because you dont have a value being passed as $_POST when the edit button is clicked because the values are not in any form.

        Try this code:

        <!-- This file creates new publications --> 
        
        <?php 
        //include("../include/connect.inc.php"); 
        
        
        
        ?> 
        
        <html> 
            <head> 
        
        <title>Seagrant</title> 
        
        </head> 
        
        <body> 
        
        <!-- All data is checked for accuracy before saving it in this section --> 
        <?php 
        if($_POST["submit"]) 
        { 
        
            isset( $_POST['title'] )?$title = $_POST['title']: $title=""; 
        	isset( $_POST['auther'] )?$auther = $_POST['auther']: $auther=""; 
        	isset( $_POST['description'] )?$description = $_POST['description']: $description=""; 
            isset( $_POST['publication'] )?$publication = $_POST['publication']: $publication=""; 
        	isset( $_POST['date'] )?$date = $_POST['date']: $date=""; 
        	isset( $_POST['abstract'] )?$abstract = $_POST['abstract']: $abstract=""; 
        	isset( $_POST['keywords'] )?$keywords = $_POST['keywords']: $keywords=""; 
        	isset( $_POST['affiliation'] )?$affiliation = $_POST['affiliation']: $affiliation=""; 
        
        
        	echo "<form action=\"\" method=\"POST\">";
        
        	echo "<p><b>Title</b>: " . $title . "</p>"; 
        	echo '<input type="hidden"  name ="title" value="'. $title .'">';
        
            echo "<p><b>Auther</b>: " . $auther . "</p>"; 
        	echo '<input type="hidden"  name ="auther" value="'.$auther .'">';
        
            echo "<b>Description</b>: " . $description . "</p>"; 
        	echo '<input type="hidden"  name ="description" value="'. $description .'">';
        
        
            echo "<p><b>Publication</b>: " . $publication . "</p>"; 
        	echo '<input type="hidden"  name ="publication" value="'. $publication .'">';
        
        
            echo "<p><b>Date</b>: " . $date . "</p>"; 
        	echo '<input type="hidden"  name ="date" value="'. $date .'">';
        
        
            echo "<p><b>Abstract</b>: " . $abstract . "</p>"; 
        	echo '<input type="hidden"  name ="abstract" value="'. $abstract .'">';
        
        
            echo "<p><b>keywords</b>: " . $keywords . "</p>"; 
        	echo '<input type="hidden"  name ="keywords" value="'. $keywords .'">';
        
        
            echo "<p><b>affiliation</b>: " . $affiliation . "</p>"; 
        	echo '<input type="hidden"  name ="affiliation" value="'. $affiliation .'">';
        
            ?> 
        
                <p><input type="Submit" value="Edit" /></p> 
                <p><input type="button" onClick ="window.location='checkedit.php?status=save'" value="Save" /></p> 
        
            </form> 
            <?php 
        
        
        }elseif($_GET["status"] == "save"){ 
        
            mysql_query('" . $title . "', '" . $auther . "', '" . $publication . "', '" . $date . "',    '" . $abstract . "', 
                    '" . $keywords . "', '" . $affiliation . "'); 
        
                    echo "Have added the publication to the database.";                 
        }else{ 
        
            ?> 
        
        
        
         <!--- All data for the publication is entered in this section ---> 
        
        <form action ="" method = "POST"> 
            <p>Title: <input type="text" name ="title" value="<?php echo $_POST['title']; ?>" /></p> 
        
        	<p>Auther: <input type="text" name="auther" value="<?php echo $_POST['auther']; ?>"/></p> 
        
        
            Description: 
            <p><textarea name="description" cols ="50" rows="10" value="<?php echo $_POST['description']; ?>"></textarea></p> 
        
            <p>Publication: <input type="text" name="publication" value="<?php echo $_POST['publication']; ?>"/></p> 
        
            <p>Date(MM/DD/YYYY): <input type="text" name="date" value="<?php echo $_POST['date']; ?>"/></p> 
        
            <p>Abstract: <input type="text" name="abstract" value="<?php echo $_POST['abstract']; ?>"/></p> 
        
            <p>Keywords: <input type="text" name="keywords" value="<?php echo $_POST['keywords']; ?>"/></p> 
        
            <p>Affiliation: <input type="text" name="affiliation" value="<?php echo $_POST['affiliation']; ?>"/></p> 
        
            <p><input type="submit" name="submit" value="Submit" /></p> 
        
        </form> 
        
        <?php 
        } 
        ?> 
        </body> 
        </html> 
        
        

          But by doing that you get this for every input box

                  <p>Title: <input type="text" name ="title" value="<br />
          <b>Notice</b>:  Undefined index:  title in <b>C:\www\dev\PHPDocument2.php</b> on line <b>89</b><br />
          " /></p>

            In the above code posted by msk, you need to make one minor change. The ternary operator should be:

            $title = isset( $_POST['title'] )?$_POST['title']:"";
                    $auther = isset( $_POST['auther'] )?$_POST['auther']:"";
                    $description = isset( $_POST['description'] )?$_POST['description']:"";
                    $publication = isset( $_POST['publication'] )?$_POST['publication']:"";
                    $date = isset( $_POST['date'] )?$_POST['date']:"";
                    $abstract = isset( $_POST['abstract'] )?$_POST['abstract']:"";
                    $keywords = isset( $_POST['keywords'] )?$_POST['keywords']:"";
                    $affiliation = isset( $_POST['affiliation'] )?$_POST['affiliation']:"";

            ~Brett

              rince thanks for pointing the error and bpat thanks for correcting me.

              I tried the same thing on my server and i didnt get the error, might be something to do with my error_reporting.

              On more thing, how about using the set of ternary statements ( i.e bpat ternary statement) in the submit section, would that put the erorr off.

                What are the errors. You allude to them, but never elaborate as to what they are. Let us help you, post the errors (and any corresponding code).

                ~Brett

                  As i posted, i dont have any errors but rince got some errors in my code. I was just trying to clear them off.

                    If your error repoting is set to E_ALL, which it should be during developement then the errors I reported will show up, as they are in the form portion of the code they need to be either set or checked to see if they are set, hence my use of isset() in the form variable echoes.

                      Thank you very much rince, i now changed it to E_ALL.

                        can you exaplain what this line does thats different from what i had?

                        $title = isset( $POST['title'] )?$POST['title']:"";

                        what does the isset do?

                        cant i just have for example

                        $title = $_POST["title"];

                        <input type="hidden" name ="title" value="'<?php echo $title; ?>">';

                        and also this works fine but i only used isset on the first 2 and not the others yet they all worked

                        <!-- This file creates new publications -->
                        
                        <?php
                        //include("../include/connect.inc.php");
                        
                        
                        
                        ?>
                        
                        <html>
                        	<head>
                        
                        <title>Seagrant</title>
                        
                        </head>
                        
                        <body>
                        
                        <!-- All data is checked for accuracy before saving it in this section -->
                        <?php
                        if($_POST["submit"])
                        { 
                        
                        	$title = isset($_POST['title'])?$_POST['title']:"";
                        	$auther = isset($_POST['auther'])?$_POST['auther']:"";
                        	$description = $_POST['description'];
                        	$publication = $_POST['publication'];
                        	$date = $_POST['date'];
                        	$abstract = $_POST['abstract'];
                        	$keywords = $_POST['keywords'];
                        	$affiliation = $_POST['affiliation'];
                        
                        	echo "<p><b>Title</b>: " . $title . "</p>";
                        	echo "<p><b>Auther</b>: " . $auther . "</p>";
                        	echo "<b>Description</b>: " . $description . "</p>";
                        	echo "<p><b>Publication</b>: " . $publication . "</p>";
                        	echo "<p><b>Date</b>: " . $date . "</p>";
                        	echo "<p><b>Abstract</b>: " . $abstract . "</p>";
                        	echo "<p><b>keywords</b>: " . $keywords . "</p>";
                        	echo "<p><b>affiliation</b>: " . $affiliation . "</p>";
                        
                        	?>
                        	<form action="" method="POST">
                        
                        
                        			<p><input type="hidden" name ="title" value="<?php echo $title; ?>" /></p>
                        			<p><input type="hidden" name="auther" value="<?php echo $auther; ?>" /></p>
                        			<p><input type="hidden" name="description" value="<?php echo $description; ?>" /></p>
                        			<p><input type="hidden" name="publication" value="<?php echo $publication; ?>" /></p>
                        			<p><input type="hidden" name="date" value="<?php echo $date; ?>" /></p>
                        			<p><input type="hidden" name="abstract" value="<?php echo $abstract; ?>" /></p>
                        			<p><input type="hidden" name="keywords" value="<?php echo $keywords; ?>" /></p>
                        			<p><input type="hidden" name="affiliation" value="<?php echo $affiliation; ?>" /></p>
                        
                        		<p><input type="submit" value="Edit" /></p>
                        		<p><input type="button" onClick ="window.location='publications.php?status=save'" value="Save" /></p>
                        
                        	</form>
                        	<?php
                        
                        
                        }elseif($_GET["status"] == "save"){
                        
                        	mysql_query('" . $title . "', '" . $auther . "', '" . $publication . "', '" . $date . "',	'" . $abstract . "',
                        			'" . $keywords . "', '" . $affiliation . "');
                        
                        			echo "Have added the publication to the database.";				
                        }else{
                        
                        	?>
                        
                        
                        
                         <!--- All data for the publication is entered in this section --->
                        
                        <form action ="" method = "POST">
                        	<p>Title: <input type="text" name ="title" value="<?php echo $_POST['title']; ?>" /></p>
                        	<p>Auther: <input type="text" name="auther" value="<?php echo $_POST['auther']; ?>" /></p>
                        	Description: 
                        	<p><textarea name="description" cols ="50" rows="10" value="<?php echo $_POST['description']; ?>" ></textarea></p>
                        	<p>Publication: <input type="text" name="publication" value="<?php echo $_POST['publication']; ?>"  /></p>
                        	<p>Date(MM/DD/YYYY): <input type="text" name="date" value="<?php echo $_POST['date']; ?>" /></p>
                        	<p>Abstract: <input type="text" name="abstract" value="<?php echo $_POST['abstract']; ?>" /></p>
                        	<p>Keywords: <input type="text" name="keywords" value="<?php echo $_POST['keywords']; ?>" /></p>
                        	<p>Affiliation: <input type="text" name="affiliation" value="<?php echo $_POST['affiliation']; ?>" /></p>
                        	<p><input type="submit" name="submit" value="Submit" /></p>
                        </form>
                        
                        <?php
                        }
                        ?>
                        </body>
                        </html>

                        😕

                          This:

                          $title = isset( $_POST['title'] )?$_POST['title']:"";

                          Is the ternary syntax. It is a condensed If()else{} statement. It is read something like so:
                          $var = IF/bVALUE IF TRUE:VALUE IF FALSE

                          So, your line just sets the $title to $_POST['title']. Well, if there is no posted title, then it would throw an error and $title could be NULL. The above code solves that by setting title to an empty string.

                          Same thing for the rest. If you don't include them, there's the possibility to have an error muck-up your display. By using the ternary operator, you circumvent it.

                          ~Brett

                            Write a Reply...