orangecat Posted February 17, 2011 Share Posted February 17, 2011 I'm helping out a friend who owns a boarding kennel. She would like an online site where she or a client can register, add their dogs to their profile and other info. I know CSS and HTML but have very, very little experience in PHP, I figured it would be fun to give this a try and learn something new. So far I've managed to create a register and log in area, and now I'm trying to make it possible for someone to add a dog breed from a drop down list to their "page" after they've logged in. I cannot get the data to insert into that specific user's table. I'm trying to use the session id and session username as the variable, and this is where the problem comes in. If I type the userid and the username out then the data will update fine...but that's not practical. I need it to know which user is logged in and update them accordingly. Anyway, what I'm typing here makes sense in my head but I've been staring at this computer all day and it's possible I'm way out in left field, so here's the code to see for yourself. (chances are it's something totally obvious....or I have stuff in there that doesn't belong, I haven't a clue.) Thank you in advance to anyone willing to help me out! The form <?php session_start(); $_SESSION['userid']=$userid;?> <html><body> <h4></h4> <form action="process.php" method="post"> <select name="breed" id="breed"> <option value="collie">Collie</option> <option value="aussie">Aussie</option> </select> <select name="sex"> <option>Dog</option> <option>Bitch</option> </select> <input type="submit" /> </form> </body></html> The php for that form <?php session_start(); $_SESSION['userid']=$userid; $_SESSION['Username']=$username;?> <html><body> <?php $host="localhost"; // Host name $username="silver_phptest"; // Mysql username $password="bowser"; // Mysql password $db_name="silver_phptestingbase"; // Database name $tbl_name="users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $breed=$_POST['breed']; // Insert data into mysql mysql_query("UPDATE users SET dogs = '$breed' WHERE userID = '$userid'"); // close connection mysql_close(); ?> </body></html> Quote Link to comment Share on other sites More sharing options...
petroz Posted February 17, 2011 Share Posted February 17, 2011 I dont see where you are setting $userid, but you can try inserting the session data directly into the query... Not recommended, but it should work. mysql_query("UPDATE users SET dogs = '$breed' WHERE userID = '".$_SESSION['userid']."'"); Quote Link to comment Share on other sites More sharing options...
orangecat Posted February 17, 2011 Author Share Posted February 17, 2011 Thanks, I gave that a try but still nothing gets entered into the database. Quote Link to comment Share on other sites More sharing options...
petroz Posted February 17, 2011 Share Posted February 17, 2011 Have you looked at your session cookie to see if there is any data in it? Quote Link to comment Share on other sites More sharing options...
orangecat Posted February 17, 2011 Author Share Posted February 17, 2011 There is data in the cookie but I also use the website domain I'm testing on for other things, so it could be for that instead. How do I make sure my sessions are storing data? 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.