Jump to content

Variable Not Storing


sorensens

Recommended Posts

^.^;; 2nd question of the day. For some reason my $to_id isn't storing in either p_messages or p_messages_sent but everything else is just fine. So, here are the two pages.

The Form: [code]
<?php
include 'cookie.php';
include 'adminbar.php';
include 'db.php';
?>
<form action="sendpm.php" method="post">
  <table border="0" cellspacing="0" cellpadding="2">
    <tr>
      <td>Recipient:</td>
      <td> <select name="to_id" id="to_id">
      <?php
$query = "SELECT name, id
          FROM membership
          WHERE status='Y' and name like '$a%'
          ORDER BY name ";
$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) !=0)
{
    while($row = mysql_fetch_array($result))
    {
        extract($row);
        echo "<option value=\"$id\">$name</option>";
    } #while
} ?>
        </select></td>
    </tr>
    <tr>
      <td>Subject: </td>
      <td><input type="subject" name="subject"></td>
    </tr>
    <tr>
      <td>Message:</td>
      <td><textarea name="message" rows="15" cols="65"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="submit" type="submit" value="Send PM"></td>
    </tr>
  </table>
  <p>&nbsp;  </p>
</form>
[/code]

The Script: [code]<?php
// sendpm.php

// Send PM to users
//=================================
// put database connection stuff here
include 'db.php';

// set variable for global_register off
$subject = mysql_escape_string(trim(strip_tags($_POST['subject'])));
$message = nl2br(mysql_escape_string(trim(strip_tags($_POST['message']))));
$to_id = strtolower(mysql_escape_string(trim(strip_tags($_POST['to_id']))));

$member = $_COOKIE['member']; // change to the cookie name u gave for the login

if (empty($subject) || empty($message) || empty($to_id))
{
    die('Error. All fields must be filled in.');
}    

// Now check if recipient is a valid member
$qCheck = "select id from membership where lower(name) = '$to_id' limit 1";
$rsCheck = mysql_query($qCheck)  or die(mysql_error());

if (mysql_num_rows($rsCheck) !=0)
{
    die ('Error, recipient is not a member in the system. ');
}
$row = mysql_fetch_row($rsCheck);
$id = $row[0];        // set the id value returned by the query to $id

// Obtain the sender id from the system
$qID = "select id from membership where name='$member'  limit 1";
$rsID = mysql_query($qID)  or die(mysql_error());
$drow = mysql_fetch_array($rsID);
$sender_id = $drow[0];

// Now insert the PM into the database
$qNew = "insert into p_messages (id, sender_id, subject, message, to_id, sentdate)
                VALUES ('','$sender_id','$id','$subject','$message', now())";
$rsNew = mysql_query($qNew) or die(mysql_error());

if ($rsNew)
{
    $qNew2 = "insert into p_messages_sent (id, sender_id, subject, message, to_id, sentdate)
                VALUES ('','$sender_id','$id','$subject','$message', now())";
    $rsNew2 = mysql_query($qNew2) or die(mysql_error());
    echo '<p>Thank you, PM has been sent to recipient.</p>';
}
else
{
    echo '<p>Error, Cannot send PM to recipient.</p>';
}
?> [/code]
Link to comment
Share on other sites

i only see the underside code

i say other question about your write if you write trimness others see your code will feel bettor you say? :)

[b]<select name="to_id" id="to_id">
<?php
$query = "SELECT name, id
FROM membership
WHERE status='Y' and name like '$a%'
ORDER BY name ";
$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) !=0)
{
while($row = mysql_fetch_array($result))
{
extract($row);
echo "<option value=\"$id\">$name</option>";
} #while
} ?>
</select>[/b]

because [b]$to_id = strtolower(mysql_escape_string(trim(strip_tags($_POST['to_id']))));[/b] so the [b]$_POST['to_id'][/b] must have value

Link to comment
Share on other sites

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.