I've got some code that gets a name from a form, checks a MySQL database for duplications, if no duplications found it is supposed to write the new name as a new record. I say supposed to because it stops at that point and tells me
syntax error at /usr/lib/cgi-bin/addoffice.cgi line 62, near "$sth = $
+dbh->prepare($stmt) || die ""
Can't find string terminator '"' anywhere before EOF at /usr/lib/cgi-b
+in/addoffice.cgi line 63.
.
It sounds to me like there is a string in the wrong place but I can't see it. In fact, if I run the script from terminal I get
<!-- warning: String found where operator expected at ./addoffice.cgi
+line 59, near "$sth = $dbh��prepare($stmt) || die "" (M
+ight be a runaway multi�line "" string starting on line 57) --
+>
What confounds me is that the code worked fine until I added the second MySQL query but the second query syntax is a copy and paste of the first.
I have tried closing and reopening the database connection in between the two queries but got the same results. I've posted the code below. Does anyone know what I've stuffed up?
# Prepare and execute the SQL query
$sth = $dbh->prepare($stmt)
|| die "prepare: $stmt: $DBI::errstr";
$sth->execute($office) || die <br/>"execute: $stmt: $DBI::
+errstr";
$sth->bind(undef,/$num);
$sth->fetchrow();
print start_html;
if ($num){ #if a match has been found
$message= "The office of ".$office." is already listed.<br
+>";
$url = "http://stgeorges.com/admin/addoffice.html?office=$
+office&msg=$message";<br/>
$q =>print "<meta http-equiv='refresh' content='0;URL=$url
+'>";
}
else{
# Create the query statement - Insert the new office into the database
$stmt = "INSERT into officers (off_name) values (?)";
# Prepare and execute the SQL query
$sth = $dbh->prepare($stmt) || die "prepare: $stmt: $DBI::
+errstr";
$sth->execute($office) || die "execute: $stmt: $DBI::errst
+r";
$sth->fetchrow();
}
print end_html;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.