steviemac Posted February 19, 2007 Share Posted February 19, 2007 I have a form that selects a certain field and then displays the row. It then echos a form that I want to be able to update a table. This is that code. Everything is working fine on the SELECT query and displaying. I'm still new at this and will be for a long time. Thanks for any help!! ??? <?php error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('track_errors', true); if ($searching =="yes") { echo "<h2>Results</h2><p>"; if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } mysql_connect("localhost", "###", "###") or die(mysql_error()); mysql_select_db("zone5aca_courses") or die(mysql_error()); $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); $data = mysql_query("SELECT * FROM bikepatrol WHERE upper($field) LIKE'%$find%'"); //And we display the results while($result = mysql_fetch_array( $data )) { echo "<form action='update_course.php' name='update' method ='POST' >"; echo "<table width='700' cellspacing'0' cellpadding='0' border='0'><tr>"; echo "<td class='thetag' bgcolor='#DDDDDD'>Update</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>ID</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>Course</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>E-Mail</td></tr>"; echo "<tr><td class='thevalue'><input type=\"radio\" name=\"update\" value=\"$result[id]\" /></td>"; echo "<td class='thevalue'>$result[id]</td>"; echo "<td class='thevalue'>$result[Course]</td>"; echo "<td class='thevalue'>$result[email_address]</td></tr>"; echo "<tr><td colspan=\"4\"><input type=\"submit\" name=\"submit\" value=\"Update Selected\" /></td></tr></table>\n"; echo "</form>\n"; } This is the update_course.php I'm not getting errors but it will not update the table. <?php error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('track_errors', true); //Connect to DB $db = mysql_connect("localhost:/tmp/mysql5.sock", "zone5aca", "15035150"); mysql_select_db("zone5aca_courses"); if(isset ($_POST['update'])) { $result = mysql_query("UPDATE bikepatrol SET id = '{$_POST['id']}', Course='{$_POST['Course']}', email_address = '{$_POST['email_address']}' WHERE id = {$_POST['update']}") or die(mysql_error()); echo "You updated the following course information:"; echo "<br>"; echo "ID Number:".$_POST['update']; echo "<br>"; echo "Course:".$_POST['Course']; echo "<br>"; echo "E-Mail:".$_POST['email_address']; echo "<br>"; } else { echo 'You didnt enter any data'; } ?> Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 I think this: WHERE id = {$_POST['update']}") Needs to be changed to this: WHERE id = '{$_POST['update']}'") Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted February 19, 2007 Share Posted February 19, 2007 I think this: WHERE id = {$_POST['update']}") Needs to be changed to this: WHERE id = '{$_POST['update']}'") perfect. or alternatively: (........ WHERE id = '". $_POST['update'] ."') Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 Better code yet. Quote Link to comment Share on other sites More sharing options...
steviemac Posted February 19, 2007 Author Share Posted February 19, 2007 I think my problem is it is only updating the id portion and nothing else. Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 $id=$_POST['id'] $course=$_POST['Course'] $email_address=$_POST['email_address'] $update=$_POST['update'] $result = mysql_query("UPDATE bikepatrol SET id ='$id', Course='$Course', email_address = '$email_address' WHERE id = '$update' ") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
steviemac Posted February 19, 2007 Author Share Posted February 19, 2007 I'm getting an error Parse error: syntax error, unexpected T_VARIABLE in /home/zone5aca/www/www/register/update_course1.php on line 33 Line 33 $result = mysql_query("UPDATE bikepatrol SET id ='$id', Course='$Course', email_address = '$email_address', Student_1_Name = $Student_1_Name WHERE id = '$update' ") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
steviemac Posted February 19, 2007 Author Share Posted February 19, 2007 I thought I had it. I added the single quotes to the Student_1_Name but I'm still getting the error. Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 19, 2007 Share Posted February 19, 2007 can you post the section where you define the variables i.e. $blah=$_POST['blah'] Quote Link to comment Share on other sites More sharing options...
steviemac Posted February 19, 2007 Author Share Posted February 19, 2007 Here is the whole code, with the changes that were made <?php error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('track_errors', true); //Connect to DB $db = mysql_connect("###############); mysql_select_db("zone5aca_courses"); $id=$_POST['id']; $course=$_POST['Course']; $email_address=$_POST['email_address']; $Student_1_Name=$_POST['Student_1_Name']; $update=$_POST['update'] $result = mysql_query("UPDATE bikepatrol SET id ='$id', Course='$Course', email_address = '$email_address', Student_1_Name = '$Student_1_Name' WHERE id = '$update' ") or die(mysql_error()); echo "You updated the following course information:"; echo "<br>"; echo "ID Number:".$_POST['update']; echo "<br>"; echo "Course:".$_POST['Course']; echo "<br>"; echo "email_address:".$_POST['email_address']; echo "<br>"; echo "Student 1 Name: " .$_POST['Student_1_Name']; echo "<br>"; echo "Student 1 SSN: ".$_POST['SSN_Student_1']; echo "<br>"; echo "Student 1 Status: ".$_POST['Status_Student_1']; echo "<br>"; echo "Student 2 Name: ".$_POST['Student_2_Name']; echo "<br>"; echo "Student 2 SSN: ".$_POST['SSN_Student_2']; echo "<br>"; echo "Student 2 Status: ".$_POST['Status_Student_2']; echo "<br>"; echo "Student 3 Name: ".$_POST['Student_2_Name']; echo "<br>"; echo "Student 3 SSN: ".$_POST['SSN_Student_2']; echo "<br>"; echo "Student 3 Status: ".$_POST['Status_Student_2']; echo "<br>"; } else { echo 'You didnt enter any data'; } ?> Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 20, 2007 Share Posted February 20, 2007 I can't find anywhere where they actually post Student_1_name to the script I checked your form too. IDK maybe I'm missing something. Quote Link to comment Share on other sites More sharing options...
steviemac Posted February 20, 2007 Author Share Posted February 20, 2007 I cut the script back to make it easier to read. This is the actual SELECT script that produces the form $data = mysql_query("SELECT * FROM bikepatrol WHERE upper($field) LIKE'%$find%'"); while($result = mysql_fetch_array( $data )) { echo "<form action='update_course1.php' name='update' method ='POST' >"; echo "<table width='700' cellspacing'0' cellpadding='0' border='0'><tr>"; echo "<td class='thetag' bgcolor='#DDDDDD'>Update</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>ID</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>Course</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>E-Mail</td></tr>"; echo "<tr><td class='thevalue'><input type=\"radio\" name=\"update\" value=\"$result[id]\" /></td>"; echo "<td class='thevalue'>$result[id]</td>"; echo "<td class='thevalue'>$result[Course]</td>"; echo "<td class='thevalue'>$result[email_address]</td></tr>"; echo "<tr><td class='thetag' bgcolor='#DDDDDD'>Student 1 Name</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>SSN Student 1</td>"; echo "<td class='thetag' bgcolor='#DDDDDD' colspan='2'>Status of Student 1</td></tr>"; echo "<tr><td class='thevalue'><input type=\"text\" size=\"30\" name=\"Contact_Person\" value=\"$result[student_1_Name]\" /></td>"; echo "<td class='thevalue'><input type=\"text\" size=\"30\" name=\"Agency\" value=\"$result[sSN_Student_1]\" /></td>"; echo "<td class='thevalue' colspan='2'><input type=\"text\" size=\"30\" name=\"StudentName\" value=\"$result[status_Student_1]\" /></td></tr>"; echo "<tr><td class='thetag' bgcolor='#DDDDDD'>Student 2 Name</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>SSN Student 2</td>"; echo "<td class='thetag' bgcolor='#DDDDDD' colspan='2'>Status of Student 2</td></tr>"; echo "<tr><td class='thevalue'><input type=\"text\" size=\"30\" name=\"Contact_Person\" value=\"$result[student_2_Name]\" /></td>"; echo "<td class='thevalue'><input type=\"text\" size=\"30\" name=\"Agency\" value=\"$result[sSN_Student_2]\" /></td>"; echo "<td class='thevalue' colspan='2'><input type=\"text\" size=\"30\" name=\"StudentName\" value=\"$result[status_Student_2]\" /></td></tr>"; echo "<tr><td class='thetag' bgcolor='#DDDDDD'>Student 3 Name</td>"; echo "<td class='thetag' bgcolor='#DDDDDD'>SSN Student 3</td>"; echo "<td class='thetag' bgcolor='#DDDDDD' colspan='2'>Status of Student 3</td></tr>"; echo "<tr><td class='thevalue'><input type=\"text\" size=\"30\" name=\"Contact_Person\" value=\"$result[student_3_Name]\" /></td>"; echo "<td class='thevalue'><input type=\"text\" size=\"30\" name=\"Agency\" value=\"$result[sSN_Student_3]\" /></td>"; echo "<td class='thevalue' colspan='2'><input type=\"text\" size=\"30\" name=\"StudentName\" value=\"$result[status_Student_3]\" /></td></tr>"; echo "<tr><td colspan=\"4\"><input type=\"submit\" name=\"submit\" value=\"Update Selected\" /></td></tr></table>\n"; echo "</form>\n"; } Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted February 20, 2007 Share Posted February 20, 2007 Here is the whole code, with the changes that were made <?php error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('track_errors', true); //Connect to DB $db = mysql_connect("###############); mysql_select_db("zone5aca_courses"); $id=$_POST['id']; $course=$_POST['Course']; $email_address=$_POST['email_address']; $Student_1_Name=$_POST['Student_1_Name']; $update=$_POST['update'] $result = mysql_query("UPDATE bikepatrol SET id ='$id', Course='$Course', email_address = '$email_address', Student_1_Name = '$Student_1_Name' WHERE id = '$update' ") or die(mysql_error()); echo "You updated the following course information:"; echo "<br>"; echo "ID Number:".$_POST['update']; echo "<br>"; echo "Course:".$_POST['Course']; echo "<br>"; echo "email_address:".$_POST['email_address']; echo "<br>"; echo "Student 1 Name: " .$_POST['Student_1_Name']; echo "<br>"; echo "Student 1 SSN: ".$_POST['SSN_Student_1']; echo "<br>"; echo "Student 1 Status: ".$_POST['Status_Student_1']; echo "<br>"; echo "Student 2 Name: ".$_POST['Student_2_Name']; echo "<br>"; echo "Student 2 SSN: ".$_POST['SSN_Student_2']; echo "<br>"; echo "Student 2 Status: ".$_POST['Status_Student_2']; echo "<br>"; echo "Student 3 Name: ".$_POST['Student_2_Name']; echo "<br>"; echo "Student 3 SSN: ".$_POST['SSN_Student_2']; echo "<br>"; echo "Student 3 Status: ".$_POST['Status_Student_2']; echo "<br>"; } else { echo 'You didnt enter any data'; } ?> you're missing an end quote here: $db = mysql_connect("###############); altho i'm sure you accidentally deleted it when deleting the password, check it anyway. also, when a parse error comes along and it says it's on line 33, it may not actually be on line 33. it may be a couple of lines above it, or a couple of lines below. it's always best to post 5 lines above and below the error line. that way, we can help you. post all your code. Quote Link to comment Share on other sites More sharing options...
steviemac Posted February 20, 2007 Author Share Posted February 20, 2007 I ended up figuring it out. if(isset ($_POST['submit'])) { $result = "UPDATE bikepatrol SET Student_1_Name = '{$_POST['Student_1_Name']}', Student_2_Name = '{$_POST['Student_2_Name']}' WHERE id = {$_POST['id']}"; mysql_query($result) or die(mysql_error()); // echo out the query echo $result; Thanks for everyones help. Quote Link to comment 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.