This function gets the date from the user:
function getCCGraduationDate () {
?>
<form method="post" action="processor.php">
Graduation Date: <input type="text" name="CCgraduationdate"><br>
<input type="submit">
<?php
}
This function sends the value to a DB and is called on the processor.php page:
function sendCCGraduationDate () {
$con = mysql_connect("localhost","root","XXXXXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("user", $con);
$grad = mysql_real_escape_string($_POST['CCGraduationDate'], $con);
$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid=$this->user_id";
mysql_query( $sql , $con );
mysql_close($con);
}
For some reason the value isn't populating in the database. I had tested similar functions last night and they worked, not sure what I'm missing here.
Please check this:
FORM CODE:
<input type="text" name="CCgraduationdate"><br>
PHP CODE:
$grad = mysql_real_escape_string($_POST['CCGraduationDate'], $con);
Your CCgraduationdate
in your form is unequal to CCGraduationDate
in your php code
If you're not getting an error like:
Notice: Undefined index: CCGraduationDate /* blah blah blah */
Then you can try adding at the top of your PHP code:
error_reporting(E_ALL);
And then see if an error comes out.
Of course, that's after changing your $sql
variable's data to:
$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid=" . $this->user_id;
Assuming there is an actual value for $this->user_id
:
$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid=$this->user_id";
// Should be:
$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid={$this->user_id}";
// Or
$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid= " . $this->user_id;
-- Edit --
$sql = "UPDATE profile SET CommunityCollegeGraduationDate='$grad' WHERE userid= " . $this->user_id;
if (!mysql_query( $sql , $con ))
die(mysql_error());
}
-- Edit --
// To avoid case and extra space issues, sanitize your var first
$grad = trim(strtolower($grad));
// You did well to escape
$grad = mysql_real_escape_string($grad, $con);