help! im pretty new at PHP, and im creating a simple pdf form with an html submit document. however, when i hit submit i get this error.
Parse error: parse error, unexpected T_STRING in home/content/c/r/z/crzycm16/html/insert.php on line 42

my form is at http://www.shsinteract.com/vets.pdf
and i am following this tutorial, http://www.andrewheiss.com/Tutorials?page=LiveCycle_PDFs_and_MySQL

My code is as follows,
Thanks for the Help!
Cameron

<?php
$host="p50mysql81.secureserver.net"; 
$username="Vetsform"; 
$password="Amina123"; 
$db_name="Vetsform"; 
$tbl_name="vetform"; 

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$VeteranName=$_REQUEST["VeteranName"];
$Address=$_REQUEST["Address"];
$StateProv=$_REQUEST["StateProv"];
$ZipCode=$_REQUEST["ZipCode"];
$Branch=$_REQUEST["Branch"];
$Dateserved=$_REQUEST["Dateserved"];
$Comments=$_REQUEST["Comments"];
$guestname=$_REQUEST["guestname"];
$Phonenumber=$_REQUEST["Phonenumber"];
$city=$_REQUEST["city"];

$sql="INSERT INTO $tbl_name(VeteranName, Address, StateProv, ZipCode, Branch, Dateserved, Comments, guestname, Phonenumber, city)
VALUES('$VeteranName';
'$Address';
'$StateProv';
'$ZipCode';
'$Branch';
'$Dateserved';
'$Comments';
'$guestname';
'$Phonenumber';
$city')
$result=mysql_query($sql);

if($result){
echo "Successful";
}

else {
echo "ERROR";
}

mysql_close();
?>

Recommended Answers

All 24 Replies

Take out the semicolons after the Values ie.,

$sql="INSERT INTO $tbl_name(VeteranName, Address, StateProv, ZipCode, Branch, Dateserved, Comments, guestname, Phonenumber, city)
VALUES('$VeteranName',
'$Address',
'$StateProv',
'$ZipCode',
'$Branch',
'$Dateserved',
'$Comments',
'$guestname',
'$Phonenumber',
$city')";
$result=mysql_query($sql);

Also, don't do $VeteranName = $_GET['VeteranName']; etc.
just do extract($_REQUEST);

And put commas. :)

Edit: I didn't see shawnCplus edit his post!

And put commas. :)

Where ? lol
Also i took out the ";" and added commas but i now get the 'Error' message :-(

<?php
// MySQL connection variables
$host="server"; 
$username="Vetsform"; 
$password="secret:-)"; 
$db_name="Vetsform"; 
$tbl_name="vetform"; 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//Save data from the HTTP POST values submitted from the PDF
extract($_REQUEST);

// Insert all the data from above into the table in the database
$sql="INSERT INTO $tbl_name(VeteranName, Address, StateProv, ZipCode, Branch, Dateserved, Comments, guestname, Phonenumber, city)
VALUES('$VeteranName',
'$Address',
'$StateProv',
'$ZipCode',
'$Branch',
'$Dateserved',
'$Comments',
'$guestname',
'$Phonenumber',
$city')";
$result=mysql_query($sql);

// If it worked, say so...
// This will change later on so it won't have the like to view all users, obviously...that's just for testing purposes
if($result){
echo "Successful";
}

else {
echo "ERROR";
}

// Close connection to the database
mysql_close();
?>

Be more descriptive with your error messages

$result=mysql_query($sql) or die(mysql_error());

Ok. What is the error now ? Print out the query. (print $sql; ) . Where are you assigning the tablename ($tbl_name) ? and NEVER display your host, username and password :S !

Be more descriptive with your error messages

$result=mysql_query($sql) or die(mysql_error());

sure, but that is honestly what the page says, "error"
if i look at the source code it shows

<b>Parse error</b>:  parse error, unexpected $ in <b>/home/content/c/r/z/crzycm16/html/insert.php</b> on line <b>44</b><br />
</object></layer></span></div></table></body></html>

$city')"; This should have been '$city')" ;

As a side note, you might want to obscure your server, password and username given that you just gave every single google user on earth access to it. If a mod is reading this please take that out for him.

Guys, Thanks for all the help i really appreciate it.
but now i really confused, haha

This is my code as of now.

<?php
// MySQL connection variables
$host="server"; 
$username="Vetsform"; 
$password="secret:-)"; 
$db_name="Vetsform"; 
$tbl_name="vetform"; 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//Save data from the HTTP POST values submitted from the PDF
extract($_REQUEST);

// Insert all the data from above into the table in the database
$sql="INSERT INTO $tbl_name(VeteranName, Address, StateProv, ZipCode, Branch, Dateserved, Comments, guestname, Phonenumber, city)
VALUES('$VeteranName',
'$Address',
'$StateProv',
'$ZipCode',
'$Branch',
'$Dateserved',
'$Comments',
'$guestname',
'$Phonenumber',
$city')";
$result=mysql_query($sql) or die(mysql_error());
// If it worked, say so...
// This will change later on so it won't have the like to view all users, obviously...that's just for testing purposes
if($result){
echo "Successful";
}

else {
echo "ERROR";
}

// Close connection to the database
mysql_close();
?>

and my error when i hit submit is now
"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 '')' at line 11"

mysql_connect("$host", "$username", "$password")or die("cannot connect");

There should be a space between the ) and or

Also, use [code=php] so we can use the line numbers.

umm.. I guess you didn't see what I posted in my previous post ? :S

Thanks guys, between the two of you i got it! i owe ya! any how now to the hard part i guess,
getting back into another pdf document i think is what im suposed to do.

oh i have a question. what is the best way to approach this? i now have it accepting the data, wont every new submit erase the old data?

You mean the script you have here ? No. On every submit, it will add a new record ! (Even if you refresh this page, it will insert a new record! )

awesome! another question, what is thge easyest way to get the data from the Db to a user? like an excel file? or another re-populated pdf? any ideas?

:) the easiest way is to execute a query just like you are doing here.

$query="select * from tablename";
$result=mysql_query($query);
while($row=mysql_fetch_array($result){
  $var=$row['column_name_of_your_table'];
 ....
...
..
.
}

The most simplest way!

i think i understand that, but what about to say another member of our organization ? like can it make a file with all of the data per submit? is that possible?

Can you explain that in detail ? I didn't get you!

Can you explain that in detail ? I didn't get you!

Sure, i apologize,

the direction im heading for is that when someone fills out the form, the data is sent to "somewhere" whether that be an e-mail or on my site in a directory somewhere, essentially, i am setting this up and someone else will be receiving the data, and preferably in the simplest way possible. to be honest i am so new at this i have no idea as to which direction to go . i was following the tutorial, but it is not exactly what i was looking for.

Excel is easier compared to pdfs. Or instead, you can send a mail with all the data fetched from the table.

Excel is easier compared to pdfs. Or instead, you can send a mail with all the data fetched from the table.

What do you suggest, you are the only resident expert i know, excel or mail will work! but do you know any tutorials that can help? or can you? i appreciate all you've done, you are helping me immensely not only with the project, but in learning also.

$city')"; This should have been '$city')" ;

just like nav33n said i think u forget to put [ ' ] in front of $city -> .....'$city')"

mail( "to_address","subject","message details","From: from_address");

In message details, you can send whatever information you want. So, I think this would be better instead of sending a user an excel attachment mail !

mail( "to_address","subject","message details","From: from_address");

In message details, you can send whatever information you want. So, I think this would be better instead of sending a user an excel attachment mail !

Sure, but how do i include the data under details? with a link to the a mysql viewer? should i include this on the submit/ insert page?

Run a query to get all the required data from the table. Put it in the message part.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.