MySQL Forums
Forum List  »  General

Re: access denied ''@'localhost' error
Posted by: Scott Nemes
Date: July 10, 2013 09:25AM

Looks like you are making progress. You are running into the same issue with the insert step as you did with the create table step. You are attempting to insert the record without specifying the connection ($server_connect), plus the connection is already closed at the top before you attempt to insert the record near the bottom.

If you want to follow your current convention, then you should add the below line below your "$tb_create" line near the top of your code:

$insert=mysql_query("INSERT INTO hydi.persons (FirstName,LastName,Age) VALUES ('hydi','nabil',34)", $server_connect);

Then near the bottom replace the part of the IF statement that does the insert with "$insert" to match the rest of your case statements.

That should work in general. However the way your code looks currently I do not think it would output errors as you would expect due to the fact that you run all the statements up top and then check errors at the bottom, so you likely would only capture the last error. All that aside, I would look into using PHP's PDO or Mysqli extensions (see links below) as they are more secure and the standard these days. The manual pages have great examples, so you should be able to redo this pretty quickly if you want. =)

http://php.net/manual/en/book.pdo.php
http://php.net/manual/en/book.mysqli.php

--
Scott Nemes
MySQL DBA

http://www.linkedin.com/in/scottnemes
http://www.twitter.com/ScottNemes

Options: ReplyQuote


Subject
Written By
Posted
Re: access denied ''@'localhost' error
July 10, 2013 09:25AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.