I ask this question as the newest kid on the PHP block, and am so appreciative of any help. Essentially, I have learned just enough to get myself in trouble.
Overall, I am trying to create a website where the user can enter multiple items through several text boxes. When the user enters all the text, and hits the submit button...I want a record to be created in a single database under an ID. I have created an id field that is set as an auto number, and when I made the site live...I got the following error. Being new to PHP, I am not sure what the code is telling me. In this example, the database is "bizpitch" and the table is "bizpitches". The site in question is
Error that is coming up is:
Error adding submitted company: 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 ''list test', company'Test', addressone'Test', add' at line 2
Here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "<html xmlns="<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<TITLE>Bizpitches.com - Pitch Your Business!</TITLE>
<META content="Elevator Pitch, Elavator Pitch, Venture Capital, Start Up, Start-up, Business Financing, Business, Financing, Franchise, Franchising, Mezzanine Financing, Capital."
name=description>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK
href="index.css"
type=text/css rel=stylesheet><!--[if IE]>
<STYLE>.ieFix {
MARGIN-LEFT: 15px
}
.box FIELDSET INPUT.checkbox {
HEIGHT: 16px
}
</STYLE>
<![endif]-->
<SCRIPT type=text/javascript>
if (navigator.appVersion.indexOf("MSIE") == -1){
function bigon(x){
return false;
}
function bigoff(x){
return false;
}
}
</SCRIPT>
<LINK media="screen, projection, print"
href="index/hoverbox.css"
type=text/css rel=stylesheet><!--[if IE]><LINK media="screen, projection"
href="index/ie_fixes.css"
type=text/css rel=stylesheet>
<LINK media="screen, projection"
href="index/index_r_menu.css"
type=text/css rel=stylesheet><LINK media="screen, projection"
href="index/right_form.css"
type=text/css rel=stylesheet><LINK media=print
href="index/print.css"
type=text/css rel=stylesheet>
<META content="MSHTML 6.00.6000.16525" name=GENERATOR>
</HEAD>
<body>
<DIV id=mainWrapper>
<DIV id=top_bar><SPAN
style="DISPLAY: inline; PADDING-LEFT: 10px; FLOAT: left"><A
style="DISPLAY: inline" href="gb9990714102576.php?addcompany=1"><IMG
title="Bizpitches.com Home Page"
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px"
height=62 alt="bizpitches logo" src="index/logo.jpg" width=328></A> </SPAN>
<DIV id=contact_box style="DISPLAY: inline; FLOAT: right; WIDTH: 200px">
<TABLE cellSpacing=2 cellPadding=0 border=0>
<TBODY>
</TBODY></TABLE></DIV>
<SPAN style="PADDING-RIGHT: 20px; DISPLAY: inline; FLOAT: right">
<A href=" </SPAN></DIV>
<DIV id=container>
<DIV id=right>
<DIV class=menu_wrapper>
</DIV></DIV>
<BR></DIV>
<?php if (isset($_GET['addcompany'])): // If the user wants to add a company
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter your company's name:<br />
<textarea name="company" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter your contact name:<br />
<textarea name="contact" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter your company's address:<br />
<textarea name="addressone" rows="1" cols="50">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Address Two:<br />
<textarea name="addresstwo" rows="1" cols="50">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>City:<br />
<textarea name="city" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>State or Province:<br />
<textarea name="company" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Postal Coade:<br />
<textarea name="postalcode" rows="1" cols="10">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Country:<br />
<textarea name="country" rows="1" cols="20">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Company Phone:<br />
<textarea name="phone" rows="1" cols="14">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Website:<br />
<textarea name="website" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Email Address:<br />
<textarea name="email" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Funds Needed (Enter Dollar Value Without Commas Or Decimals):<br />
<textarea name="company" rows="1" cols="20">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Startup (Y/N):<br />
<textarea name="startup" rows="1" cols="1">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Industry:<br />
<textarea name="industry" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Pitch:<br />
<textarea name="company" rows="20" cols="50">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Additional Information:<br />
<textarea name="addlinfo" rows="20" cols="50">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>More Additional Information:<br />
<textarea name="company" rows="20" cols="50">
</textarea></p>
<input type="submit" value="SUBMIT" />
</form>
<?php else: // Default page display
// Connect to the database server
$dbcnx = @mysql_connect('XXXXXXX', 'bizpitch', 'XXXXXXXXX');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the company database
if (!@mysql_select_db('bizpitch')) {
exit('<p>Unable to locate the company ' .
'database at this time.</p>');
}
// If a company has been submitted,
// add it to the database.
if (isset($_POST['company'])) {
$company = $_POST['company'];
$contact = $_POST['contact'];
$addressone = $_POST['addressone'];
$addresstwo = $_POST['addresstwo'];
$city = $_POST['city'];
$stateprovince = $_POST['stateprovince'];
$postalcode = $_POST['postalcode'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$email = $_POST['email'];
$fundsneeded = $_POST['fundsneeded'];
$startup = $_POST['startup'];
$industry = $_POST['industry'];
$pitch = $_POST['pitch'];
$addlinfo = $_POST['addlinfo'];
$addlinfotwo = $_POST['addlinfotwo'];
$sql = "INSERT INTO bizpitches SET
contact'$contact',
company'$company',
addressone'$addressone',
addresstwo'$addresstwo',
city'$city',
stateprovince'$stateprovince',
postalcode'$postalcode',
country'$country',
phone'$phone',
website'$website',
email'$email',
fundsneeded'$fundsneeded',
startup'$startup',
industry'$industry',
pitch'$pitch',
addlinfo'$addlinfo',
addlinfotwo'$addlinfotwo',
addlinfotwo'$addlinfotwo'
entrydate=CURDATE(),";
if (@mysql_query($sql)) {
echo '<p>Your company has been added.</p>';
} else {
echo '<p>Error adding submitted company: ' .
mysql_error() . '</p>';
}
}
echo '<p>Here are all the companies in our database:</p>';
// Request the text of all the companies
$result = @mysql_query('SELECT company FROM bizpitches');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
// Display the text of each company in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['company'] . '</p>';
}
// When clicked, this link will load this page
// with the company submission form displayed.
echo '<p><a href="' . $_SERVER['PHP_SELF'] .
'?addcompany=1">Add a Company!</a></p>';
endif;
?>
</body>
</html>
Overall, I am trying to create a website where the user can enter multiple items through several text boxes. When the user enters all the text, and hits the submit button...I want a record to be created in a single database under an ID. I have created an id field that is set as an auto number, and when I made the site live...I got the following error. Being new to PHP, I am not sure what the code is telling me. In this example, the database is "bizpitch" and the table is "bizpitches". The site in question is
Error that is coming up is:
Error adding submitted company: 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 ''list test', company'Test', addressone'Test', add' at line 2
Here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "<html xmlns="<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<TITLE>Bizpitches.com - Pitch Your Business!</TITLE>
<META content="Elevator Pitch, Elavator Pitch, Venture Capital, Start Up, Start-up, Business Financing, Business, Financing, Franchise, Franchising, Mezzanine Financing, Capital."
name=description>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK
href="index.css"
type=text/css rel=stylesheet><!--[if IE]>
<STYLE>.ieFix {
MARGIN-LEFT: 15px
}
.box FIELDSET INPUT.checkbox {
HEIGHT: 16px
}
</STYLE>
<![endif]-->
<SCRIPT type=text/javascript>
if (navigator.appVersion.indexOf("MSIE") == -1){
function bigon(x){
return false;
}
function bigoff(x){
return false;
}
}
</SCRIPT>
<LINK media="screen, projection, print"
href="index/hoverbox.css"
type=text/css rel=stylesheet><!--[if IE]><LINK media="screen, projection"
href="index/ie_fixes.css"
type=text/css rel=stylesheet>
<LINK media="screen, projection"
href="index/index_r_menu.css"
type=text/css rel=stylesheet><LINK media="screen, projection"
href="index/right_form.css"
type=text/css rel=stylesheet><LINK media=print
href="index/print.css"
type=text/css rel=stylesheet>
<META content="MSHTML 6.00.6000.16525" name=GENERATOR>
</HEAD>
<body>
<DIV id=mainWrapper>
<DIV id=top_bar><SPAN
style="DISPLAY: inline; PADDING-LEFT: 10px; FLOAT: left"><A
style="DISPLAY: inline" href="gb9990714102576.php?addcompany=1"><IMG
title="Bizpitches.com Home Page"
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px"
height=62 alt="bizpitches logo" src="index/logo.jpg" width=328></A> </SPAN>
<DIV id=contact_box style="DISPLAY: inline; FLOAT: right; WIDTH: 200px">
<TABLE cellSpacing=2 cellPadding=0 border=0>
<TBODY>
</TBODY></TABLE></DIV>
<SPAN style="PADDING-RIGHT: 20px; DISPLAY: inline; FLOAT: right">
<A href=" </SPAN></DIV>
<DIV id=container>
<DIV id=right>
<DIV class=menu_wrapper>
</DIV></DIV>
<BR></DIV>
<?php if (isset($_GET['addcompany'])): // If the user wants to add a company
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter your company's name:<br />
<textarea name="company" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter your contact name:<br />
<textarea name="contact" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter your company's address:<br />
<textarea name="addressone" rows="1" cols="50">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Address Two:<br />
<textarea name="addresstwo" rows="1" cols="50">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>City:<br />
<textarea name="city" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>State or Province:<br />
<textarea name="company" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Postal Coade:<br />
<textarea name="postalcode" rows="1" cols="10">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Country:<br />
<textarea name="country" rows="1" cols="20">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Company Phone:<br />
<textarea name="phone" rows="1" cols="14">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Website:<br />
<textarea name="website" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Email Address:<br />
<textarea name="email" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Funds Needed (Enter Dollar Value Without Commas Or Decimals):<br />
<textarea name="company" rows="1" cols="20">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Startup (Y/N):<br />
<textarea name="startup" rows="1" cols="1">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Industry:<br />
<textarea name="industry" rows="1" cols="30">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Pitch:<br />
<textarea name="company" rows="20" cols="50">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Additional Information:<br />
<textarea name="addlinfo" rows="20" cols="50">
</textarea></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>More Additional Information:<br />
<textarea name="company" rows="20" cols="50">
</textarea></p>
<input type="submit" value="SUBMIT" />
</form>
<?php else: // Default page display
// Connect to the database server
$dbcnx = @mysql_connect('XXXXXXX', 'bizpitch', 'XXXXXXXXX');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the company database
if (!@mysql_select_db('bizpitch')) {
exit('<p>Unable to locate the company ' .
'database at this time.</p>');
}
// If a company has been submitted,
// add it to the database.
if (isset($_POST['company'])) {
$company = $_POST['company'];
$contact = $_POST['contact'];
$addressone = $_POST['addressone'];
$addresstwo = $_POST['addresstwo'];
$city = $_POST['city'];
$stateprovince = $_POST['stateprovince'];
$postalcode = $_POST['postalcode'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$email = $_POST['email'];
$fundsneeded = $_POST['fundsneeded'];
$startup = $_POST['startup'];
$industry = $_POST['industry'];
$pitch = $_POST['pitch'];
$addlinfo = $_POST['addlinfo'];
$addlinfotwo = $_POST['addlinfotwo'];
$sql = "INSERT INTO bizpitches SET
contact'$contact',
company'$company',
addressone'$addressone',
addresstwo'$addresstwo',
city'$city',
stateprovince'$stateprovince',
postalcode'$postalcode',
country'$country',
phone'$phone',
website'$website',
email'$email',
fundsneeded'$fundsneeded',
startup'$startup',
industry'$industry',
pitch'$pitch',
addlinfo'$addlinfo',
addlinfotwo'$addlinfotwo',
addlinfotwo'$addlinfotwo'
entrydate=CURDATE(),";
if (@mysql_query($sql)) {
echo '<p>Your company has been added.</p>';
} else {
echo '<p>Error adding submitted company: ' .
mysql_error() . '</p>';
}
}
echo '<p>Here are all the companies in our database:</p>';
// Request the text of all the companies
$result = @mysql_query('SELECT company FROM bizpitches');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
// Display the text of each company in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['company'] . '</p>';
}
// When clicked, this link will load this page
// with the company submission form displayed.
echo '<p><a href="' . $_SERVER['PHP_SELF'] .
'?addcompany=1">Add a Company!</a></p>';
endif;
?>
</body>
</html>