Monday, December 31, 2018

php - One MySQL Database & Multiple Table



How to connect to a certain table in MySQL database?



I have tried :



mysql_select_db("baybeestore",$connection);


but it gives me an error :-




"Error : Table 'baybeestore.form' doesn't exist"


But I've created a table named as order. Are there any PHP codes to connect to my table order in the same database that have multiple databases?



Is it wise enough to create multiple database & one table for one website
or multiple table with one database?



FULL CODE :




$connection = mysql_connect("localhost","user","1234");
if(!$connection)
{
die('Failed to connect to MySQL :' . mysql_error());
}
mysql_select_db("baybeestore",$connection)
$sql = "INSERT INTO
form(name, address, email, handphone, item, payment)

VALUES

('$strname', '$straddress', '$stremail', '$strhandphone', '$stritem', '$strpayment')";

if(!mysql_query($sql, $connection))
{
die('Error : ' . mysql_error());
}
echo "Data have been saved.";
mysql_close($connection);

Answer



As per your edit/added code. Your originally posted code




You're using two different tables for your queries. Result: ERROR



You have SELECT * FROM order and INSERT INTO form 2 different animals altogether.



If anything, that should be INSERT INTO order or SELECT * FROM form yet... ORDER is a reserved word and should be enclosed with backticks.



I.e.:



INSERT INTO `order`




No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...