Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:38:47+00:00 2026-06-13T01:38:47+00:00

Please whats wrong with this code? Im using it to add some data to

  • 0

Please whats wrong with this code?

Im using it to add some data to database but im getting empty $toid and $toname when trying to insert.

This is the form. The variables $toid and $toname are ok here.

//write new message
if (isset($_GET['action']) && $_GET['action'] == compose) { 
        if (isset($_GET['toid'])) {
            $toid = $_GET['toid'];
            $tosql = "select * from authors where id =".$toid.""; 
            $toquery = mysql_query($tosql,$connection) or die(mysql_error());
            $torow = mysql_fetch_array($toquery);   
            $toname = $torow['displayname'];
        if (isset($_GET['subject'])) { $subject = $_GET['subject']; }
        if (isset($_GET['message'])) { 
            $message = $_GET['message']; 
            echo "<h3>Replying</h3>
            <table>
                <tr>
                    <td colspan='2'>Replying to ".$toname.".</td>
                </tr>
                <tr>
                    <td colspan='2'>".$subject."".nl2br($message)."<br />
                    </td>
                </tr>
            </table><br />Type your answer:<br /><br />";
        } else { echo "New message"; }
        echo "<form action=\"mail.php?action=send\" method=post>
            <table>
                <tr>
                    <td>To:</td><td><input type=\"text\" name=\"to\" size=\"50\" value=\"".$toname."\"></td>
                </tr>
                <tr>
                    <td>Title:</td><td><input type=text name=subject size=50 value=".$subject."></td>
                </tr>
                <tr>
                    <td valign=\"top\">Message:</td><td><textarea  rows=\"10\" cols=\"70\" name=\"message\"></textarea></td>
                </tr>
                <tr>
                    <td align=\"right\" colspan=\"2\"><input id=\"submitstyle\" type=\"submit\" value=\"Enviar Mensagem\"></td>
                </tr>
            </table>
        </form>"; 
        }
} 

Here is the code to insert the message to databse, the $toid and $toname are empty here. Its suposed to being retrieved from the form above, right?

//send message  
if (isset($_GET['action']) && $_GET['action'] == send) { 

    if ($subject == "" || $message == "") {
        header('Location: mail.php?action=compose&toid='.$toid.'&subject=\''.$subject.'\'&sendpm=false');
        exit(); 
    }

    $date = DATE(YmdHis); 

    echo $userid."from<br />to".$toid."<br />toname".$toname;

    $sendsql = "INSERT INTO mail (sender, reciever, subject, message, created_at, status, sender_deleted, reciever_deleted) 
                        VALUES (".$userid.", ".$toid.", ".$subject.", ".$message.", ".$date.",unread, 0, 0)"; 
    $sendquery = mysql_query($sendsql,$connection) or die(mysql_error());

    echo "<div class=\"alert\" style=\"text-align: center; margin-top: 13px;\"><b>Mensagem particular enviada com sucesso!</b></div>
            <br /><table align=\"center\" width=\"75%\" class=\"sortable\">
                <tr>
                    <td colspan='2' style=\"text-align:center;font-weight:normal;\">Mensagem particular enviada para ".$toname.".</td>
                </tr>
                <tr>
                    <td colspan='2'>
                        Title: ".$subject."
                        Message: ".nl2br($message)."

                    </td>
                </tr>
            </table>";
}

Im also getting this sql error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' RE: assunto3, 3, 20121017023723,unread, 0, 0)' at line 2 wich i think its because of the empty variables mentioned.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:38:48+00:00Added an answer on June 13, 2026 at 1:38 am

    First, you need to pass those variables as hidden form values: http://www.echoecho.com/htmlforms07.htm

    Then you need to get the variables from the form via $_POST.

    Try $toid = $_POST[‘toid’] and $toname = $_POST[‘toname’]. But be wary about SQL injection: http://php.net/manual/en/security.database.sql-injection.php

    Don’t just accept values blindly from $_POST. Be sure to validate and filter them first.

    Or if toid/toname aren’t changable by the user, why not just requery for them?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please tell me whats wrong with this code. I'm not getting complete
Please, help me. I dont know what is wrong with this code: import android.appwidget.AppWidgetProvider;
whats wrong with this? anybody help me please.. if(stripos($nerde, $hf) !== false) && (stripos($nerde,
Why doesn't this code work? Probably I've done somethig wrong, but I can't find
In my java code,I am retrieving some multibyte data from database and making some
Can someone please tell me what's wrong with this sp. The logic seems to
Can anyone please point out what im doing wrong with this Stored Procedure please.
Please, what is wrong with this: Form2_Closing: Form1.DataGridView1.Rows[0].Cells[1].Value = 323; Error: Index was out
Can somebody please tell me what is wrong with the following pom.xml? i'm getting
I am using C# code and Tridion(CMS) classes to fetch data from Tridion, below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.