Click to See Complete Forum and Search --> : php - problem with setting up mysql db/table


rhboarder
April 7th, 2010, 09:55 PM
Im having the most frustrating time trying to figure this out, this script runs great on my private (WAMP) server but not on my hosting server (LAMP). The script is pretty simple, creates a database with a table of 6 fields:

<?php

$host = "127.0.0.1";
$username = "my_username";
$pwd = "my_password";

if (mysql_connect($host, $username, $pwd))
{
$query = "CREATE DATABASE IF NOT EXISTS weup";
//execute query
if (mysql_query($query))
{
print "Database created successfully!<br />";
//must select db before creating table
if (@mysql_select_db("weup"))
{
$query = "CREATE TABLE IF NOT EXISTS applications(appname VARCHAR(25),
description VARCHAR(200), applink VARCHAR(50), authname VARCHAR(50), authage INT, authloc VARCHAR(40))";
//create the table
if (mysql_query($query)) print "Table created successfully!";
else print "Error creating table";
}
} else print "Error creating database";
mysql_close();
} else print "Unable to connect to " . $host;

?>

PeejAvery
April 8th, 2010, 10:56 AM
You haven't stated which part of it fails.

rhboarder
April 8th, 2010, 11:06 AM
oh im sorry. specifically the 'mysql_query($query)' is whats not working. I know the actual string is good so am i executing it wrongly?

PeejAvery
April 8th, 2010, 06:02 PM
Which one?

Also...you have a @ in front of mysql_select_db(). That tells it to suppress errors. You might not get a good log report that way.

rhboarder
April 8th, 2010, 07:22 PM
both of them, so right now i'm getting outputted "error creating database". and if i take out that first "if(mysql_query())" and just have "mysql_query", then on the next query i get "Error creating table". so basically both

if (mysql_query($query))

are coming back negative.

PeejAvery
April 8th, 2010, 07:56 PM
So copy the exact query string into phpMyAdmin. See what that returns.

rhboarder
April 9th, 2010, 11:21 AM
hey guys, thanks for the replies. after running it through phpMyAdmin I realized the problem had to do with my hosting server not the code.