/    Sign up×
Community /Pin to ProfileBookmark

Query parse error

I’ve been following the PHP/MySQL Tutorial from [URL]http://www.freewebmasterhelp.com/tutorials/phpmysql/4[/URL]. Though, I’ve created a different kind of database based on airport information I need when playing FlightSim98. Also, I set up the table’s structure manually in phpMyAdmin.

Okay.. so I’m trucking along and being sure to follow the tutorial as closely as possible… and I get my two little pages (airports.php and insertairport.php) coded.. I test run it… and BAM! I get a stupid little

[QUOTE]

Parse error: parse error, unexpected ‘,’ in /home/hsphere/local/home/penguine/mindsjourney.net/Lab/insertairport.php on line 33

[/QUOTE]

I go down to line 33 and it reads as thus

[code=php]$query – “INSERT INTO mva_airports VALUES (“,’$id’,’$faaid’,’$name’,’$city’,’$state’,’$country’,’$atis’,’$ndb’,’$vor’,’$elev’,’$lat,’$long’,’$rwy1′,’$rwy2′,’$mva’,’$mve’,’$gates’,’$notes’)”;[/code]

I typed it just like I was told with the exception of changing the table name and input variables.

Just incase you wanna check them, here’s the assign variable lines I typed in at the beginning of the script.

[code=php]
// Declare form variables.
$id=$_POST[‘id’];
$faaid=$_POST[‘faaid’];
$name=$_POST[‘name’];
$city=$_POST[‘city’];
$state=$_POST[‘state’];
$country=$_POST[‘country’];
$atis=$_POST[‘atis’];
$ndb=$_POST[‘ndb’];
$vor=$_POST[‘vor’];
$elev=$_POST[‘elev’];
$lat=$_POST[‘lat’];
$long=$_POST[‘long’];
$rw1=$_POST[‘rw1’];
$rwy2=$_POST[‘rw2’];
$mva=$_POST[‘mva’];
$mve=$_POST[‘mve’];
$gates=$_POST[‘gates’];
$notes=$_POST[‘notes’];
[/code]

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@SanderKMar 04.2005 — Yup, little mistake in your query.
[code=php]$query - "INSERT INTO mva_airports VALUES('$id','$faaid','$name','$city','$state','$country','$atis','$ndb','$vor','$elev','$lat,'$long','$rwy1','$rwy2','$mva','$mve','$gates','$notes')";[/code]

The [u]VALUES('$id',[/u] part, you had a double qoute which had to be a single qoute and a ',' too much.
Copy linkTweet thisAlerts:
@penguineauthorMar 04.2005 — ARG!!! What the hell's the point of making a tutorial if yer gonna give a person the wrong information? I hate it when they write these things then never proofread. :mad:

Okay. Thanks. ?
Copy linkTweet thisAlerts:
@SanderKMar 04.2005 — You could contact them to inform them about the error; they might give you a cookie ?

Also, that code isn't secure it all. You can easily hack your site right now. Check [url=http://phpsec.org/projects/guide/]this site[/url] for some info about security. '2. Form Processing' is what you will need for this.
Copy linkTweet thisAlerts:
@penguineauthorMar 04.2005 — Yeah, I know. I had seen that path.php include somewhere else. I was thinking about that. :S Kinda dumb for this tutorial to teach people to do it without that.

Okay.. I'm having another problem here. No parse errors, but I'm getting my "Unable to add entry" error. :S

Here's the full query code.

[code=php]
// Run query.
$query - "INSERT INTO mva_airports VALUES ('$id,'$faaid','$name','$city','$state','$country','$atis','$ndb','$vor','$elev','$lat,'$long','$rwy1','$rwy2','$mva','$mve','$gates','$notes')";
mysql_query($query);
// Add confirmation and error statements.
if (mysql_query($query)) {
echo 'Success! Entry added.';
}
else {
die("Error. Unable to add entry.");
}
[/code]
Copy linkTweet thisAlerts:
@SanderKMar 04.2005 — Uhm, you do realize you are adding it twice now? You have a 'mysql_query' 2 times in there. First you add it without error checking, then you add it with error checking. Simply get rid of the first 'mysql_query'.
Copy linkTweet thisAlerts:
@penguineauthorMar 04.2005 — Oh. I didn't realize that. Okay.


Ermmm... did that and it's still not working.
Copy linkTweet thisAlerts:
@penguineauthorMar 04.2005 — I'm still getting the ugly "Error: Unable to add entry."

Here's the updated query code

[code=php]
// Run query.
$query - "INSERT INTO airports VALUES ('$faaid','$name','$city','$state','$country','$atis','$ndb','$vor','$elev','$lat,'$long','$rwy1','$rwy2','$mva','$mve','$gates','$notes')";
// Add confirmation and error statements.
if (mysql_query($query)) {
echo 'Success! Entry added.';
}
else {
die("Error. Unable to add entry.");
}
[/code]


Here's the code in the form

[CODE]
<form action="insertairport.php" method="post">
<tr>
<td class="label">Airport ID:</td>
<td class="input"><input type="text" name="faaid" cols="4"></td>
<td class="label">Elevation:</td>
<td class="input"><input type="text" name="elev" cols="5"></td>

</tr><tr>
<!-- yatta yatta -->
</tr><tr bgcolor="333333">
<td align="center" colspan="4"><input type="submit"></td>
</tr>
</table>
</form>
[/CODE]


Here's the php code beneath the form. (Wouldn't be surprised if the tutorial I used told me the wrong way to do it again. :mad: )

[code=php]
<?php
include('config.php');
include('lib.php');

// Declare form variables.
$id=$_POST['id'];
$faaid=$_POST['faaid'];
$name=$_POST['name'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$atis=$_POST['atis'];
$ndb=$_POST['ndb'];
$vor=$_POST['vor'];
$elev=$_POST['elev'];
$lat=$_POST['lat'];
$long=$_POST['long'];
$rw1=$_POST['rw1'];
$rwy2=$_POST['rw2'];
$mva=$_POST['mva'];
$mve=$_POST['mve'];
$gates=$_POST['gates'];
$notes=$_POST['notes'];


// Connect to the database.
include('opendb.php');

// Close database connection.
include('closedb.php');

php?>
[/code]



Okay.. so what did I do wrong this time?


edit: Dammit, I got problems in my opendb file too. >_<

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/hsphere/local/home/penguine/mindsjourney.net/Lab/Magellan/opendb.php on line 3

Error connecting to mysql[/QUOTE]


What's that mean?

Line 3 on that page goes

[code=php]
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
[/code]


On another note.. is there any tutorials out there that tell you the RIGHT way to do things in PHP? I've tried four of them now and I'm still getting problems in every step I take.
×

Success!

Help @penguine spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...