Jump to content

[SOLVED] Newbee problem with UPDATE query from a form


steviemac

Recommended Posts

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';
}
?>

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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';
}
?> 

Link to comment
Share on other sites

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";

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
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.