ROCKINDANO Posted August 17, 2009 Share Posted August 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/ Share on other sites More sharing options...
ignace Posted August 17, 2009 Share Posted August 17, 2009 if(!($db = @ mysql_connect('localhost', username', 'pass'))) should be: if(!($db = @ mysql_connect('localhost', 'username', 'pass'))) What is the problem you are encountering? Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900356 Share on other sites More sharing options...
ROCKINDANO Posted August 17, 2009 Author Share Posted August 17, 2009 yes thats right that was a typo on putting th code in this forum. but other than that. when i click on edit and edit a posting's content and click update, it erases all the content. any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900358 Share on other sites More sharing options...
ROCKINDANO Posted August 17, 2009 Author Share Posted August 17, 2009 for some reason its not passing the records of the table other than the job_id record. can someone help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900370 Share on other sites More sharing options...
onthespot Posted August 17, 2009 Share Posted August 17, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900373 Share on other sites More sharing options...
ignace Posted August 17, 2009 Share Posted August 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900375 Share on other sites More sharing options...
ROCKINDANO Posted August 17, 2009 Author Share Posted August 17, 2009 right ignace. i just can't figure this one out. Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900377 Share on other sites More sharing options...
onthespot Posted August 17, 2009 Share Posted August 17, 2009 Ok see I told you i was probably wrong! Thought I would at least give it a go. Good luck mate Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900383 Share on other sites More sharing options...
ROCKINDANO Posted August 17, 2009 Author Share Posted August 17, 2009 Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900413 Share on other sites More sharing options...
ROCKINDANO Posted August 18, 2009 Author Share Posted August 18, 2009 I need help with this problem. i have been going at it for the past two days and can't seem to figure it out. can someone help me please. Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-900964 Share on other sites More sharing options...
ROCKINDANO Posted August 18, 2009 Author Share Posted August 18, 2009 WELL GUESS NO HELP. THANKS ANY WAYS Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-901029 Share on other sites More sharing options...
Aeolus Posted August 18, 2009 Share Posted August 18, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-901040 Share on other sites More sharing options...
ROCKINDANO Posted August 20, 2009 Author Share Posted August 20, 2009 they don't echo, i am guessing its the form. for some reason when clicking edit it clears out the fields. Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-902737 Share on other sites More sharing options...
mikesta707 Posted August 20, 2009 Share Posted August 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/170711-updating-a-table/#findComment-902745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.