Twango Posted March 5, 2011 Share Posted March 5, 2011 Ok, help me please.i want to use this code to add accounts.<?php$mh = "mysql9.000webhost.com";$md = "a5301810_dat2";$mu = "a5301810_***";$mp = "******";$con = mysql_connect($mh,$mu,$mp);if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db($md, $con);$sql="INSERT INTO Accounts (Usr, Pw, Special)VALUES('$_POST[Account]','$_POST[Password]','$_POST[special]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con)?>So it gives the error "Error: Table 'a5301810_dat2.Accounts' doesn't exist"Now, i use a simple <form> to the information to this.-I created the tabled in a different php document with this code:<?php$con = mysql_connect("mysql9.000webhost.com","a5301810_****","******");if (!$con) { die('Could not connect: ' . mysql_error()); }// Create tablemysql_select_db("a5301810_dat2", $con);$sql = "CREATE TABLE Accounts(Usr varchar(20),Pw varchar(20),Special varchar(20),)";// Execute querymysql_query($sql,$con);echo "Created Accounts";mysql_close($con);?>I ran it once (That should work, right?)So. what am i doing wrong? *DB passwords and info hidden for safety " Link to comment Share on other sites More sharing options...
[dx] Posted March 5, 2011 Share Posted March 5, 2011 The best for testing is mysql_error(). Link to comment Share on other sites More sharing options...
thescientist Posted March 5, 2011 Share Posted March 5, 2011 sounds like the table doesn't exist.i would go back to your original table creation code and actually verify the table was created (or view it using phpMyAdmin or something equivalent). This is how I would make sure the table was actually created, by testing the return value of the table create code (mysql_query). You didn't actually test to see if it worked, the way it's written, it will always print "Accounts Created". <?php$con = mysql_connect("mysql9.000webhost.com","a5301810_****","******");if (!$con){die('Could not connect: ' . mysql_error());}// Create tablemysql_select_db("a5301810_dat2", $con);$sql = "CREATE TABLE Accounts(Usr varchar(20),Pw varchar(20),Special varchar(20),)";// Execute query //Test to make sure it went throughif(mysql_query($sql,$con)){ echo "Created Accounts";}else{ echo "ERROR: table Accounts NOT created";};mysql_close($con);?> make sure you get an accurate create message, then move onto INSERT. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.