Jump to content

Error trying to write to MySQL


Recommended Posts

I'm busy trying to do my first php to MySQL project using Dreamweaver MX.

 

I have a pretty straight forward form, but when I hit the "submit" button, I get the following error:

 

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/breforml/public_html/patientSubmissionScript.php on line 14

 

Now, the code in my INSERT script looks like this:

 

<?php

//open the connection

$conn = mysql_connect("localhost", "breforml_kevin", "joshcam1");

//pick the database to use

mysql_select_db ("breforml_main", $conn);

//create the sql statment

$sql = "INSERT INTO main values('','$_POST[fName]','$_POST[sName]', '$_POST['patientAge'],

'$_POST', '$_POST[cupSize]', '$_POST[chest]', '$_POST[hTel]', '$_POST[wTel]', '$_POST[cTel]',

'$_POST[financeReq]', $_POST[patientsubscribe]','$_POST[comments]')";

//execute the sql statement

if (mysql_query($sql, $conn)){

echo "Thank you! You have been added to our database and we will contact you shortly.";

} else{

echo "Sorry, but something went wrong with your enquiry. Please go back and ensure that all fields have been completed.";

}

?>

 

Can anybody help me with this? :(

Link to comment
Share on other sites

You've got an error at the $_POST[patientAge] variable. Try this:

$sql = "INSERT INTO main values('','$_POST[fName]','$_POST[sName]', '$_POST[patientAge]', 
'$_POST[eMail]', '$_POST[cupSize]', '$_POST[chest]', '$_POST[hTel]', '$_POST[wTel]', '$_POST[cTel]',
'$_POST[financeReq]', $_POST[patientsubscribe]','$_POST[comments]')";

Link to comment
Share on other sites

it's only because you use array in string..... just add {} after the $ for var is array

 

$sql = "INSERT INTO main values('','${_POST[fName]}','${_POST[sName]}', '${_POST[patientAge]}', '${_POST}', '${_POST[cupSize]}', '${_POST[chest]}', '${_POST[hTel]}', '${_POST[wTel]}', '${_POST[cTel]}','${_POST[financeReq]}', ${_POST[patientsubscribe]}','${_POST[comments]}')";

 

cocazoulou

 

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.