Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse error, trying to update MySQL table w/ form & PHP 1

Status
Not open for further replies.

DiamondLil

Technical User
Jul 16, 2002
107
US
Argggg...help! Ok, the page is here:

I have it connecting to the MySQL server, pulling & displaying information from a table on the server called prologiloads.

Then I have a form with 5 fields that when a user clicks submit, it <SHOULD> insert those values into that table. I keep getting a parse error. I can't get it to work and I'm so frustrated I can't see straight. Please, can someone help?

I'm using <form action=&quot;edit.php&quot; method=&quot;post&quot;> which is probably wrong but I tried <FORM TARGET=&quot;<?php echo $PHP_SELF; ?>&quot; METHOD=GET> as well and that didn't work.

Below is the code that I keep getting errors on:

<?php

if ($newentry == &quot;submit&quot;) {
$sql = &quot;INSERT INTO prologiloads SET
loaddate='$loadavaildate',
origcity='$origcity',
origstate='$origstate',
destcity='$destcity',
deststate='$deststate';

if (!@mysql_query($sql)) {
echo (&quot;<p>Your entry has been added.</p>&quot;);
} else {
echo (&quot;<p>There has been an error adding your entry: &quot; .
mysql_error() . &quot;</p>&quot;);
}

}

//mysql_close();
?>
 
don't use braces with your echo statements.
and

$sql = &quot;INSERT INTO prologiloads SET loaddate='$loadavaildate', origcity='$origcity', origstate='$origstate', destcity='$destcity', deststate='$deststate'&quot;;
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
note the last &quot; added to your sql= &quot;blah &quot;<---; ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
When do you assign the values of HTML variables to a PHP variables...
you must use something like $GLOBALS[&quot;var in a form&quot;] to get the value you posted in the form or something like $HTTP_POST_VARS
Someone who has never served other is someone that has never lived...
 
hi,

ur sql query should be,

$sql = &quot;INSERT INTO prologiloads (loaddate,origcity,origstate,destcity,deststate) values
('$loadavaildate','$origcity','$origstate','$destcity','$deststate');



 
HI guys!
Thanks for the responses! Yes, KarveR ,those parenthesis were part of the problem. I took them out like you suggested. It's tough, I'm new to this and I'm referring to so many different sources and scripts - and it seems like everybody does things differently.

And whoops-I'm a dingbat on forgetting the end &quot; . Got it now, though. Thanks.

No errors right now - but it's not passing the variables. I guess that's where daca, your $GLOBALS[&quot;var in a form&quot;] or $HTTP_POST_VARS comes in. Where In the script would I put it? Is the syntax just $GLOBALS[&quot;the names of all the variables-with or without the $?&quot;]

 
Ah - another question....

I haven't heard back yet from the hosting co. as to whether or not the Register_globals is on or off in the PHP.ini file.

DACA - would declaring the variables like you suggest work if the register globals is off or is there some way I have to work around that?
 
Using $HTTP_*_VARS or $_* works whether or not register_globals is on. You should replace the * with the method used for the form or SESSION or whatever variables you want to access. $_* is for PHP 4.1+ and $HTTP_*_VARS is for earlier versions. //Daniel
 
Thank you guys for the help the other day - I was pulled onto another project but now I get to come back to this.

I've tried to star your posts, because you've answered my questions (rockin'!) - but everytime I try my browser freezes right after the pop up window opens.

I'll try again soon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top