Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 902
Athirah Hazira Avatar asked Dec 26 '22 16:12

Athirah Hazira


1 Answers

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`
  • http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
like image 147
Funk Forty Niner Avatar answered Dec 28 '22 10:12

Funk Forty Niner