Hi
I am inserting some results from a user input form into mysql database.
The code I have works up to a point but 2 of the values aren't getting put into the database.
By testing the output of certain variables I think I know where the error is, but I cannot see what the problem is - can anyone help......
IF ($_POST[AuthorityLevel] == "Concession User")
{$AuthorityLevel = "2";}
ELSEIF ($_POST[AuthorityLevel] == "Client Administrator")
{$AuthorityLevel = "3";}
ELSE
{$AuthorityLevel = "4";}
$Client = $_POST[client];
$Section = $_POST[section];
$CName = $_POST[new_name];
$CPhone = $_POST[new_phone];
$CFax = $_POST[new_fax];
$CLogIn = $_POST[new_username];
$CPass = $_POST[new_password1];
$CEmail = $_POST[new_email];
// find ClientId
$query = "SELECT `ClientId` FROM `tblClient` WHERE `CoName` = '$Client'";
$result = mysql_query($query)
or die(mysql_error());
while($row = mysql_fetch_array($result))
$ClientId = $row["ClientId"];
// find SectionId
$query = "SELECT SectionId FROM tblSection
WHERE SectionName = '$Section'";
$result1 = mysql_query($query)
or die(mysql_error());
while($row1 = mysql_fetch_array($result1))
$SectionId = $row1["SectionId"];
// find ConcesRef
$query = "SELECT `ConcesRef` FROM `tblUser`
WHERE `CLogIn` = '$username'";
$result2 = mysql_query($query)
or die(mysql_error());
while($row2 = mysql_fetch_array($result2))
$ConcesRef = $row2["ConcesRef"];
//test these variables
echo $ClientId;
echo $SectionId;
echo $ConcesRef;
IF ($_POST[new_password1] != $_POST[new_password2])
{
echo ' The passwords you gave were not the same, please click the back arrow on your browser and try again.';
}
else
{
$sql = "INSERT INTO tblUser (ConcesRef, SectionRef, ClientRef, CName, CPhone, CFax, CLogIn, CPass, CEmail, AuthorityLevel)
VALUES ('$ConcesRef', '$SectionId', '$ClientId', '$CName', '$CPhone', '$CFax', '$CLogIn', '$CPass', '$CEmail', '$AuthorityLevel')";
$result = mysql_query($sql)
or die(mysql_error());
echo '<div align="center">
<p> </p>
<p><font face="Arial, Helvetica, sans-serif"><b><font size="3" color="#FF0000">
The record has been added.
</font></b></font></p>
</div>';
}
Out of the variables I am INSERTING, only $SectionId and $ClientId don't work.
I know that $Client and $Section work OK because when I echo them out they come up with the expected results.
So I am guessing that any error lies in the $query sections of the code.
From the echo test of the variables $ClientId and $SectionId don't output anything.
Interestingly the $ConcesRef value goes in OK based on the same query structure........
Can anyone see where I have gone wrong - thanks