patelp7 Posted March 7, 2007 Share Posted March 7, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/41653-solved-entering-data-from-one-table-to-another/ Share on other sites More sharing options...
patelp7 Posted March 7, 2007 Author Share Posted March 7, 2007 $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".... Quote Link to comment https://forums.phpfreaks.com/topic/41653-solved-entering-data-from-one-table-to-another/#findComment-201852 Share on other sites More sharing options...
craygo Posted March 7, 2007 Share Posted March 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/41653-solved-entering-data-from-one-table-to-another/#findComment-201855 Share on other sites More sharing options...
patelp7 Posted March 7, 2007 Author Share Posted March 7, 2007 would you know how to call a variable from a session? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/41653-solved-entering-data-from-one-table-to-another/#findComment-201869 Share on other sites More sharing options...
craygo Posted March 7, 2007 Share Posted March 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/41653-solved-entering-data-from-one-table-to-another/#findComment-201909 Share on other sites More sharing options...
patelp7 Posted March 7, 2007 Author Share Posted March 7, 2007 Nice one Govnerr!! Quote Link to comment https://forums.phpfreaks.com/topic/41653-solved-entering-data-from-one-table-to-another/#findComment-202059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.