Hello,
I am trying to use this PHP form to mysql script that I have found on the internet.
Here is my form:
<html>
<head>
<title>English Language</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="insert.php">
<p>Forum URL: http://<input name="name" type="text" id="tableprefix">.example.com
<input type="submit" name="Submit">
</p>
</form>
</body>
</html>
Basically, I want to have the form users input insert data into a table with a variable table prefix. Here is what I basically want to have in my insert.php:
<?php
// Include the Mysql Config file (config.php)
include 'config.php';
// Connect to Mysql
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$tableprefix = $_POST['tableprefix'];
//$table = $tableprefix."_languages";
// Insert into Mysql Database:
$query = "INSERT INTO `".$tableprefix."_languages` (lid, ldir, lname, lauthor, lemail) VALUES ('3', 'en', 'English', 'Invision Power Board', 'languages@invisionboard.com')";
mysql_query($query) or die("Query failed: " . mysql_error());
//mysql_query("INSERT INTO $table (lid, ldir, lname, lauthor, lemail) VALUES ('3', 'en', 'English', 'Invision Power Board', 'languages@invisionboard.com')") or die ("Query failed: " . mysql_error());
// Show alert when data inserted to Mysql
echo "<script language=javascript>alert('Data inserted to Mysql Database!'); window.location = 'index.php'; </script>";
// Close connection to Mysql
mysql_close($conn);
?>
It just does not work. The error I get is:
Query failed: Table 'exampleuser_exampledb._languages' doesn't exist
I do not know how to get the variable to work in there. Any help to get it to work would be appreciated. Thanks!