Posting values PHP/mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

Posting values PHP/mysql

Post by mikes1471 »

Hi guys

Im just looking to establish the reason all the desired values from my code are not being posted to my database as intended, the only values posted seem to be $msgto, $msgsubject and $msg:

New_message.php

Code: Select all

<?php
session_start();
include('design/header.php');
require('connect.php');
$user=$_SESSION['username'];
$msgfrom=$_GET[$id];
?>
<form name="message" action="messageck.php"
method="post">
 To: <br>
 <input type="text" name="msgto"><br>
 Title: <br>
 <input type="text" name="msgsubject"><br>
Message: <br>
<textarea rows="10" cols="60" name="msg">
</textarea><br>
<input type="submit" value="Submit">
<?php
echo '<input type="hidden" name="msgfrom" value="'.$user.'"><br>';
 
include("design/footer.php");
?>
 
</form>
Messageck.php

Code: Select all

<?php
session_start();
include('design/header.php');
require('connect.php');
 
$msgsubject=$_POST['msgsubject'];
$msgto=$_POST['msgto'];
$msg=$_POST['msg'];
$msgfrom=$_POST['msgfrom'];
$msgdate=$_POST['msgdate'];
$userid=$_POST['id'];
 
$ck_reciever = "SELECT username FROM users WHERE username = '".$msgto."'";
 
        
        if( mysql_num_rows( mysql_query( $ck_reciever ) ) == 0 ){
die("The user you are trying to contact does not exist. Please go back and try again.<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
");
}
elseif(strlen($msg) < 1){
die("Your can't send an empty message!<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
");
}
elseif(strlen($msgsubject) < 1){
die("You must have a Title!<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
");
}else{
mysql_query("INSERT INTO users (msgfrom, msgto, msgsubject, msg, msgdate, userid) VALUES ('$msgfrom','$msgto','$msgsubject','$msg','$date','$id')") OR die("Could not send the message: <br>".mysql_error());
echo "The Message Was Successfully Sent!";
echo $msgsubject;
echo $msgto;
echo $msgfrom;
echo $msg;
echo $msgdate;
echo $userid;
?>
<form name="back" action="inbox.php"
method="post">
<input type="submit" value="Back to The Inbox">
</form>
<?php
}
 
include("design/footer.php");
?>
Is there an obvious reason why this doesnt work for the other values? I've echoed the values on messageck.php and confirmed its only the three values being carried accross
User avatar
Robert07
Forum Contributor
Posts: 113
Joined: Tue Jun 17, 2008 1:41 pm

Re: Posting values PHP/mysql

Post by Robert07 »

Hello,
I don't see a date or an id parameter in the form, that's why those aren't appearing in the second file. If you aren't getting the msgfrom param either you might try moving the hidden input up above the submit button in the code.
Regards,
Robert
Post Reply