i have created a database initially and had framed only one table.

The php script was working fine , i could store values and reterive from them.

I again created one more table in the same database , inorder to store data in it. but the PhP script is by default accessing the first table in the same DB rather than accessing the second one.
Is there any way to specify the table name..?

or will i have to create one more DB for the table ..?

Might want to show the code so we can point out what to change

<html>
<head>
     <title> The aliens abducted me </title>

</head>

<body>
    <h2> The final report </h2>

<?php
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$name = "$fname" .' '."$lname";
$email = $_POST['email'];



$msg = "Thanks for aubmitting the form $name". '<br/>' .
       " this is ur email is : $email".'<br/>'."we will get back to you ASAP \n we have stored the data in our database";

echo $msg;

$dbc = mysqli_connect('localhost','root','','aliendb') or die('error connecting to MySql');

$query = "INSERT INTO alien(fname,lname,email)".
         "VALUES ('$fname','$lname','$email')";

$result = mysqli_query($dbc , $query) or die('Error processing the query');

mysqli_close($dbc);

?>


</body>
</html>

intially aliendb had only one table alien .
Now i have added one more called as store.
I want the script to store the values in the other table (store).

You can use mysql_select_db to change the database. And neither PHP or MySQL automatically select a table or a DB. As you can see in the query it's inserting into alien and in the mysql_connect function it's using the aliendb database

well i have indeed chosen the aliendb (database) . But the whole point is , by doing so its inserting the values by default in the first table (alien).
But i want to insert the data in the second table of the same DB , which is store. So how do i select the other table inside the DB ?

well i have indeed chosen the aliendb (database) . But the whole point is , by doing so its inserting the values by default in the first table (alien).
But i want to insert the data in the second table of the same DB , which is store. So how do i select the other table inside the DB ?

You aren't locked into tables, only the database. So once you select the database you can use SELECT/INSERT/UPDATE/etc. on any table in that database. You might want to read up on a few MySQL tutorials (take a look at w3schools) to see how to work on different tables.

actually i got it .. i couldnt believe i overlooked on that....

i just had to change the table name in
INSERT INTO query instead of alien i wrote store and now its functioning.

Ne ways thanks for ur help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.