Jump to content

Need help creating a table in MySQL using PHP with existing database already made


BenAlcock

Recommended Posts

I have a database already created in MySQL called "accounts" and im trying to insert a new table called "test". I am using XAMPP Control Panel: v3.1.0.3.1.0, XAMPP: v1.8.1 [php: 5.4.7] and MySQL: v5.5.27. I am very new to PHP (only been learning for a few days). I would appreciate any attempts of trying to help me.

- Ben

 

<?php

$accounts = mysql_connect("localhost", "root", "qazwsxedc")

or die (mysql_error());

mysql_select_db("accounts",$accounts);

$sql = "CREATE TABLE test

(

ID int NOT NULL AUTO_INCREMENT,

PRIMARY KEY(ID),

Username varchar(20),

Password varchar(20),

First name varchar(20),

Last name varchar(20)

)";

mysql_query($sql, $accounts);

 

?>

Link to comment
Share on other sites

I am also new to .php but i am fairly confident your database name wouldn't just be called accounts it would be "yourdomai'_accounts (i purposely missed the "n" on domain because the last letter of your domain name wont be included in the DB name

 

Uhm, please don't give advice when you literally have no idea what you're talking about. What you're describing sounds like a setup from a specific hosting company. OP is using XAMPP for localhost development.

Link to comment
Share on other sites

Debug the call to mysql_query() and determine if it is in fact returning a resource:

 

mysql_query($sql, $accounts) or die("Mysql Error: " . mysql_error());

 

Also make sure that error_reporting() is set to E_ALL or -1 and display_errors() is ON

Link to comment
Share on other sites

Uhm, please don't give advice when you literally have no idea what you're talking about. What you're describing sounds like a setup from a specific hosting company. OP is using XAMPP for localhost development.

 

Wow, sorry i will keep my mouth shut next time. Reason i said what i said is because i had a mySQL problem a while ago and it was due to DB name being incorrect even though my CP said it was correct

Edited by clarky0
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.