Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/206240-putting-data-into-the-mysql-database/
Share on other sites

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..

 

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!

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 />";
}

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.

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.