Jump to content

My First Foray Into Mysql


bigsilk
 Share

Recommended Posts

I set up a db in MySQL through cPanel. It's there. I see it.I'm trying to create a table in which to store data from an online form.I'm not quite sure how to create the table in the db. I believe I have the right code:

<?php$con = mysql_connect("localhost","***","***");if (!$con) { die('Could not connect: ' . mysql_error()); }// Create tablemysql_select_db("bigsilkd_attorneys", $con);$sql = "CREATE TABLE attorneys(attoneyID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(attorneyID),LawFirmName varchar(30),MainOfficeAddress varchar(30),MainOfficeCity varchar(30),MainOfficeState varchar(2),MainOfficeZip varchar(10),MainOfficePhone varchar(30),MainOfficeEmail varchar(30),WebAddress varchar(30),Overview varchar(30),YearsofExperience int (3),Languages varchar(30),GeographiesServing varchar(30),PracticeAreas varchar(30),MainAttorneyName varchar(30),MainAttorneyPhone varchar(30),MainAttorneyEmail varchar(30),)";// Execute querymysql_query($sql,$con);mysql_close($con);?>
But when I fill out the form and hit the Submit button:
<form action="insert.php" method="post"> Law Firm Name: <input type="text" size="90" name="LawFirmName"><br> 'Tag Line': <input type="text" size="95" name="p_subtitle"><br> Your Name: <input type="text" size="97" name="p_name"><br> Office Street Address: <input type="text" size="77" name="MainOfficeAddress"><br> Office City: <input type="text" size="22" name="MainOfficeCity"> Office State: <select name="MainOfficeState" size="1">
(There's more to the form, I'm just excluding it for the sake of cleanliness.)I get this:Error: Table 'bigsilkd_attorneys.attorneys' doesn't existI assume that CREATE TABLE needs to be run once, but I'm not sure how to get it to run, or whether or not I was successful. It's apparent I wasn't.Here's insert.php:
<?php$con = mysql_connect("localhost","***","***");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("bigsilkd_attorneys", $con);$sql="INSERT INTO attorneys (LawFirmName, MainOfficeAddress, MainOfficeCity, MainOfficeState, MainOfficeZip, MainOfficePhone, MainOfficeEmail, WebAddress, Overview, YearsofExperience, Languages, GeographiesServing, PracticeAreas, MainAttorneyName, MainAttorneyPhone, MainAttorneyEmail)VALUES('$_POST[LawFirmName]','$_POST[MainOfficeAddress]','$_POST[MainOfficeCity]','$_POST[MainOfficeState]','$_POST[MainOfficeZip]','$_POST[MainOfficePhone]','$_POST[MainOfficeEmail]','$_POST[WebAddress]','$_POST[Overview]','$_POST[YearsofExperience]','$_POST[Languages]','$_POST[GeographiesServing]','$_POST[PracticeAreas]','$_POST[MainAttorneyName]','$_POST[MainAttorneyPhone]','$_POST[MainAttorneyEmail]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con)?>
Link to comment
Share on other sites

Well, why not just create the table from cPanel, or run the create script once first. It won't happen unless you run it, heh.

Link to comment
Share on other sites

I didn't see a 'create table' option in the MySQL wizard in my cPanel, else I would have done so.I uploaded the 'CREATE TABLE' page and opened it in a browser window, thinking that would get it to run. No love there.Is there something else I have to do to get it to run?

Link to comment
Share on other sites

I don't use cPanel, but I use PHPMyAdmin, and there ought to be a query box somewhere. Copy the table creation query, minus quotes, into the query box and execute it. You will get good feedback about any syntax errors that way, too. However, running the script should have been successful or given you errors. I take it there weren't any errors? Hm, you misspelled 'attorney' in the table create statement for the first column - that might have some bearing on it. If the table was created successfully, you now need to change the column name to attorney:ALTER TABLE attorneys CHANGE attoneyID attorneyID INT NOT NULL AUTO_INCREMENT ;

Link to comment
Share on other sites

Glad to help with hurdle number one.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...