Asked recently on Yahoo! Answers:
Help what do I do? It’s a MySql error… on connecting through php?
Warning: mysql_insert_id(): A link to the server could not be established in /home/www/cwc-3d.awardspace.com/admincp/… on line 163ok. how do i insert the id for the MySql database i cannot figure this out.. PLEASE HELP!!!
You’re probably misusing mysql_insert_id().
That function returns the unique key from the last insert operation. You don’t use it to insert records; you use it to get back from the database the record id of the newly inserted records.
Also, it does sound like you are passing bad credentials to the MySQL server.
View this code sample:
<?php $host = "your database server name"; $user = "username"; $pass = "password"; $dbname = "name of your database"; //connect to database server $link = mysql_connect($host, $user, $pass) or die('Cannot connect to database server.'); //select the database with which you want to work mysql_select_db($dbname) or die('Cannot select database'); //create SQL statement $sql = "INSERT INTO table_name (column_name) VALUES ('some_value')"; //execute statemet $rs = mysql_query($sql) or die(mysql_error()); //get record id for inserted record $id = mysql_insert_id(); //echo to screen echo $id; ?>
