douqiu0351 2013-08-12 14:13
浏览 11

如何从textarea创建表?

Edited and Solved (Thanks to Prix)

Here is the Full Script, An amazing Visitor Tracker: https://github.com/solarisedesign/Visitor-Tracker-PHP-MySQL

I found a solution with the help of user Prix! An amazing and awesome person! He helped me create a new SQL Table!

Here is an image of an example I found online, and this is how I want to build it:

http://i39.tinypic.com/106aghx.png

Here is an image of the new Database by Prix: enter image description here

Direct Link to the Database query, by Prix: http://sqlfiddle.com/#!2/4bc83/5/0

Many thanks to Prix for helping me out....... Check the full Topic below... Thank you

My Question was:

I am simply trying to create my own script for users to log Visitor IPs and also go in and Track who was visiting their site and everything will be logged inside a MySQL database!

When launching the script, they users will be asked to choose a Name inside a "textarea". So when a user picks a name and clicks on CREATE URL, then the script will create a SQL database table called test. Right now the Script is only used for 1 Person or user! But I want to make it available for everyone, so users only have to visit our site and simply create a user, and all the files and tables will be automatically added in the folder and ready for use.

I want to know how I can create a Table for each user that choose a name in textarea! So when a user chooses the name "mike" in the textarea, then the script should create a table named "mike" and simply add the rest of the tables inside the table "mike"!

The textarea is called "$name" in the sql code below, and when I add "$name" infront of the this part:

CREATE TABLE $name

Then I simply get an error. I don't know how to add the textarea so it can create the same table as the name chosen in the text area:

This is my full script:

<form action="" method="post" >
    <table width="400" border="0" cellspacing="0" cellpadding="5">
        <tr>
            <td colspan="3" align="center">Please choose a Folder or Name?</td>
        </tr>
        <tr>
            <td>Name </td>
            <td>&nbsp;</td>
            <td><input type="text" name="name" 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['name'];
        echo " "; 
        echo "Conguradulations. Your new URL is sucessfully created.!"; 
        echo " ";
        echo " ";
        echo "Your new URL name is $name"; 
    }
    $dbhost = 'host';
    $dbuser = 'dbuser';
    $dbpass = 'dbpass';
    $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('dbname');
    $retval = mysql_query( $sql, $conn );
    if(! $retval ) {
        die('Could not create table: ' . mysql_error());
    }
    mysql_query($sql,$conn);
?>

So the script above has the everything in it and done. I just need help to attach the textarea so it can create the a table in MySQL using the text from the textarea!

I was thinking that this could help me out, and if someone could help me create a code from that to help me out.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分