Unable to get Table Name using variable string MYSQL Error

Course Queries Syllabus Queries 3 years ago

2.34K 1 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago

if ($_GET['category'] == "ebooks") { $tableName = $smallsubcodewithoutspace.'_ebooks'; $sectionTitle = "Ebook"; } elseif ($_GET['category'] == "syllabus") { $tableName = $smallsubcodewithoutspace.'_syllabus'; $sectionTitle = "Syllabus"; } elseif ($_GET['category'] == "pnotes") { $tableName = $smallsubcodewithoutspace.'_pnotes'; $sectionTitle = "Practical Note"; } elseif ($_GET['category'] == "assignments") { $tableName = $smallsubcodewithoutspace.'_assignments'; $sectionTitle = "Assignment"; } elseif ($_GET['category'] == "tnotes") { $tableName = $smallsubcodewithoutspace.'_tnotes'; $sectionTitle = "Theory Notes"; } //if form has been submitted process it if(isset($_POST['submit'])){ $_POST = array_map( 'stripslashes', $_POST ); //collect form data extract($_POST); //very basic validation if($contentTitle ==''){ $error[] = 'Please enter the Content Title !'; } if($contentLink ==''){ $error[] = "Please enter the Content Link !"; } if(!isset($error)){ try { //insert into database $stmt = $db->prepare("INSERT INTO `$tableName` (contentTitle,contentLink,contentAuthor) VALUES (:contentTitle, :contentLink, :contentAuthor)") ; $stmt->execute(array( ':contentTitle' => $contentTitle, ':contentLink' => $contentLink, ':contentAuthor' => $contentAuthor )); //redirect to index page header('Location: add-content.php?notallowed=true'); exit; } catch(PDOException $e) { echo $e->getMessage(); } } } //check for any errors if(isset($error)){ foreach($error as $error){ echo '
class="alertpk">
class="alert alert-warning" role="alert">'.$error.'
'
; }
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum