For some reason i am not getting an output from this code. Specifically from this if statement: I inserted an html tag with a test word, but it never appeared on the output. I fixed the "SELECT" typo.. still getting same results.. no output.. i think the problem is from this statement.
$db = new PDO("mysql:dbname=university", "root", "");
I inserted another test phrase right before it - success and another one right after it - didn't output
if($sel=="getinfo"){
try {
$db = new PDO("mysql:dbname=university", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$rows = $db->exec("SEEELECT * FROM fminformationtable WHERE FM_ID = '$_POST[iden]'");
?>
test
<?php
}
This is the full function
if($sel=="addnew"){
try {
$db = new PDO("mysql:dbname=university", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$rows=$db->query("INSERT INTO fminformationtable
VALUES('$_POST[iden]','$_POST[lname]','$_POST[fname]','$_POST[office]','$_POST[ext]','$_POST[hphone]','$_POST[mobile]','$_POST[address]','$_POST[email]','$_POST[syear]','$_POST[tyear]','$_POST[ldegree]','$_POST[ofrom]','$_POST[dyear]','$_POST[rinterest]')");
}
catch (PDOException $ex) {
?>
<p>Your information has been submitted! </p>
<?php
}
if($sel=="update"){
try {
$db = new PDO("mysql:dbname=university", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$rows=$db->query("UPDATE fminformationtable SET
Office=`$_POST[office]`,
Extension=`$_POST[ext]`,
HomePhone=`$_POST[hphone]',
MobilePhone=`$_POST[mobile]`,
Adress=`$_POST[address]`,
Email=`$_POST[email]`,
StartingYear=`$_POST[syear]`,
TerminationYrear=`$_POST[tyear]`,
LatestDegree=`$_POST[ldegree]`,
ObtainedFrom=`$_POST[ofrome]`,
DegreeYear=`$_POST[dyear]`,
ResearchInterest=`$_POST[rinterest]`
");
}
catch (PDOException $ex) {
}
}
}
if($sel=="delete"){
try {
$db = new PDO("mysql:dbname=university", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$rows = $db->exec("DELETE FROM fminformationtable WHERE FM_ID = '$_POST[iden]'");
}
catch (PDOException $ex) {
}
}
if($sel=="getinfo"){
try {
$db = new PDO("mysql:dbname=university", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$rows = $db->exec("SEEELECT * FROM fminformationtable WHERE FM_ID = '$_POST[iden]'");
?>
test
<?php
}
SEEELECTmight be a typo ... it throws, which is never caught!POSTvariable directly in the query is a huge mistake. You need to read up on sql injection. As you are already using PDO, switching to prepared statements with bound variables is easy.$rows = $db->exec("SEEELECT *...is that a typo?POSTdirectly in your statment is a huge no-no ... No pun intended .. Or is there?