Jump to content

[SOLVED] Im stuck on my first project.


Northern Flame

Recommended Posts

This is the first project that I have ever done alone in PHP and I am stuck in 1 part.

Auto creating a MySQL table.

On the install.php file the user is asked to name his table.

Once he names the table, it will be sent to a script called send_var.php

which will then write it into an empty file called /var/tables.php

It writes everything that I ask it to write, but it doesn't create the table.

Am I suppose to somehow make the page create the table?

Because I thought it would automatically create itself.

heres the part of my code that writes the MySQL query to create the tables.

 

if (!empty($errors)){
echo
  "<h1><font color=red>Error</font></h1><br>";
   foreach ($errors as $key => $val){
       echo $val;
    } 
}  
  else {
    echo 'Alright, it is installed!<br>
    To start working on this website, just 
	click <a href="/Admin/index.php">here!</a>';
    $db = "var/tables.php";
    $fh = fopen($db, 'w') or die("cant open file");
    $stringData = '
<?php
$dbhost = "'.$dbhost.'";
$dbuser = "'.$dbuser.'";
$dbpass = "'.$dbpass.'";
$dbname = "'.$dbname.'";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
                     ("Error connecting to mysql");
mysql_select_db($dbname);
$query =<?php
    "CREATE TABLE '.$table.'( '.
         'username VARCHAR(20), '.
         'encryptpass VARCHAR(255) NOT NULL, '.
         'password VARCHAR(20) NOT NULL, '.
         'website_title VARCHAR(30) NOT NULL, '.
         'meta_key VARCHAR(100) NOT NULL, '.
         'meta_des VARCHAR (100) NOT NULL,'.
	 'links BLOB(500) NOT NULL, '.
	 'top_h1 VARCHAR(100) NOT NULL, '.
	 'top_p BLOB(500) NOT NULL, '.
	 'site_name VARCHAR(30) NOT NULL, '.
	 'bottom_h2 VARCHAR(100) NOT NULL, '.
	 'bottom_p BLOB(500) NOT NULL)";
mysql_query($query); ?>
';
    fwrite($fh, $stringData);
    fclose($fh);

 

IF ANYONE CAN HELP I'D REALLY APPRECIATE IT!!!!

Link to comment
Share on other sites

Alright, you can try run those query on your phpmyadmin to ensure the query are right, then

Try use this for your query,

	$query =
    "CREATE TABLE ".$table."( '.
         'username VARCHAR(20), '.
         'encryptpass VARCHAR(255) NOT NULL, '.
         'password VARCHAR(20) NOT NULL, '.
         'website_title VARCHAR(30) NOT NULL, '.
         'meta_key VARCHAR(100) NOT NULL, '.
         'meta_des VARCHAR (100) NOT NULL,'.
	 'links BLOB(500) NOT NULL, '.
	 'top_h1 VARCHAR(100) NOT NULL, '.
	 'top_p BLOB(500) NOT NULL, '.
	 'site_name VARCHAR(30) NOT NULL, '.
	 'bottom_h2 VARCHAR(100) NOT NULL, '.
	 'bottom_p BLOB(500) NOT NULL)";

 

Edit: Take note of the double quote used on $query and $table.

Link to comment
Share on other sites

You don't need to put http for it, try this

$query ="
CREATE TABLE `".$table."` (
  `username` VARCHAR(20),
  `encryptpass` VARCHAR(255) NOT NULL,
  `password` VARCHAR(20) NOT NULL,
  `website_title` VARCHAR(30) NOT NULL,
  `meta_key` VARCHAR(100) NOT NULL,
  `meta_des` VARCHAR (100) NOT NULL,
  `links` BLOB(500) NOT NULL,
  `top_h1` VARCHAR(100) NOT NULL,
  `top_p` BLOB(500) NOT NULL,
  `site_name` VARCHAR(30) NOT NULL,
  `bottom_h2` VARCHAR(100) NOT NULL,
  `bottom_p` BLOB(500) NOT NULL
)
";

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.