justlukeyou Posted December 3, 2012 Share Posted December 3, 2012 (edited) Hi, I can echo the id number of a member. "The ID Number is 239." I am now trying to enter number of the user as the organiserid. I can insert eventname into the table but I am struggling to add the id number. Can anyone advise how I should be doing this please. <div class="boardintro"> The ID Number is <?php echo (!empty($row['id'])) ? $row['id'] : ''; ?> </div> <?php if(isset($_POST['createevent'])){ $organiserid = trim($_POST['$id']); $eventname = mysql_real_escape_string(trim($_POST['eventname'])); { $query = mysql_query("INSERT INTO table (eventname, organiserid) VALUES ('" .$eventname."', '" .$organiserid."')"); if($query) { } else { $error = "There was a problem with the submission. Please try again."; } } } ?> Edited December 3, 2012 by justlukeyou Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 3, 2012 Share Posted December 3, 2012 "I am struggling" does not define your problem? What is it doing that it shouldn't, or what is it not doing that is should? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) The code does not insert the id from table1 into table2. I can echo the id from table1. I can insert a question into table2 but I cant insert the users ID when they ask a question. Edited December 3, 2012 by justlukeyou Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 3, 2012 Share Posted December 3, 2012 Have you tried echoing mysql_error() ? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted December 3, 2012 Author Share Posted December 3, 2012 No. I think its this code which is wrong? Ive tried around 10 different variants but cant get any to work. Does this look right? $organiserid = trim($_POST['$id']); Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 3, 2012 Share Posted December 3, 2012 (edited) No. I don't believe you can post a variable. Even if you can you have it in single quotes which will not parse it's value Edited December 3, 2012 by SocialCloud Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted December 3, 2012 Author Share Posted December 3, 2012 Oh right. Is there a standard way of posting data from one table to another? Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 3, 2012 Share Posted December 3, 2012 Selecting from it getting the row and assigning it to a variable. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted December 3, 2012 Author Share Posted December 3, 2012 Okay, so Im selecting it from the database and I can echo it. How do I allocate it to a variable. So to transfer a variable from one table to another table I have to allocate it to a variable first? <?php $query = "SELECT * FROM users WHERE id = " . intval($_SESSION['userID']) . " LIMIT 1"; if ($result = mysql_query($query)) { $row = mysql_fetch_array($result); } ?> Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) Sorry, thought I had it. Edited December 3, 2012 by justlukeyou Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 If you are using mysql_fetch_array you can use: $id = $row['name of your column that contains the id']; Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted December 5, 2012 Author Share Posted December 5, 2012 Brilliant, thanks. I just need to do this and it worked fine: $organiserid = $row['id']; Quote Link to comment 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.