Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Creating a Table with a variable as the table name

Featured Replies

Hi guys,

 

Can anybody tell me what I am doing wrong here, or maybe suggest an easier way to do it...?

 

Below are some different coding formats i have already tried.

Number 1

 

$query2 = "CREATE TABLE '$course_id'( '.
	 'id INT NOT NULL AUTO_INCREMENT, '.
	 'title VARCHAR(40) NOT NULL, '.
	 'department VARCHAR(40) NOT NULL, '.
	 'tutor VARCHAR(40) NOT NULL, '.
	 'students VARCHAR(500) NOT NULL, '.
	 'PRIMARY KEY(id))";

 

Number 2

 

$query2 = 'CREATE TABLE' . $course_id . '( '.
	 'id INT NOT NULL AUTO_INCREMENT, '.
	 'title VARCHAR(40) NOT NULL, '.
	 'department VARCHAR(40) NOT NULL, '.
	 'tutor VARCHAR(40) NOT NULL, '.
	 'students VARCHAR(500) NOT NULL, '.
	 'PRIMARY KEY(id))';

Number 3

 

$query2 = "CREATE TABLE $course_id '( '.
	 'id INT NOT NULL AUTO_INCREMENT, '.
	 'title VARCHAR(40) NOT NULL, '.
	 'department VARCHAR(40) NOT NULL, '.
	 'tutor VARCHAR(40) NOT NULL, '.
	 'students VARCHAR(500) NOT NULL, '.
	 'PRIMARY KEY(id))";

 

 

At the end of EVERY try of this is the following statement:

$result2 = mysql_query($query2);

 

I am also running another query with some of the same fields but that shouldn't matter right? I have run 2 queries before. :)

 

Any ideas?

 

Thanks in advance.

  • Author

Solved it, nevermind.

 

$sql = "CREATE TABLE `matthusele5`.`$name` (`id` INT NOT NULL, `title` TEXT NOT NULL, `department` TEXT NOT NULL, `tutor` TEXT NOT NULL, `students` TEXT NOT NULL, PRIMARY KEY (`id`)) ENGINE = MyISAM";

 

This seemed to work, gotta love PHP MyAdmin :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.