Jump to content

Update form


phily245

Recommended Posts

I have a form which updates data in a database about vacancies at my client's business. Everything in the form updates fine and the form passes the validation, however, the Job details field (post_desc) passes the validation that it is not empty but will not update the database. Here is the code for the form:

<?php
      
    	Please select the Vacancy you want to amend by left clicking, then enter all the information needed below, then left click the "Amend Vacancy" button to amend the Vacancy in the database.<br/><br/><br/><br/>
    
        <?php 

	if(isset($_SESSION["report"]) && $_SESSION["report"] != ""){ 

		print '<span class="report">' . $_SESSION["report"] . '<br/></span>'; 

		if($_SESSION["reportcount"] == 1){

			unset($_SESSION["report"]);
			unset($_SESSION["reportcount"]);  

		}

		$_SESSION["reportcount"] ++;

	}

	?>
        
        	<?php if(!isset($_GET["id"])) { ?>
        
        <?php

	$query = mysql_query("SELECT * FROM sits_vacant WHERE 1 ORDER BY post_title ASC") or die (mysql_error());

	$count = mysql_num_rows($query);

	if($count == 0){

		echo '<a title="No Vacancies to display." target="_self" class="button buttonfull" >No Vacancies to display.</a>';

	}

	while($fetch = mysql_fetch_array($query)){

		echo '<a href="amend_vacancy.php?id=' . $fetch["post_id"] . '" title="Amend ' . stripslashes($fetch["post_title"]) . '" target="_self" class="button buttonfull" >' . stripslashes($fetch["post_title"]) . '</a>';

	}

	echo '<br/><br/><br/>
		<div class="content_menu"></div>';

	?>
        
        <?php }else{ ?>
        
        	<?php $query = mysql_query("SELECT * FROM sits_vacant WHERE post_id = '" . $_GET["id"] . "' LIMIT 1") or die (mysql_error()); ?>
       		 <?php $fetch = mysql_fetch_array($query); ?>
        <form id="amend_form" name="amend_form" method="post" class="main_form" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]."?id=".$_GET["id"]; ?>">				

                <label for="name">Vacancy Title
                  <input name="title" type="text" class="text" id="title" title="Vacancy Title" maxlength="60"				
			<?php if(isset($_POST["title"])){ echo 'value="' . $_POST["title"] . '"'; }else{ echo 'value="' . stripslashes($fetch["post_title"]) . '"'; } ?> 
			>				
          </label>
                    
<br/>
                
          <label for="post_desc">Vacancy Description
                
               <textarea name="post_desc" id="post_desc" title="Job Description" class="textarea" cols="12" rows="3" wrap="virtual" <?php if(isset($_POST["post_desc"])){ echo 'value="' . $_POST["post_desc"] . '"'; }else{ echo 'value="' . stripslashes($fetch["post_desc"]) . '"'; } ?>></textarea>
                
                <br/>
                
               <label for="salary">Salary (dd-mm-yyyy)
                  <input name="salary" type="text" class="text" id="salary" title="Salary" maxlength="60"				
			<?php if(isset($_POST["salary"])){ echo 'value="' . $_POST["salary"] . '"'; }else{ echo 'value="' . stripslashes($fetch["post_salary"]) . '"'; } ?> 
			>				
          </label>
                    
<br/>

<label for="closing">Vacancy Closing Date
                  <input name="closing" type="text" class="text" id="closing" title="Vacancy |Closing Date" maxlength="60"				
			<?php if(isset($_POST["closing"])){ echo 'value="' . $_POST["closing"] . '"'; }else{ echo 'value="' . stripslashes($fetch["post_closing"]) . '"'; } ?> 
			>				
          </label>
                    
<br/>                                 

                
                
              <input name="submit" id="submit" value="Amend Vacancy" type="submit" class="buttonfull" onclick=""javascript: document.amend_form.submit();"">
		</form>
		<br/><br/>
            <div class="content_menu"></div>
            <a href="amend_vacancy.php" title="Back" target="_self" class="button buttonfull">Back</a>
		<br/>
		<div class="content_menu"></div>
            
            <?php } ?>
?>

 

And here is the code to validate and update the database:

<?php
<?php session_start(); ?>
<?php require_once("includes/db_connector.php"); ?>
<?php include("includes/login_class.php"); ?>
<?php include("includes/php_functions.php"); ?>
<?php 

$login = new loginClass();
$login->encrypt = true;

if(!isset($_SESSION['loggedin']) || $login->loginCheck($_SESSION['loggedin']) == false){

session_write_close();
gotoURL("index.php");
exit();

}

if(isset($_GET["success"]) && $_GET["success"] == 1){

$_SESSION["report"] = "<b>Success:</b> Vacancy has been added to the database.<br/>";
$_SESSION["reportcount"] = 0;

}

if(isset($_POST["title"])){
if($_POST["title"] == ""){	

	$_SESSION["report"] = "<b>Error:</b> Title is empty.<br/>";
	$_SESSION["reportcount"] = 0;

}


if(!isset($_POST["post_desc"]) || $_POST["post_desc"] = ""){	

	$_SESSION["report"] = "<b>Error:</b> Description is empty.<br/>";
	$_SESSION["reportcount"] == 0;

}


if($_POST["salary"] == ""){	

	$_SESSION["report"] = "<b>Error:</b> Salary is empty.<br/>";
	$_SESSION["reportcount"] = 0;

}	

        if($_POST["closing"] == ""){	

	$_SESSION["report"] = "<b>Error:</b> Closing Date is empty.<br/>";
	$_SESSION["reportcount"] = 0;

}

        if (!preg_match ("/\d{2}-\d{2}-\d{4}/", $_POST["closing"]))
        {

                $_SESSION["report"] = "<b>Error:</b> Date is in the wrong format. It must be dd-mm-yyyy<br />";
	$_SESSION["reportcount"] = 0; 

        }


if($_SESSION["report"] == ""){		

	$text = $_POST["post_desc"];
	$text = stripslashes($text);
	$text = stripslashes($text);
	$text = stripslashes($text);
	$text = stripslashes($text);
	$text = stripslashes($text);
	$text = str_replace("‘", "'", $text);
	$text = str_replace("’", "'", $text);
	$text = str_replace("”", '"', $text);
	$text = str_replace("“", '"', $text);
	$text = str_replace("–", "-", $text);
	$text = str_replace("…", "...", $text);
	$text = str_replace("\r", "", $text);
	$text = str_replace("\n", "", $text);
	$text = str_replace("®", "®", $text);
	$text = str_replace("°", "°", $text);
	//$text = strip_tags($text, '<a><font><strong><i><b><u><sup><sub><strike><s><em><ul><ol><li><div><br>');
	$text = nl2br($text);
	$text = mysql_real_escape_string($text);



	mysql_query("UPDATE sits_vacant SET post_title = '" . mysql_real_escape_string($_POST["title"]) . "', post_desc = '" . $text . "', post_salary = '" . mysql_real_escape_string($_POST["salary"]) . "', post_closing = '" . $_POST["closing"] . "' WHERE post_id = '" . $_GET["id"] . "'") or die (mysql_error());

	$_SESSION["report"] = "<b>Success:</b> Vacancy has been added to the database.<br/>";
	$_SESSION["reportcount"] = 0;

	gotoURL("amend_vacancy.php?success=1");
	exit();

}

}

?>
?>

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/246109-update-form/
Share on other sites

this line

if(!isset($_POST["post_desc"]) || $_POST["post_desc"] = ""){

 

should be

 

if(!isset($_POST["post_desc"]) || $_POST["post_desc"] == ""){

 

(two equal signs)

 

* I didn't check the rest, since this was the first bug I found and may solve your problem.

Link to comment
https://forums.phpfreaks.com/topic/246109-update-form/#findComment-1263913
Share on other sites

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.