Jump to content

How to create a Simple MYSQL Table using PHP or HTML Textarea?


Miklo

Recommended Posts

First of all, I am Miguel and very happy to have found this forum! I really been looking for a  nice php forum with mysql experts as well! And I really need your help today!
 
My Question is simple: How to create a simple Table with a PHP file from a Textarea!
 
Here is an example Image of how I want the Textarea to look like:
106aghx.jpg
 
I found a Code online a few days ago, that Allows users to Trace their Visitors. The Script was an IP Logger that I later changed to a "Visitor Tracker".. So users will be able to pick a URL or a FOLDER by simply typing the name of the folder in the Textarea! After clicking Submit the text will be changed to a Folder and then used as a URL! And that URL will be their Tracking Folder-
 
So if the user creates a username called "mike", then the folder will be "www.website.com/mike.
 
Now here is the problem! The script I have have 1 TABLE, and rest of the other tables are inside that one table!Then everyone website owener will be able to see eachothers visitors. Not good.
 
Thats why I wanted to Create a PHP file that simply Creates a NEW TABLE for each user. And thats where I am locked.
 
This is the code I am using for my index.php page:

<form action="" method="post" >
<table width="400" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td colspan="3" align="center">Please write gallery name and description</td>
  </tr>
  <tr>
    <td>Name </td>
    <td> </td>
    <td><input type="text" name="gname" id="text" value=""></td>
  </tr>
  <tr>
    <td colspan="3" align="center"><input type="submit" name="submit" id="submit" value="Submit"></td>
  </tr>
</table>
</form>
<?PHP
if (isset($_POST['submit'])) {
$name = $_POST['gname'];
$username = 'gname';
echo " ";
echo "Conguradulations. Your new URL is sucessfully created.!";
echo " ";
echo " ";
echo "Your new URL name is www.Removed.com/$name";
    }
$dbhost = 'host';
$dbuser = 'username';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$sql = 'CREATE TABLE test('.
  'entry_id int(11) NOT NULL AUTO_INCREMENT, '.
  'visitor_id int(11) default NULL, '.
  'ip_address varchar(15) NOT NULL, '.
  'page_name text, '.
  'query_string text, '.
  'timestamp timestamp NOT NULL default CURRENT_TIMESTAMP, '.
  'PRIMARY KEY  ( entry_id ), '.
  'KEY visitor_id ( visitor_id , timestamp )) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;';

mysql_select_db('testdb');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not create table: ' . mysql_error());
}
mysql_query($sql,$conn);
?>

I tried to change this:

CREATE TABLE test

to

CREATE TABLE $name

But still didnt work! I am really new using this kinda scripts. So I am kinda lost..After 4 days of searching, I found a script in here so I thought I could maybe get some help in here.. As you can see the SQL creates a table with the name "test" and adds all the other tables inside! And thats what I want to change so the Textarea text could replace the test for each new user, and when the table is created, it should then rest of the querries should be added in there...

 

I found a the Script in here, dont know if this could help >> http://forums.phpfreaks.com/topic/168449-solved-inserting-multiple-lines-from-a-text-area-to-sql-table/

 

Here is another Script too, but in another forum: http://www.webmasterforums.com/php-development/3343-textarea-mysql.html

 

I tried for days on the last script, but I couldnt make that work either! I dont know which page should be added where, and How I should add my SQL code inside... so if anyone could fix the problem with more professional knowledge, then my days and weeks of hard work is saved!

 

Thank you very very much in advance!

Edited by Miklo
Link to comment
Share on other sites

I still havnt got any Answer on a forum that I really counted on would at least answer back if not the fix..

 

Anyways, I came to let you guys know that I finally managed to fix it. By myself!

 

Topic is Solved and can be closed

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.