sticks464 Posted September 9, 2009 Share Posted September 9, 2009 I have been working on this form script which will enable a user to edit database entries and I'm not having much luck. Being new to php it is a little daunting and am surprised I have this much done. A little help would be very much appreciated. By the way this is my first post and I am extremely glad I found this forum. <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("job_listing", $con); $sql = "SELECT * FROM jobs"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table class="listing"> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <?php while($row=mysql_fetch_array($result)){ ?> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' value="<? echo . $row['JobNumber'] . ; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' value="<? echo $row['JobTitle'] . ; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]'value="<? echo . $row['JobCompany'] . ; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]'value="<? echo . $row['JobLocation'] . ; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><input type='textarea' name='JobDescription[]' > <? echo . $row['JobDescription'] . ; ?> </textarea> </td> </tr> <tr> <td> </td> <td> </td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </form> </table> <?php if(isset($_POST['Submit'])){ for($i=0;$i<$count;$i++){ $JobTitle[$i] = mysql_real_escape_string($JobTitle[$i]); $JobCompany[$i] = mysql_real_escape_string($JobCompany[$i]); $JobLocation[$i]= mysql_real_escape_string($JobLocation[$i]); $JobDescription[$i] = mysql_real_escape_string($JobDescription[$i]); $JobNumber[$i] = mysql_real_escape_string($JobNumber[$i]); $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription['$i']."' WHERE JobNumber=".$JobNumber[$i]; $result1=mysql_query($sql1); } } if($result1){ echo 'all done'; } ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/ Share on other sites More sharing options...
SilveR316 Posted September 9, 2009 Share Posted September 9, 2009 Looks like you have short tags turned off in your php configuration. Try using regular <?php tags instead of <? tags in the text fields. Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915619 Share on other sites More sharing options...
bossman Posted September 9, 2009 Share Posted September 9, 2009 i dont think that is the problem....here is what i used.... first you have to make sure you are pulling in your rows before you even try to echo them, by creating a variable for each row, for example $variable1 = $row['row1']; $variable2 = $row['row2']; $variable3 = $row['row3']; then you would pull them into your form, based off of your id field, which im assuming you have. <input type="text" name="variable1" value="<? echo "$variable1" ?>"/> <input type="text" name="variable2" value="<? echo "$variable2" ?>"/> <input type="text" name="variable3" value="<? echo "$variable3" ?>"/> and then proceed to run the UPDATE query, make sense? Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915626 Share on other sites More sharing options...
sticks464 Posted September 9, 2009 Author Share Posted September 9, 2009 That gets all but the job description entries to show up and editing will not submit to the database. <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("job_listing", $con); $sql = "SELECT * FROM jobs"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table class="listing"> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <?php while($row=mysql_fetch_array($result)){ ?> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' size="20" maxlength="250" value="<?php echo $row['JobNumber']; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' size="100" maxlength="250" value="<?php echo $row['JobTitle']; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]' size="100" maxlength="250" value="<?php echo $row['JobCompany']; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]' size="100" maxlength="250" value="<?php echo $row['JobLocation']; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><textarea input type='text' name='JobDescription[]' rows="10" cols="61" value="<?php echo $row['JobDescription']; ?>" </textarea> </td> </tr> <tr> <td> </td> <td> </td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </form> </table> <?php if(isset($_POST['Submit'])){ for($i=0;$i<$count;$i++){ $JobTitle[$i] = mysql_real_escape_string($JobTitle[$i]); $JobCompany[$i] = mysql_real_escape_string($JobCompany[$i]); $JobLocation[$i]= mysql_real_escape_string($JobLocation[$i]); $JobDescription[$i] = mysql_real_escape_string($JobDescription[$i]); $JobNumber[$i] = mysql_real_escape_string($JobNumber[$i]); $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription['$i']."' WHERE JobNumber=".$JobNumber[$i]; $result1=mysql_query($sql1); } } if($result1){ echo 'all done'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915648 Share on other sites More sharing options...
bossman Posted September 9, 2009 Share Posted September 9, 2009 is there some sort of 'edit' button that takes you to this page?? if so , you have to pass the 'edit_id' so it knows which id and rows associated with it need to be edited....it would be something like this.... <a href='edit_entries.php?edit_id=$id'>[<strong>Edit</strong>]</a> then, on the edit page.... $query = mysql_query('SELECT * FROM `yourdatabase` WHERE `id`='.$_GET['edit_id']); that will get the 'edit_id' from the previous page so it knows which row you are trying to edit.... THEN....you call in the rows as i did in the last post and proceed with the UPDATE query. Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915666 Share on other sites More sharing options...
sticks464 Posted September 9, 2009 Author Share Posted September 9, 2009 I'm not sure I follow you completely. What I have is a page called admin.php. This page contains only a menu with links to a form used to submit entries into the db (with a backend page that connects to the db and actually submits the form data), a link to a form to delete entries from the db (no backend) and a link to the page I am trying to create (the code I posted less html and css). Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915683 Share on other sites More sharing options...
DavidAM Posted September 9, 2009 Share Posted September 9, 2009 This is not the correct way to write a TEXTAREA <textarea input type='text' name='JobDescription[]' rows="10" cols="61" value="<?php echo $row['JobDescription']; ?>" </textarea> I never liked that it is different, and I mess it up every time, too: <textarea name='JobDescription[]' rows="10" cols="61"><?php echo $row['JobDescription']; ?></textarea> It is NOT an INPUT tag (removed that stuff), it has NO value attribute, instead the "value" goes between the openning and closing tags. So much for consistent standards. Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915705 Share on other sites More sharing options...
sticks464 Posted September 9, 2009 Author Share Posted September 9, 2009 Ok, I already figured that one out. Still won't submit changes. <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("job_listing", $con); $sql = "SELECT * FROM jobs"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table class="listing"> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <?php while($row=mysql_fetch_array($result)){ ?> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' size="20" maxlength="250" value="<?php echo $row['JobNumber']; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' size="100" maxlength="250" value="<?php echo $row['JobTitle']; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]' size="100" maxlength="250" value="<?php echo $row['JobCompany']; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]' size="100" maxlength="250" value="<?php echo $row['JobLocation']; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><textarea name='JobDescription[]' rows="10" cols="61"><?php echo $row['JobDescription']; ?> </textarea> </td> </tr> <tr> <td> </td> <td> </td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </form> </table> <?php if(isset($_POST['Submit'])){ for($i=0;$i<$count;$i++){ $JobTitle[$i] = mysql_real_escape_string($JobTitle[$i]); $JobCompany[$i] = mysql_real_escape_string($JobCompany[$i]); $JobLocation[$i]= mysql_real_escape_string($JobLocation[$i]); $JobDescription[$i] = mysql_real_escape_string($JobDescription[$i]); $JobNumber[$i] = mysql_real_escape_string($JobNumber[$i]); $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription[$i]."' WHERE JobNumber=".$JobNumber[$i]; $result1=mysql_query($sql1); } } if($result1){ echo 'all done'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915712 Share on other sites More sharing options...
gevensen Posted September 9, 2009 Share Posted September 9, 2009 error: <? echo . $row['JobNumber'] . ; ?> instead use <?php echo $row['JobNumber'] ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915715 Share on other sites More sharing options...
gevensen Posted September 9, 2009 Share Posted September 9, 2009 also if your having trouble with inserts or updates try doing a manual one from phpmyadmin and then changing the data, the format will be there Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915718 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 add this line after you execute the query: $result1=mysql_query($sql1); // after this line add if (! $result1) echo mysql_error(); see if we can find out why Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915838 Share on other sites More sharing options...
sticks464 Posted September 10, 2009 Author Share Posted September 10, 2009 This is the error I get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Is this line 1 for the error $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); or another line 1? And this is the code shown by phpmysqladmin UPDATE `job_listing`.`jobs` SET `JobDescription` = 'A different test.' WHERE `jobs`.`ID` =5 LIMIT 1 ; and that should correspond to this line $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription[$i]."' WHERE JobNumber=".$JobNumber[$i]; Which makes me believe this part of the code is incorrect WHERE JobNumber=".$JobNumber[$i]; Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915842 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 mysql_error says line 1 because it is line 1 of the sql you sent (not line 1 of the php code). It is usually line 1. Try echoing the sql just before you send it to the server, then look for the " (double quote) or is it '' (two single quotes) somewhere where it doesn't belong. $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription[$i]."' WHERE JobNumber=".$JobNumber[$i]; echo '<PRE>' . $sql1 . '</PRE>'; $result1=mysql_query($sql1); (I use PRE so it is easier to read in the page.) Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915853 Share on other sites More sharing options...
sticks464 Posted September 10, 2009 Author Share Posted September 10, 2009 I absolutely do not see any errors. It gives me two lines of formated code, shouldn't it only give one? UPDATE jobs SET JobTitle='', JobCompany='', JobLocation='', JobDescription='' WHERE JobNumber= UPDATE jobs SET JobTitle='', JobCompany='', JobLocation='', JobDescription='' WHERE JobNumber= $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription[$i]."' WHERE JobNumber=".$JobNumber[$i]; echo '<PRE>' . $sql1 . '</PRE>'; $result1=mysql_query($sql1); Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-915862 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 Well, you are inside a loop, so there would be one SQL statement for each pass through the loop. The error is at the end of the statement: WHERE JobNumber= equals what? In fact there are no values supplied to the statement at all. So, now I see what I missed before: $JobTitle[$i] = mysql_real_escape_string($JobTitle[$i]); $JobCompany[$i] = mysql_real_escape_string($JobCompany[$i]); $JobLocation[$i]= mysql_real_escape_string($JobLocation[$i]); $JobDescription[$i] = mysql_real_escape_string($JobDescription[$i]); $JobNumber[$i] = mysql_real_escape_string($JobNumber[$i]); $JobTitle (and the others) have not been defined. At least, they are not defined in the code you provided earlier. If you are looking for the POSTed values it should be: $JobTitle[$i] = mysql_real_escape_string($_POST['JobTitle'][$i]); Let me point out one other problem which might cause you confusion later. You are populating the table with data from the database, and allowing the user to change it. Then when they make changes and Submit, you are populating the table from the database, THEN updating the database with the posted changes. The data you see on the page is the data from the database BEFORE it was updated. So, you're going to think it did not update. I know it feels counter-intuitive, but you probably want to put the database update code up BEFORE you select for display. Watch out, because you will not have the $count for your loop. For example (this is just a quick swing from your original code, but you get the idea) <?php // connect to database $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("job_listing", $con); // If user POSTed an update if(isset($_POST['Submit'])){ $count = count($_POST['JobNumber']); $done = 0; for($i=0;$i<$count;$i++){ $JobTitle[$i] = mysql_real_escape_string($_POST['JobTitle'][$i]); $JobCompany[$i] = mysql_real_escape_string($JobCompany[$i]); $JobLocation[$i]= mysql_real_escape_string($JobLocation[$i]); $JobDescription[$i] = mysql_real_escape_string($JobDescription[$i]); $JobNumber[$i] = mysql_real_escape_string($JobNumber[$i]); $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription['$i']."' WHERE JobNumber=".$JobNumber[$i]; $result1=mysql_query($sql1); if ($result1) $done++; } echo $done . ' updates succeeded (out of ' . $count . ' attempted.'); } /* NOTE: $result1 will NOT be defined if there are no updates. Also, $result1 will be TRUE or FALSE based on the results of the LAST call. */ //if($result1){ // echo 'all done'; //} // Show the current data $sql = "SELECT * FROM jobs"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table class="listing"> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <?php while($row=mysql_fetch_array($result)){ ?> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' value="<? echo . $row['JobNumber'] . ; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' value="<? echo $row['JobTitle'] . ; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]'value="<? echo . $row['JobCompany'] . ; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]'value="<? echo . $row['JobLocation'] . ; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><input type='textarea' name='JobDescription[]' > <? echo . $row['JobDescription'] . ; ?> </textarea> </td> </tr> <tr> <td> </td> <td> </td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </form> </table> Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916036 Share on other sites More sharing options...
sticks464 Posted September 10, 2009 Author Share Posted September 10, 2009 Adding post works, and your correct, it does not reflect the change on the submit form but does so on the output page. I tried your code and get Parse error: syntax error, unexpected ')', expecting ',' or ';' on line 75 which in my editor is a } Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916073 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 Well, I just whipped that out real quick, but I see a closing parenthesis out of place. This: echo $done . ' updates succeeded (out of ' . $count . ' attempted.'); should actually be this: echo $done . ' updates succeeded (out of ' . $count . ' attempted.)'; Also be sure to use the $_POST on all of those lines inside the loop, I only did the first one in the sample code I sent. Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916122 Share on other sites More sharing options...
sticks464 Posted September 10, 2009 Author Share Posted September 10, 2009 Your code works with some changes to get it to display the db contents, however if one word is deleted from any of the job descriptions, ALL job descriptions are completely deleted on submission. Changed value="<? echo . $row['JobNumber'] . ; ?> "> to this value="<?php echo $row['JobNumber']; ?> "> <?php // connect to database $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("job_listing", $con); // If user POSTed an update if(isset($_POST['Submit'])){ $count = count($_POST['JobNumber']); $done = 0; for($i=0;$i<$count;$i++){ $JobTitle[$i] = mysql_real_escape_string($_POST['JobTitle'][$i]); $JobCompany[$i] = mysql_real_escape_string($_POST['JobCompany'][$i]); $JobLocation[$i]= mysql_real_escape_string($_POST['JobLocation'][$i]); $JobDescription[$i] = mysql_real_escape_string($_POST['JobDescription'][$i]); $JobNumber[$i] = mysql_real_escape_string($_POST['JobNumber'][$i]); $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription['$i']."' WHERE JobNumber=".$JobNumber[$i]; $result1=mysql_query($sql1); if ($result1) $done++; } echo $done . ' updates succeeded (out of ' . $count . ' attempted.)'; } /* NOTE: $result1 will NOT be defined if there are no updates. Also, $result1 will be TRUE or FALSE based on the results of the LAST call. */ //if($result1){ // echo 'all done'; //} // Show the current data $sql = "SELECT * FROM jobs"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table class="listing"> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <?php while($row=mysql_fetch_array($result)){ ?> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' size="20" maxlength="250" value="<?php echo $row['JobNumber']; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' size="100" maxlength="250" value="<?php echo $row['JobTitle']; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]' size="100" maxlength="250" value="<?php echo $row['JobCompany']; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]' size="100" maxlength="250" value="<?php echo $row['JobLocation']; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><textarea name='JobDescription[]' rows="10" cols="61"><?php echo $row['JobDescription']; ?> </textarea> </td> </tr> <tr> <td> </td> <td> </td> </tr> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916140 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 Hmm. let's see what is getting posted. Back up near the top let's add a couple of lines. Find if(isset($_POST['Submit'])){ and add this after it: print '<PRE>'; print_r($_POST); exit(); This will display the contents of the POST array and then exit (no sense messing with the data until we figure it out). You can leave the rest of the code as is. Post the results so we can see what the problem is. Make sure you xxxx-out any sensitive information (if necessary). Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916196 Share on other sites More sharing options...
sticks464 Posted September 10, 2009 Author Share Posted September 10, 2009 I made spelling corrections which are displayed in the result Array ( [JobNumber] => Array ( [0] => 00145 [1] => 00146 ) [JobTitle] => Array ( [0] => Claims Examiner [1] => Sales Producer ) [JobCompany] => Array ( [0] => xxx [1] => xxx ) [JobLocation] => Array ( [0] => xxx [1] => xxx ) [JobDescription] => Array ( [0] => We are seeking a senior workers compensation claims examiner for an excellent insurance organization. The ideal candidate will have five (5) plus years experience handling claims. The caseload is very reasonable. We encourage qualified candidates to submit their resume to us. [1] => A growing prominent insurance organization is seeking a commercial lines property and casualty sales producer for a niche market for a xxx xxx territory. We are looking for an aggressive and self confident individual with prior P&C sales experience and a proven track record. In return you will be offered an opportunity to make excellent compensation. Excellent benefits package. ) [submit] => Submit ) Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916215 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 Looks like we got all of the data back, and in the expected elements of the array. I don't see why it would be updating incorrectly. It must be something small that we're just not seeing. Take those three lines back out and maybe echo the SQL instead of sending it to the server to see what we are telling it to do. Wait, there it is. Something small, easy to miss: $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]. "', JobCompany='".$JobCompany[$i]. "', JobLocation='".$JobLocation[$i]. "', JobDescription='".$JobDescription['$i']. "' WHERE JobNumber=".$JobNumber[$i]; Look at the subscript on JobDescription, you've put quotes around it (the $i). I bet that is messing up the SQL statement. (I just added the line breaks so you can see it a little easier.) Remove those single quotes and give it a whirl. Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916259 Share on other sites More sharing options...
sticks464 Posted September 10, 2009 Author Share Posted September 10, 2009 Excellent!! I applaud your diligence and thank you for sticking with this thread. I appreciate it very much. One final question, how do I put a submit button on each form instead of only one button for all entries? Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916276 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 Glad to help. It's actually kind of fun. Do you want to make each Job Entry a separate form, so clicking Submit will only send 1 job to update? You could move the form openning and closing tags inside the loop: <?php while($row=mysql_fetch_array($result)){ ?> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' value="<? echo . $row['JobNumber'] . ; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' value="<? echo $row['JobTitle'] . ; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]'value="<? echo . $row['JobCompany'] . ; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]'value="<? echo . $row['JobLocation'] . ; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><input type='textarea' name='JobDescription[]' > <? echo . $row['JobDescription'] . ; ?> </textarea> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </form> <?php } ?> I guess you could do it that way. This might confuse the user. You might want to add some kind of visual separator between entries to help clarify the fact that they are individual forms. I am NOT 100% sure that all browsers will treat that (forms inside a table) correctly or that it is even "legal" by the specs. But I have put multiple forms inside a table before, I just have not tested it in multiple browsers. Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916403 Share on other sites More sharing options...
sticks464 Posted September 10, 2009 Author Share Posted September 10, 2009 Actually I moved the table inside the loop which with the present styling give 40px of separation between tables. Thank you once again, I have learned a lot. <?php while($row=mysql_fetch_array($result)){ ?> <table class="listing"> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' size="20" maxlength="250" value="<?php echo $row['JobNumber']; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' size="100" maxlength="250" value="<?php echo $row['JobTitle']; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]' size="100" maxlength="250" value="<?php echo $row['JobCompany']; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]' size="100" maxlength="250" value="<?php echo $row['JobLocation']; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><textarea name='JobDescription[]' rows="10" cols="61"><?php echo $row['JobDescription']; ?> </textarea> </td> </tr> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </form> </table> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173697-solved-edit-database-entries/#findComment-916414 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.