Jump to content

Recommended Posts

Hello,

 

I am having trouble with this simple problem, but can't figure it out. I have a table that holds some job opening, I am trying to give the user an option to edit a posting and update any of its content. i have 3 pages.

 

the first page just list all jobs and i have a link(edit) to edit the postings.

						print "<td><a href='editjobs.php?job_id=$job_id'>Edit</a></td>";

 

2nd is editjobs.php

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Editing Job openings</title>
<style type="text/css">
<!--
#logo {
border:0px solid #000000;
padding:5px;
border-bottom:2 solid #000066;
}
.form1 {
border:1px solid #CCCCCC; 
padding:5px; 
width:3\00px*/;			/****IE HACK****/ 
margin:50px 0px; 
font-size: 14px;
}
.form1 table {
font-size:14px;
color:#003300
text-align: center;
padding:5px;
}
.form1 input {float:left;}
</style>

</head>
<body>
<?php
	if(!isset($_SESSION["user_id"]) || !isset($_SESSION["ip_addr"]))
		 die("Invalid operation!!!<br />Please login first<br /><a href=\"login.php\">Login</a>");

			$user_id=$_SESSION["user_id"];
		$ip_addr=$_SESSION["ip_addr"];
		if($ip_addr != $_SERVER["REMOTE_ADDR"])
			 die("invalid operation!!!<br /> please login first");

	if(!($db = @ mysql_connect('localhost', username', 'pass')))
	{
		print "Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.";
	}						
		 //select which database you want to edit
		mysql_select_db("compdb"); 

				$query = "SELECT * FROM users WHERE user_id='{$user_id}'";
				$result = mysql_query($query);
				$num_result = mysql_num_rows($result);

				if($num_result == 0)
				die("Invalid operation <br /> Please login first");
				$row = @ mysql_fetch_array($result);
?>
<div class="form1">
<div id="logo"><img src="../images/logo.png" title="" border="0" /></div>
<p>
    <?php
$job_id = $_GET["job_id"];
$department = $_GET["department"];
		$pay = mysql_real_escape_string($_GET["pay"]);
		$jobnum = mysql_real_escape_string($_GET["jobnum"]);
		$dateclose = mysql_real_escape_string($_GET["dateclose"]);
		$summary = mysql_real_escape_string($_GET["summary"]);
		$description = mysql_real_escape_string($_GET["description"]);
		$conditions = mysql_real_escape_string($_GET["conditions"]);
		$ex = mysql_real_escape_string($_GET["ex"]);
		$ed = mysql_real_escape_string($_GET["ed"]);

	$query = "SELECT * FROM fulltime WHERE job_id ='$job_id'";
	$result = mysql_query($query);

		while($r=mysql_fetch_array($result))
		{	
		  //the format is $variable = $r["nameofmysqlcolumn"];
		  //modify these to match your mysql table columns
			$department=$r["department"];
			$pay=$r["pay"];
			$jobnum=$r["jobnum"];
			$closedate=$r["dataclose"];
			$summary=$r["summary"];
			$description=$r["description"];
			$conditions=$r["conditions"];
			$ex=$r["ex"];
			$ed=$r["ed"];
		}//end while loop
?>
      <form method="post" action="updatefulltime.php">

    <table width="80%" border="0" cellspacing="5" cellpadding="0">
  <tr><td colspan="2">Title & Department: <input name="department" type="text" value="<?php print "".$department."";?>"  size="50" maxlength="100" /><?php print "".$department."";?></td></tr>
  <tr><td>Pay Rate: <input name="pay" type="text" value="<?php print "".$pay. "";?>" size="10" maxlength="15"  /></td></tr>
  <tr><td colspan="2">Job #: <input name="jobnum" type="text" value="<?php print"".$jobnum."";?>" size="10" maxlength="10" /></td></tr>
  <tr><td colspan="2">Closing Date: <input name="dateclose" type="text" value="<?php print "".$closedate."";?>" size="15" maxlength="15" /></td></tr>
  <tr><td colspan="2">Job Summary:</td></tr>
  <tr><td colspan="2"><textarea name="summary" cols="100" rows="10"><?php print "".$summary."";?></textarea></td></tr>
  <tr><td colspan="2">Equipment and Materials: </td></tr>
  <tr><td colspan="2"><textarea name="description" cols="100" rows="10"><?php print "".$description."";?></textarea></td></tr>
  <tr><td colspan="2">Conditions:</td></tr>
  <tr><td colspan="2"><textarea name="conditions" cols="100" rows="10"><?php print "".$conditions."";?></textarea></td></tr>
  <tr><td colspan="2">Example of work:</td></tr>
  <tr><td colspan="2"><textarea name="ex" cols="100" rows="10"><?php print "".$ex."";?></textarea></td></tr>
  <tr><td colspan="2">Education:</td></tr>
  <tr><td colspan="2"><textarea name="ed" cols="100" rows="10"><?php print "".$ed."";?></textarea></td></tr>
  <tr><td><?php print "<a href='editupdate.php?job_id=$job_id'>update</a>"; ?></td></tr>
</table>
</form>
</div>
</body>
</html>

 

the other page is editupdate.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Updating job openings</title>
<style type="text/css">
<!--
#logo {
border:0px solid #000000;
padding:5px;
border-bottom:2 solid #000066;
}
.form1 {
border:1px solid #CCCCCC; 
padding:10px; 
width:3\00px*/;			/****IE HACK****/ 
margin:50px 100px; 
font-size: 14px;
}
.form1 table {
font-size:14px;
color:#003300
text-align: center;
padding:10px;
}
.form ul, li, a {list-style:none; color:#0066CC}

.form1 input {float:left;}
-->
</style>

</head>

<body>
<div class="form1">
<div class="logo"><img src="../images/logo.png" title="" border="0" /></div>
		<?php
	if(!($db = @ mysql_connect('localhost', 'username', 'pass')))
	{
		print "Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.";
	}						
		 //select which database you want to edit
		mysql_select_db("compdb"); 
		$job_id = $_GET["job_id"];

		$department = $_GET["$department"];
//			$pay = mysql_real_escape_string($_GET["pay"]);
//			$jobnum = mysql_real_escape_string($_GET["jobnum"]);
//			$dateclose = mysql_real_escape_string($_GET["dateclose"]);
//			$summary = mysql_real_escape_string($_GET["summary"]);
//			$description = mysql_real_escape_string($_GET["description"]);
//			$conditions = mysql_real_escape_string($_GET["conditions"]);
//			$ex = mysql_real_escape_string($_GET["ex"]);
//			$ed = mysql_real_escape_string($_GET["ed"]);


		$query= "UPDATE fulltime SET department = '$department',  pay = '$pay', jobnum = '$jobnum', dataclose = '$dateclose', job_id = '$job_id', summary = '$summary', description = '$description', conditions = '$conditions', ex = '$ex', ed = '$ed' WHERE job_id = '$job_id'";
		$result = mysql_query($query)or die(mysql_error());

		print "" .$department. "<br />";
		print "" .$job_id. "<br />";			
	?>
</div>
</body>
</html>

 

can someone help please

 

thanks a million in advance

Link to comment
https://forums.phpfreaks.com/topic/170711-updating-a-table/
Share on other sites

I could be completely wrong but when you select many values change

 

         while($r=mysql_fetch_array($result))

 

to

 

         while($r=mysql_fetch_assoc($result))

 

That might be the problem?

 

No that just changes the result set from numerical + associative to associative only

Link to comment
https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900375
Share on other sites

I'll play with this, give me a few mins :)

 

>> can you give me a snippet of your mysql table so I can insert that and save myself some time?

 

 

Edit:

 

Actually, do me a favor, try echoing all your values before you insert them into the table. If they don't echo, they aren't defined, and the problem is your form and not your mysql insert...

Link to comment
https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-901040
Share on other sites

well first off, I don't see anywhere where you post the variable, or put the variables in a get variable. The only get variable you pass is the job ID on your editjobs.php page. try making the link into a button, and have the button submit a form that all the text areas are a part of.

Link to comment
https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-902745
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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