1

I'm just trying to insert some variables into a DB. The connection works but I keep getting a query error.

Here's the HTML:

<form action="process-step1.php" method="post">

    <div id="fromDiv" class="clearfix">
        <h4>Your Name</h4>
        <input type="text" name="from" id="from" value="" />
        <h4>Your E-mail</h4>
        <input type="text" name="fromemail" id="fromemail" value="" />
    </div>

    <div id="toDiv" class="clearfix">
        <h4>Recipient Name</h4>
        <input type="text" name="to" id="to" value="" />
        <h4>Recipient E-mail</h4>
        <input type="text" name="toemail" id="toemail" value="" />
    </div>

    <div id="messageDiv" class="clearfix">
        <h4>Message</h4>
        <textarea name="message" id="message"></textarea>
    </div>

    <div id="submitDiv" class="clearfix">
        <input type="submit" value="Preview my Card" name="submit" id="submit" />
    </div>

</form>

Here is the PHP Process:

$from = mysql_escape_string($_POST['from']);
$fromemail = mysql_escape_string($_POST['fromemail']);
$to = mysql_escape_string($_POST['to']);
$toemail = mysql_escape_string($_POST['toemail']);
$message = mysql_escape_string($_POST['message']);

$query = "INSERT INTO cards (fromemail, from, to, toemail, message, stamp) VALUES ('$fromemail', '$from', '$to', '$toemail', '$message', 'now()' )";
$results = mysql_query($query);

Any help would be appreciated. Thanks in advance.

2 Answers 2

1

Escape the reserved word - To and From.

$query = "INSERT INTO cards (fromemail, `from`, `to`, toemail, message, stamp) VALUES 
           ('$fromemail', '$from', '$to', '$toemail', '$message', 'now()' )";
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this answer. I have changed the field/variable names and it worked.
0

Try this

$query = "INSERT INTO cards (fromemail, from, to, toemail, message, stamp) VALUES ('".$fromemail."', '".$from."', '".$to."', '".$toemail."', '".$message."', '".now()' )";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.