justAnoob Posted April 11, 2009 Share Posted April 11, 2009 Check out the commented lines <?php session_start(); include "connection.php"; mysql_connect("$host", "$username", "$password") or die("Could not connect."); mysql_select_db("$db_name") or die("Could not find database"); $sendto = mysql_real_escape_string($_POST['sendto']); $subject = mysql_real_escape_string($_POST['subject']); $message = mysql_real_escape_string($_POST['message']); $findit = $_SESSION['id']; //if i comment this line out,, of course the user_id does not get inserted into the database $from = $_SESSION['id']; // so why wouldn't this line work, can i not use 2 variables from the same session variable $result=mysql_query("SELECT id FROM members WHERE username = '$findit'"); $row=mysql_fetch_assoc($result); $user_id = $row['id']; $sql = "INSERT INTO member_messages(user_id, sendto, subject, message, from)VALUES('$findit', '$sendto','$subject','$message', '$from')"; mysql_query($sql) or die('There was an error.'); mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 11, 2009 Share Posted April 11, 2009 that should be working, add error_reporting(E_ALL); after session_start(); Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 11, 2009 Share Posted April 11, 2009 echo $_SESSION['id']; and see if it even has the value you expect. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted April 11, 2009 Author Share Posted April 11, 2009 i did the echo of $_SESSION['id'] and it came back as whatever user I am signed in as,, which is good. no problems there. When i echo $from, it comes back as the username also,,, great,,, but when I echo both $findit and $from,,,, nothing appears,,, just gives me my sql error. What is going on???? Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 11, 2009 Share Posted April 11, 2009 user_id in the database, is it capable of taking usernames? can it hold enough characters, etc... Quote Link to comment Share on other sites More sharing options...
justAnoob Posted April 11, 2009 Author Share Posted April 11, 2009 user_id in the database gets inserted just fine...... it's the from($from) that is getting the problem.. if i take out the $from variable of the script,, everthing works fine.. the "from" row in the database is varchar with more than enough characters. I don't understand what is going on. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 11, 2009 Share Posted April 11, 2009 instead of reassigning $_SESSION['id'], you try just simplifying and putting $_SESSION['id'] straight into your query? $result=mysql_query("SELECT id FROM members WHERE username = '".$_SESSION['id']."'"); $row=mysql_fetch_assoc($result); $user_id = $row['id']; $sql = "INSERT INTO member_messages(user_id, sendto, subject, message, from)VALUES('".$_SESSION['id']."', '$sendto','$subject','$message', '".$_SESSION['id']."')"; mysql_query($sql) or die('There was an error.'); Quote Link to comment Share on other sites More sharing options...
justAnoob Posted April 11, 2009 Author Share Posted April 11, 2009 Here is all the code,,, form and script... Please remember that the $findit variable works just fine with getting inserted into the mysql row user_id.... that is not the problem... just getting the userid again for the mysql row "from" <form id="form5" name="form5" method="post" action="sendnew.php"> <table width="945" height="215" border="0" cellpadding="0" cellspacing="3"> <tr> <td width="88"><div align="right">Send to:</div></td> <td width="481"><input name="sendto" type="text" id="sendto" size="35" /></td> </tr> <tr> <td><div align="right">Subject:</div></td> <td><input name="subject" type="text" id="subject" size="35" /></td> </tr> <tr> <td height="115"><div align="right">Message:</div></td> <td><textarea name="message" id="message" cols="65" rows="7"></textarea></td> </tr> <tr> <td height="19"><div align="right">From:</div></td> <td><?php echo $username; ?></td> </tr> <tr> <td height="19"> </td> <td> <div align="left"> <input type="submit" name="submit" id="submit" value="Send Message" /> </div></td> </tr> </table> </form> and the script <?php session_start(); include "connection.php"; mysql_connect("$host", "$username", "$password") or die("Could not connect."); mysql_select_db("$db_name") or die("Could not find database"); $sendto = mysql_real_escape_string($_POST['sendto']); $subject = mysql_real_escape_string($_POST['subject']); $message = mysql_real_escape_string($_POST['message']); $findit = $_SESSION['id']; $result=mysql_query("SELECT id FROM members WHERE username = '$findit'"); $row=mysql_fetch_assoc($result); $user_id = $row['id']; $sql = "INSERT INTO member_messages(user_id, sendto, subject, message, from)VALUES('$findit', '$sendto','$subject','$message', '".$_SESSION['id']."')"; mysql_query($sql) or die('There was an error.'); mysql_close(); ?> 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.