Jump to content

[SOLVED] entering data from one table to another


patelp7

Recommended Posts

does anyone know how to write a statement where you are able to transfer data from one table to another?

 

I have got one table with user details.

 

and I have another table for creating bulletins.

 

is there a statement which will put the ID of the user from user details to bulletins everytime they create a bulletin?

 

Thanks.

$query = "insert into bulletin (Subject, Description, DrComments, Admin_ID) Values ('$Subject', '$Description',

'$Drcomments', '$adminmember.Admin_ID')";

 

is the query i got at the moment, but instead of inserting the Value of $adminmember.Admin_ID, it is entering "Admin_ID"....

yes, you would have to query the table and store the id somewhere. You may want to use sessions to store the id of the user so you do not have to carry it across pages.

 

I assume the person is logging into your sight. When you check the credentials of the user store their id in a session value and then when you run your insert query just insert the session value.

 

Ray

Yes, you have to store it in order to call it. Here is an example that I have used. You can change things

 

login.php

<?php
session_start();
if(isset($_POST['username'])){
  $username = $_POST['username'];
  $password = md5($_POST['password']);
  $getuser = "SELECT * FROM users WHERE username = '$username' AND password = '$password' AND status = '1'";
  $result = mysql_query($getuser) or die (mysql_error());
  $r = mysql_fetch_array($result);
  $qualify = mysql_num_rows($result);
  if($qualify > 0){
    $_SESSION['userid'] = $r['userid'];
    $_SESSION['username'] = $r['username'];
    echo "<META HTTP-EQUIV=\"Refresh\" content=\"2;url=index.php\">";
    echo "<p align=center>Thank you ".$r['firstname'].", you will now be redirected to the home page.</p>";
  } else {
  print '<p align=center>Bad username/password<br>Click <a href="'.$self.'?do=login">HERE</a> to return to login page.';
  }
} else {
// login.html contains the login form only
include('login.html');
}
?>

 

Now at the top of EVERY PAGE you must have session_start() as the first thing

Then in your query on any page just call the id with

$_SESSION['userid'];

 

$query = "INSERT INTO bulletin (Subject, Description, DrComments, Admin_ID) Values ('$Subject', '$Description',
'$Drcomments', '".$_SESSION['userid']."')";

 

Ray

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.