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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.