Jump to content

need help entry database using php and mysql


loveblue

Recommended Posts

hai .... I need help .....

I have a database table "device" and "event".

column table "device" content "account" and "dev_id".

while in table "event" content "account", "dev_id" and "event".

 

table in the "device" I have the following data:

"account" "dev_id"

  demo    red_car

  demo    blue_car

  admin    red_car

 

I want to insert data to table "event". if there is data entry with "dev_id" blue_car, the data insert to the table there are no problems. the problem appears when there is equality that is "dev_id" red_car because both dev_id are owned by the demo and admin accounts.

 

I want to ask for assistance on how to enter data to the table "event" occurs when conditions such as the above there are similarities "dev_id" red_car. so that data entered is complete all that is

 

"account"    "dev_id"  "event"

  demo      red_car    stop

  admin      red_car    stop

 

here is my php

 

<?

//conn1--------------------------------------------------------------------------------------------------------

$host1="localhost";

$user1="root";

$pass1="cipluk";

$conn1 = mysql_connect("$host1","$user1","$pass1");

mysql_select_db("gts", $conn1);

 

$query_id = "select account from device where dev_id = '$vehicle_id'";

  $jawab = mysql_query($query_id,$conn1);

  while ($row_id = mysql_fetch_array($jawab)) {

  $accid = $row_id['account'];

  }

 

//insert----------------------------------------------------------------------

 

$sql    = "INSERT INTO event(account,dev_id,event) VALUES (";

$sql .= "'". addslashes($accid) . "'";

                $sql    .= ",'" . addslashes($vehicle_id) . "'";

                $sql    .= ",'" . addslashes($event) . "'";

                $sql    .= ");";

echo "Data insertion \r\n".$sql;

mysql_query($sql,$conn1);

 

 

thankyou verry much

 

really need help

It all depends how your inserting the values into the database.

Button,

Page Refresh

Form (linking to a button I guess)

 

Also, I do advise you to not put real database passwords and usernames. Also, I don't see your database name?

It all depends how your inserting the values into the database.

Button,

Page Refresh

Form (linking to a button I guess)

 

Also, I do advise you to not put real database passwords and usernames. Also, I don't see your database name?

 

thanks for the reply......

the database name is gts...

 

I use php socket to receive the data. data processed and entered into the database.

at the time of entering into the database that what I want to ask. when data is selected in the query there are 2 or more how to enter the database.

$query_id = "select account from device where dev_id = '$vehicle_id'";

 

here is what i'v got from the dump

 

string(52) "select account from device where dev_id = 'red_car'"

string(5) "admin"

string(4) "demo"

 

Data insertion INSERT INTO event(account,dev_id,event) VALUES ('demo','red_car','stop')

 

only one data inserted....account demo.

i need admin account is inserted to with data

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.