Unable to get Table Name using variable string MYSQL Error

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 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 '
'
; }
0 views
0 shares

profilepic.png
manpreet 2 years ago

The error INCORRECT TABLE NAME '' error means you don't have a value in $tableName. Your $_GET['category'] is not picking up a recognized value or the extract($_POST) is changing $tableName to an empty value.


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