Jump to content

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

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.