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
https://forums.phpfreaks.com/topic/59762-solved-im-stuck-on-my-first-project/
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.

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
)
";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.