justlukeyou Posted December 3, 2012 Share Posted December 3, 2012 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."; } } } ?> Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/ 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? Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397323 Share on other sites More sharing options...
justlukeyou Posted December 3, 2012 Author Share Posted December 3, 2012 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. Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397325 Share on other sites More sharing options...
MDCode Posted December 3, 2012 Share Posted December 3, 2012 Have you tried echoing mysql_error() ? Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397326 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']); Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397327 Share on other sites More sharing options...
MDCode Posted December 3, 2012 Share Posted December 3, 2012 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 Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397328 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? Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397330 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. Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397331 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); } ?> Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397333 Share on other sites More sharing options...
justlukeyou Posted December 3, 2012 Author Share Posted December 3, 2012 Sorry, thought I had it. Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397336 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']; Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397345 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']; Link to comment https://forums.phpfreaks.com/topic/271561-insert-id-number-into-database/#findComment-1397751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.