Seaholme Posted June 30, 2010 Share Posted June 30, 2010 All of the information below goes into the database, except for $owner = $_SESSION['id']); I'm not sure why it's not also going in. I tried changing it so that it read $owner = '13'); and even just the number 13 didn't go in. Can anybody help? :/ $name = trim($_POST['name']); $gender = trim($_POST['gender']); $breed = trim($_POST['breed']); $date = date("m/d/y"); $owner = $_SESSION['id']); // Finally, create the record. $newDog = @mysql_query("INSERT INTO dogs (name, gender, breed, date, owner) VALUES ('$name', '$gender', '$breed', '$date', '$owner')") or die("Error: ".mysql_error()); echo 'You have made a new dog, yay!'; } else { Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/ Share on other sites More sharing options...
Pikachu2000 Posted June 30, 2010 Share Posted June 30, 2010 If it's an integer, try it without the single quotes around it in the query string. Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/#findComment-1078973 Share on other sites More sharing options...
Seaholme Posted June 30, 2010 Author Share Posted June 30, 2010 As in $owner = $_SESSION[id]; ? 'Cause that didn't work either! Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/#findComment-1079108 Share on other sites More sharing options...
magnetica Posted June 30, 2010 Share Posted June 30, 2010 Hi Just before this bit $owner = $_SESSION['id']); Have you tried to just print it out and check if $_SESSION actually holds 'id' print $_SESSION['id]; Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/#findComment-1079114 Share on other sites More sharing options...
Goose87 Posted June 30, 2010 Share Posted June 30, 2010 Is it just me or is the code below wrong? $owner = $_SESSION['id']); Remove the bracket and maybe that would help. Like Magnetica said: Just try a print and see if a value comes out. If it does, then the query might be wrong, if it doesn't, then there's something wrong earlier on.. Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/#findComment-1079116 Share on other sites More sharing options...
Seaholme Posted June 30, 2010 Author Share Posted June 30, 2010 Firstly, thanks for everybody's help (: Secondly, I did what you suggested and the print command didn't work, however what I have below DOES work to show up the username and id when I put it on the page, but not the onhand. echo 'Logged in as: <a href=profile.php>'.$_SESSION['username'].'</a> (#'.$_SESSION['id'].') Money: $'.$_SESSION['onhand'].''; ... however, when I put exactly the same PHP in the header, it works to show up the username, id AND onhand. So I'm extremely confused. It won't print the $_SESSION['id'] bit, however it WILL recognise it when it's in the form I have above. And when it's in the header, it'll show up the onhand part, however when I put exactly that same code into the main body of the page, it won't show up the onhand bit any more (but the id and username still show up fine :S)! This is a major headache for me! D: I'd really appreciate it if somebody could explain why it'll show it up in some places and not in others. Let me know if you need any more info. about the rest of the code I'm using! Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/#findComment-1079120 Share on other sites More sharing options...
Pikachu2000 Posted June 30, 2010 Share Posted June 30, 2010 As in $owner = $_SESSION[id]; ? 'Cause that didn't work either! No, I mean where you use its value in the query string: VALUES ('$name', '$gender', '$breed', '$date', $owner) <= unquote the $owner variable, if it is an integer value. And, I don't see it in the posted code, so I have to ask, you DO have a session_start(); at the head of that script, right? Also, Goose87 is right, and there is a typo in the assignment of the $owner variable: $owner = $_SESSION['id']); <= get rid of the last parenthese Then, just after that line, add this block of code to see exactly what is in the $_SESSION array at that point: foreach( $_SESSION as $key => $val ) { echo "Key: " . $key . " - Value: " . $val . "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/#findComment-1079218 Share on other sites More sharing options...
kenrbnsn Posted June 30, 2010 Share Posted June 30, 2010 You do have <?php session_start(); ?> at the beginning of the script, don't you? Ken Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/#findComment-1079227 Share on other sites More sharing options...
runthis Posted June 30, 2010 Share Posted June 30, 2010 I had a same problem, you have something wrong in your actual database, for instance if i a have a field in my structure that is an INT and i try to update it with "pickleeater" it wont tell me there is an error, it just wont go, try changing your field types to match your inserts bro. Quote Link to comment https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/#findComment-1079229 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.