Dan560
asked on
PHP import help
Hi,
I am very new to PHP and MySQL however I do not think this request is too difficult.
I am trying to build a php script that will allow my market managers to enter their company profit factors for the year. The form asks what country they work in and what their profit factors are. It then imports this data into a MYSQL database.
Some sample data looks like this
Market Profit Factor
UK 50
BE 200
DE 80
This works fine, however I would like to know how I can tell my script to just overwrite existing records. As If I enter a profit factor twice then I get two rows of data i.e -
Market Profit Factor
UK 50
UK 50
Is there anyway I can just overwrite the data?
I have attached my php
I am very new to PHP and MySQL however I do not think this request is too difficult.
I am trying to build a php script that will allow my market managers to enter their company profit factors for the year. The form asks what country they work in and what their profit factors are. It then imports this data into a MYSQL database.
Some sample data looks like this
Market Profit Factor
UK 50
BE 200
DE 80
This works fine, however I would like to know how I can tell my script to just overwrite existing records. As If I enter a profit factor twice then I get two rows of data i.e -
Market Profit Factor
UK 50
UK 50
Is there anyway I can just overwrite the data?
I have attached my php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="bonuscalc"; // Database name
$tbl_name="market_values"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$market=$_POST['market'];
$profit_factor=$_POST['profit_factor'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(market, profit_factor)VALUES('$market', '$profit_factor')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER