Solved

Using Script to create tables...

Posted on 2002-04-22
15
201 Views
Last Modified: 2006-11-17
I am really just learning MySQL and PHP, and also have a project I need to get done with the deadline coming up soon.

The server that hosts the website does not allow me to use a command line, so I think I need to use scripts to create my tables. Andriv offered me the following code in another question:

$dbconnect = mysql_connect("host","user","password");
$mysql_select_db("dbName",$dbconnect);
$Query = "Create table tableName (prodid int(10) not null auto_increment,next field,next field)";
mysql_query($Query);


My question is, what do I surround the code with? HTML? PHP?

If PHP I would assume it would look like the following:

<?
   code from Andriv, to build table and columns
?>

Then would I need an HTML form to run the PHP, like this?

<html>
<head>
</head>
<body>

<form action="xxxx.php" method=post>
<table border=0>
<tr>
  <td colspan=2 align=center><input type=submit value="Submit Order"></td>
</tr>
</table>
</form>  

</body>
</html>


I really appreciate the help.



0
Comment
Question by:GaryZ
15 Comments
 
LVL 1

Expert Comment

by:bowker
ID: 6961609
Download phpMyadmin (http://sourceforge.net/project/showfiles.php?group_id=23067 then select the last entry under 2.2.6 which is phpMyAdmin-2.2.6-php3.zip) ... that's a group of scripts which forms a GUI frontend  to MySQL.  Edit the config.inc file to embed your MySQL username and password, then upload all the scripts to your shared server using FTP.

You will probably want to password-protect the subdirectory where you put the program - if you have Telnet access, you can do this with an .htaccess and .htpasswd file ... otherwise, look for another project on SourceForge called "phpaccess" -- put this script in the same subdir as phpMyAdmin and run it to create the password protection you need.

This is an overview - please let me know if I can give you any other details ...

Bob.
0
 

Author Comment

by:GaryZ
ID: 6961675
Will this run on Windows 2000 or only on the host server?
0
 
LVL 4

Expert Comment

by:lokeshv
ID: 6961811
u have to upload that t ur server..


u can try this also...

<?
if($submit){
$dbconnect = mysql_connect("host","user","password");
$mysql_select_db("dbName",$dbconnect);
$Query = "Create table tableName (prodid int(10) not null auto_increment,next field,next field)";
$result=mysql_query($Query);
if(!$result){
    echo "Error:".mysql_error();
}
}
else{
?>

<html>
<head>
</head>
<body>

<form action="<?=$PHPSELF?>" method=post>
<table border=0>
<tr>
 <td colspan=2 align=center><input type=submit name=submit value="Create Table"></td>
</tr>
</table>
</form>  

</body>
</html>
<?}?>


Hope this helps...

LK

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Expert Comment

by:peebody
ID: 6962229
And please always use <?php ?> to embedd your php code, because not every environment accepts <? ?>

PP
0
 
LVL 1

Expert Comment

by:bowker
ID: 6962820
GaryZ -

phpMyAdmin runs on the server ... it's a GUI frontend to MySQL, enabling you to add/edit/delete tables, add/edit/delete records, - in short, control the whole database.  On your local machine, edit config.inc (to add your username, password and database name) then use FTP to upload all the files to your server, for example, into a new subdirectory (under the web root dir) called "phpmyadmin".  Then point your browser to http://www.yourdomain.com/phpmyadmin/index.php3 and you're off and running ...

PHPAccess is a similar process, although there's nothing to edit ahead of time.  Use FTP to upload the file intpo /phpmyadmin, then point your browser to http://www.yourdomain.com/phpmyadmin/phpaccess.php to run the script.  This script allows you to add/edit/delete Usernames and Passwords controlling access to all files in the subdirectory /phpmyadmin where it's located.  Now, when you go to phpmyadmin/index.php3 you'll be challenged for your username and password ...

Let me know if I can help you walk through all this ...

Bob.
0
 

Author Comment

by:GaryZ
ID: 6967219
OK. I have downloaded the file and unzipped it into a directory. Now I need to configure the config.inc.php3 file.

It says to change host,user, password, and authentication mode.

The ISP sent me the name of the database they created, plus the username and password. Is the host the domain name? What about the authentication mode?

It also appears that these have to be changed in more than one spot?

The database will contain inventory information and will be accessed by a search form from the internet. There is not special login needed, anyone should be able to do the search.
0
 
LVL 1

Accepted Solution

by:
bowker earned 150 total points
ID: 6967420
Gary --

You only have 3 changes to make ... leave the rest as-is:

$cfgServers[$i]['host']          = 'localhost';              // leave as 'localhost'
$cfgServers[$i]['port']          = '';        
$cfgServers[$i]['socket']        = '';        
$cfgServers[$i]['connect_type']  = 'tcp';      
$cfgServers[$i]['controluser']   = '';        
$cfgServers[$i]['controlpass']   = '';      
$cfgServers[$i]['auth_type']     = 'config';    
$cfgServers[$i]['user']          = '';                                // enter your username
$cfgServers[$i]['password']      = '';                          // enter your password
$cfgServers[$i]['only_db']       = '';                             // enter your database name

If you still have problems, send me your telephone number bowker@inetwebinc.com and I'll talk you through the process ...

Bob.
0
 
LVL 1

Expert Comment

by:bowker
ID: 6967429
Gary --

Sorry, the code I quoted starts at line 46 of config.inc.php3 ... you can safely delete lines 69 through 99 inclusive, as you'll only be using this installation for 1 database.

Bob.
0
 

Author Comment

by:GaryZ
ID: 6973646
I have it loaded and renamed the php3 to php, I get the following error when I try to run index.php. It appears that maybe the hosting domain does not have something set up of I need to get a path from them

Fatal error: Failed opening required './libraries/grab_globals.lib.php' (include_path='')
0
 
LVL 1

Expert Comment

by:bowker
ID: 6974113
Gary --

It's referring to a file that should be in the dir /libraries under phpMyadmin ... did you create the dirs phpMyadmin/libraries, phpMyadmin/lang and phpMyadmin/images on the server and upload the files in those corresponding subdirs from your drive to the server?

Bob.
0
 

Author Comment

by:GaryZ
ID: 6974885
I have to chagne all references to php3 to php. PHP3 does  not work on the server.
0
 

Author Comment

by:GaryZ
ID: 6974940
Yep, that was the problem, came right up (Oh, you also have to configur the line that has the path to the mySQLAdmin directory).

One last question. I downloaded the phpaccess and unzipped. There is no documentation, do I just load the script htaccess.class.php to the server and run it to set the username and password?
0
 
LVL 1

Expert Comment

by:bowker
ID: 6975115
Gary --

Yes, that's it ... but the file I downloaded has just 1 PHP script named phpaccess.php - no associated class, just the script.

This script creates and manages access to the subdirectory in which you place it, and from which you run it.  Should you ever need to get rid of challenge-response access to that dir, delete the files .htaccess and .htpasswd, which phpaccess creates and manages for you.

You do need to protect this directory, and phpaccess is the easiest way to do that.

Bob.
0
 
LVL 1

Expert Comment

by:bowker
ID: 6975125
Gary --

You can make your PHP installation handle files with .php3 by adding the following line to the .htaccess file in the main directory:

AddType application/x-httpd-php .php3

If the main dir does not already have a file named .htaccess, then create one with the single line and upload it ... the line forces Apache to hand files named .php3 off to PHP.  Obviously the line

AddType application/x-httpd-php .html

... would do the same for all files with .html, too.

Bob.
0
 

Author Comment

by:GaryZ
ID: 6975144
Thanks for the help. I will probably be back for more.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP and JQuery Syntax question 4 26
Custom Wordpress Loop 22 39
Delete  php pages of a part of our site 8 34
JQuery Search Filter 2 39
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question