php /mysql connection issue

Dear Friend,

I am a beginner in php/mysql and trying to connect my database from a php script to add some info.

But the script doesn’t deliver the info to mysql, your further assistance will be appreciated.


Here is a quick example with some comments for you:

// Connecting to MySQL database
$mysqlink=mysql_connect(HostName,UserName,Password) or die(mysql_error());

// Selecting database

// Querying data
$r=mysql_query(“SELECT * FROM yourtable where id=1”);

// Display full record
echo '<pre>';
echo '</pre>';


// Adding record
mysql_query(“INSERT INTO yourtable (id,yourfield1,yourfield2) VALUES (2,‘Value 1’,‘Value 2’)”);

// Updating record
mysql_query(“UPDATE yourtable SET yourfield1=‘New Value 1’, yourfield2=‘New Value 2’ where id=2”);


Hope this helps :slight_smile:

Thank you Sir , but it still doesn’t work, here is my script.thank you for your time(it is a learning project)

<? php define=("DBName" , "..............." ); define= ("HostName",:"............"; define=("UserName", "............"); define=("Password", "............"); $db=mysql_connect ( HostName, UserName,Password) or die(mysql_error()); mysql_select_db(DBName, $db); global $db ; // need the connection $query= 'INSERT INTO ecomm_products (product_code, name, description, price) VALUES ("00001", "Trwy logo t-shirt", 17.95), ("00002", "some else", 5,95), mysql_query ($query, $db) or die (mysql_error ($db)); echo ' no way'; ?>

What exactly is not working, are you getting error message? Is database created? You can try debugging, and also turn on notices/warnings/errors using error_reporting() function.

When I save the script , a blank page comes up with no error ,
Nothing just blank


Looks like your syntax is not correct:[php]define=(“DBName” , “…” );
define= (“HostName”,:"…";
define=(“UserName”, “…”);
define=(“Password”, “…”);[/php]

here is correct code:[php]define(“DBName” , “…” );
define(“UserName”, “…”);
define(“Password”, “…”);[/php]

NO = sign.

Sponsor our Newsletter | Privacy Policy | Terms of Service