ardyandkari Posted January 11, 2007 Share Posted January 11, 2007 hi, i am having a problem inputting data into my mysql database. i am using an html form and php. the form is just a basic form: name type of company, city, etc. i have tried a few different things, but being a noob to php, dont really know what is wrong.i will post the php code now and the error after:[code]<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title></head><body><?php$username="user";$password="name";$database="password";$first=$_POST['name'];$last=$_POST['type'];$phone=$_POST['phone'];$mobile=$_POST['city'];$fax=$_POST['county'];$email=$_POST['email'];$web=$_POST['web'];$description=$_POST['description'];mysql_connect(mysql.someserver.net,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query = "INSERT INTO contacts VALUES ('','$name','$type','$phone','$city','$county','$email','$web','description')";mysql_query($query);mysql_close();?></body></html>[/code]i have used mysql_connect(mysql_someserver_net,$username,$password); also.this is the error message:Warning: mysql_connect(): Unknown MySQL Server Host 'mysq_someserver_net' (0) in (path to the php page) on line 24Unable to select databaseany help would be very much appreciated.thanks in advance.ardy Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/ Share on other sites More sharing options...
ted_chou12 Posted January 11, 2007 Share Posted January 11, 2007 $query = "INSERT INTO contacts VALUES (''[color=red],[/color]'$name','$type','$phone','$city','$county','$email','$web','description')";this is a syntax.Ted Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158215 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Its saying you havent specified a correct database server. mysql.someserver.net Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158220 Share on other sites More sharing options...
ardyandkari Posted January 11, 2007 Author Share Posted January 11, 2007 [quote author=ted_chou12 link=topic=121933.msg502207#msg502207 date=1168521740]$query = "INSERT INTO contacts VALUES (''[color=red],[/color]'$name','$type','$phone','$city','$county','$email','$web','description')";this is a syntax.Ted[/quote]thanks for the quick reply.i fixed the syntax.i am still unable to connect to the database. tried changing the connect to "mysql_connect(localhost,$username,$password);" now i get this as an error.Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in (path to php page) on line 24Unable to select databasesuper confused...thanks alot though for pointing out another problem.[quote author=thorpe link=topic=121933.msg502213#msg502213 date=1168522615]Its saying you havent specified a correct database server. mysql.someserver.net[/quote]for the address i copied it right from my host's mysql page. unless they put up faulty addresses.... Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158224 Share on other sites More sharing options...
ted_chou12 Posted January 11, 2007 Share Posted January 11, 2007 so there is still a problem? you cannot connect to your mysql db is it? some host servers dont support "localhost" and you need to have the server.mysql.net something like that as thorpe mentioned. Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158237 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 localhost needs to be a string...[code=php:0]mysql_connect("localhost",$username,$password);[/code]but the problem appears to be within your mysql servers configuration. Google for the specific error. Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158239 Share on other sites More sharing options...
ardyandkari Posted January 11, 2007 Author Share Posted January 11, 2007 [quote author=thorpe link=topic=121933.msg502237#msg502237 date=1168523879]localhost needs to be a string...[code=php:0]mysql_connect("localhost",$username,$password);[/code]but the problem appears to be within your mysql servers configuration. Google for the specific error.[/quote]i dont understand what you mean by "string", do you mean it has to be the web address?also, i have hosting through godaddy, so i dont think that it is something with the server.thanks Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158593 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 [quote]i dont understand what you mean by "string"[/quote]It needs to be within quotes as in my example. Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158598 Share on other sites More sharing options...
ardyandkari Posted January 11, 2007 Author Share Posted January 11, 2007 thanks alot.ill try that in a bit. Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158608 Share on other sites More sharing options...
ardyandkari Posted January 11, 2007 Author Share Posted January 11, 2007 changed to string.now it returns this error:Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in (path to php script) on line 24Unable to select database Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158621 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 As Ive said. Something is misconfigured on the database server. Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158628 Share on other sites More sharing options...
ardyandkari Posted January 11, 2007 Author Share Posted January 11, 2007 emailed godaddy to get location of mysql.sock.hopefully they dont say that i have to check the code. if they do....well >:( :o >:(!thanks so much for all the help. Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158636 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 You dont need to know the location of the socket, there is nothing you can do about it.Id'e check to make sure your meant to be using "localhost" Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158646 Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 GoDaddy hosting does not use localhost. You need the specific server. You can find it in your setup.Go into Control Panel, MySQL, then click on the first icon in the list of three, the tooltip says View Connection Strings Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158656 Share on other sites More sharing options...
Draicone Posted January 11, 2007 Share Posted January 11, 2007 This line:[code]mysql_connect(mysql.someserver.net,$username,$password);[/code]Should be ok without the quotes, because PHP will look for a defined value of each of those names, throw an error and then assume they are all one string (including the dots). Ask godaddy for your MySQL server, not the path to the local socket. Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158702 Share on other sites More sharing options...
ardyandkari Posted January 12, 2007 Author Share Posted January 12, 2007 ok...it connects now........THANKS to all who have helped out!!! it is super appreciated. Grinnow...i tried the form, it comes back with no errors, which i assume means that everything went well.but when i check the database, it doesn't show that there are any records. does it take some time for the entries to get put into the database? i took all the code from a tutorial page, so i was assuming that everything worked until i was directed to a syntax error earlier...thanks in advance...ardy Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158846 Share on other sites More sharing options...
trq Posted January 12, 2007 Share Posted January 12, 2007 [quotes]Should be ok without the quotes, because PHP will look for a defined value of each of those names, throw an error and then assume they are all one string[/quote]Brilliant advice to leave it then huh? Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-158859 Share on other sites More sharing options...
ardyandkari Posted January 12, 2007 Author Share Posted January 12, 2007 ok...i checked the mysql account and it says that i have 0 records. im lost.ill post the code again...[code]<?$hostname="mysql.someserver.net";$username="blah blah";$password="not really";$dbname="database";$usertable="table";$first=$_POST['name'];$last=$_POST['type'];$phone=$_POST['phone'];$mobile=$_POST['city'];$fax=$_POST['county'];$email=$_POST['email'];$web=$_POST['web'];$description=$_POST['description'];mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");mysql_select_db($dbname);$query = "INSERT INTO customers VALUES ('$name','$type','$phone','$city','$county','$email','$web','description')";mysql_query($query);mysql_close();?>[/code]like i said...the php page doesnt return an error anymore, but it also doesnt input any data into my database...just a long shot, tell me if i am right...if i use the GET command it will not affect the db either, because GET doesnt place data, it only "get"s it......... Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-159040 Share on other sites More sharing options...
redbullmarky Posted January 12, 2007 Share Posted January 12, 2007 change this line:[code]mysql_query($query);[/code]to[code]$result = mysql_query($query) or die(mysql_error());[/code]which should tell you if there's a problem with your query. Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-159041 Share on other sites More sharing options...
ardyandkari Posted January 12, 2007 Author Share Posted January 12, 2007 you guys are awesome!!! :Dthanks alot redbullmarky for the fix.i am super grateful to you for allowing me to pick your brains...as i learn php more, i hope to be able to actually contribute to the site. thanks again to everyone for all the help, and i will probably be back!laterardy Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-159062 Share on other sites More sharing options...
ardyandkari Posted January 12, 2007 Author Share Posted January 12, 2007 locked... Link to comment https://forums.phpfreaks.com/topic/33741-using-php-to-access-mysql-database/#findComment-159064 Share on other sites More sharing options...
Recommended Posts