Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance

> Error In Php Script

This is a discussion on Error In Php Script, within the PHP section. This forum and the thread "Error In Php Script" are both part of the Programming Your Website category.

 
Reply to this topicStart new topic
> Error In Php Script, Script Not Submitting to Table
PoetAlley
post Feb 17 2008, 01:33 PM
Post #1


New Squeeze
*

Posts: 5
Joined: 17-February 08


Attached File  Site_Request_Table.jpg ( 86.5K ) Number of downloads: 9

I am still getting error messages about my sql when I submit the form, and these are the errors I am getting.

"An error occured in script '/home/accident/public_html/site_request.php' on line 113: "
CODE
Query: INSERT into site_request (email, pages, design, titles, header, left, centre, right, footer, extra, cost, total, request_date) VALUES ('myemail@address.com', '6', 'Surround Style', 'index, album1, album2, album3, album4, album5', 'Red', 'Green', 'White', 'No right column required!', 'Blue', 'both', '25', '150', NOW() )

And this is the code for the page.
CODE
// Check for a header colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['header'])))) {
  $h = escape_data($_POST['header']);
} else {
  $h = FALSE;
  echo '<p>Please enter a colour for your header section!</p>';
}

// Check for a left column colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['left'])))) {
  $l = escape_data($_POST['left']);
} else {
  $l = '<i>No left column required!</i>';
}

// Check for a centre section colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['centre'])))) {
  $c = escape_data($_POST['centre']);
} else {
  $c = FALSE;
  echo '<p>Please enter a colour for your centre section!</p>';
}

// Check for a right column colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['right'])))) {
  $r = escape_data($_POST['right']);
} else {
  $r = '<i>No right column required!</i>';
}

// Check for a footer colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['footer'])))) {
  $f = escape_data($_POST['footer']);
} else {
  $f = '<i>No footer section required!</i>';
}
$query = "INSERT into site_request (email, pages, design, titles, header, left, centre, right, footer, extra, cost, total, request_date) VALUES ('$e', '$p', '$d', '$t', '$h', '$l', '$c', '$r', '$f', '$x', '$cost', '$total', NOW() )";
$result = mysql_query ($query) or trigger_error("Query: $query\n
MySQL Error: " . mysql_error());

These are the settings of the sections on the form itself.
CODE
<p><b>Header:</b> <input type="text" name="header" size="15" maxlength="30" /></p>
<p><b>Left Column:</b> <input type="text" name="left" size="15" maxlength="32" /></p>
<p><b>Centre:</b> <input type="text" name="centre" size="15" maxlength="30" /></p>
<p><b>Right Column:</b> <input type="text" name="right" size="15" maxlength="32" /></p>
<p><b>Footer:</b> <input type="text" name="footer" size="15" maxlength="32" /></p>

If anyone can help I would be very grateful.

This post has been edited by PoetAlley: Feb 17 2008, 02:01 PM
Go to the top of the page
 
+Quote Post
Rakuli
post Feb 17 2008, 01:49 PM
Post #2


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


The first value you are entering isn't quoted properly. You need to add some apostrophe's around the value and escape any quotes within the value.

Are you escaping your values before inserting them? $val = mysql_real_escape_string($val);

This will ensure that someone doesn't try to inject SQL and hack your database.

CODE
'<A href="mailto:\'myemail@address.com\'">'myemail@address.com'</A>'


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
PoetAlley
post Feb 17 2008, 02:15 PM
Post #3


New Squeeze
*

Posts: 5
Joined: 17-February 08


QUOTE (Rakuli @ Feb 17 2008, 06:49 PM) *
The first value you are entering isn't quoted properly. You need to add some apostrophe's around the value and escape any quotes within the value.

Are you escaping your values before inserting them? $val = mysql_real_escape_string($val);

This will ensure that someone doesn't try to inject SQL and hack your database.

CODE
'<A href="mailto:\'myemail@address.com\'">'myemail@address.com'</A>'

That was something that was added after I posted to another forum, and it was part of the error submission when attempting to submit the form, without the anchor tags though.

In response to your request for other information, I have already escaped these values by using the regular expressions at the start of the script.
CODE
// Check for an email address.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,40}$', stripslashes(trim($_POST['email'])))) {
$e = escape_data($_POST['email']);
} else {
$e = FALSE;
echo '<p>Please enter a valid email address!</p>';
}
Go to the top of the page
 
+Quote Post
christopher
post Feb 17 2008, 02:37 PM
Post #4


Squeezing
***

Posts: 54
Joined: 15-February 08
From: Ottawa, Canada


QUOTE (PoetAlley @ Feb 17 2008, 01:33 PM) *
Attached File  Site_Request_Table.jpg ( 86.5K ) Number of downloads: 9

I am still getting error messages about my sql when I submit the form, and these are the errors I am getting.

"An error occured in script '/home/accident/public_html/site_request.php' on line 113: "
CODE
Query: INSERT into site_request (email, pages, design, titles, header, left, centre, right, footer, extra, cost, total, request_date) VALUES ('myemail@address.com', '6', 'Surround Style', 'index, album1, album2, album3, album4, album5', 'Red', 'Green', 'White', 'No right column required!', 'Blue', 'both', '25', '150', NOW() )


My guess would be the single quotes around the values destined for the int(3) and decimal(6,2) columns are the problem.


--------------------
Blog: annoyed.ca | Web Site Hosting: www.bluephyre.com
Go to the top of the page
 
+Quote Post
PoetAlley
post Feb 17 2008, 02:58 PM
Post #5


New Squeeze
*

Posts: 5
Joined: 17-February 08


QUOTE (christopher @ Feb 17 2008, 07:37 PM) *
My guess would be the single quotes around the values destined for the int(3) and decimal(6,2) columns are the problem.

Cannot place double quotation marks around these values, these are already in use around the whole statement. Could you make other suggestions please?
Go to the top of the page
 
+Quote Post
Rakuli
post Feb 17 2008, 03:16 PM
Post #6


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


WHat he means is that you shouldn't treat numeric values as strings. Take the quotes around the integers away altogether smile.gif


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
PoetAlley
post Feb 17 2008, 03:29 PM
Post #7


New Squeeze
*

Posts: 5
Joined: 17-February 08


Still no difference, the code is still not being accepted, but this may have some influence on the outcome.
CODE
MySQL Error: 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 'left, centre, right, footer, extra, cost, total, request_date) VALUES ('alley-ca' at line 1
Go to the top of the page
 
+Quote Post
Rakuli
post Feb 17 2008, 04:00 PM
Post #8


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


Just a quick grasp at straws..

Mysql does not allow spaces between the function name and the first parenthesis... Try removing the space you have between VALUES and (

VALUES('alley-etc...

I'm not SURE if VALUES is treated as a function but it could be the case.


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
christopher
post Feb 17 2008, 04:03 PM
Post #9


Squeezing
***

Posts: 54
Joined: 15-February 08
From: Ottawa, Canada


QUOTE (PoetAlley @ Feb 17 2008, 03:29 PM) *
Still no difference, the code is still not being accepted, but this may have some influence on the outcome.
CODE
MySQL Error: 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 'left, centre, right, footer, extra, cost, total, request_date) VALUES ('alley-ca' at line 1



'left' and 'right' are reserved words in MySQL. You may need to put backticks (single-quote look-a-like thing, usually on the keyboard key directly to the left of the number 1) around those column names.


I also wonder about that space after VALUES before the ( bracket...


--------------------
Blog: annoyed.ca | Web Site Hosting: www.bluephyre.com
Go to the top of the page
 
+Quote Post
PoetAlley
post Feb 17 2008, 06:27 PM
Post #10


New Squeeze
*

Posts: 5
Joined: 17-February 08


QUOTE (christopher @ Feb 17 2008, 09:03 PM) *
'left' and 'right' are reserved words in MySQL. You may need to put backticks (single-quote look-a-like thing, usually on the keyboard key directly to the left of the number 1) around those column names.


I also wonder about that space after VALUES before the ( bracket...


Thank you so much, I did as you stated and decided to add the ` backtick to each of the headings in that line: left, centre, right, and footer,, as well as closing the gap between VALUES and the opening bracket, and it worked just perfectly.

Here is the code for the complete script.

CODE
<?php
ob_start();
session_start()
// Include the configuration file for error management and such.
require_once ('includes/config.inc.php');
if (isset($_POST['Send'])) { // Handle the form
require_once ('includes/mysql_connect.php'); // Connect to the database.

$d=$_POST['design'];
$x=$_POST['extra'];

// Check for an email address.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,40}$', stripslashes(trim($_POST['email'])))) {
  $e = escape_data($_POST['email']);
} else {
  $e = FALSE;
  echo '<p>Please enter a valid email address!</p>';
}

// Check for pages quantity.
if (eregi ('^[[:digit:]]{1,3}$', stripslashes(trim($_POST['pages'])))) {
  $p = escape_data($_POST['pages']);
} else {
  $p = FALSE;
  echo '<p>Please enter a number between 1 and 99!</p>';
}

if (isset($_POST['design'])) {
  $d = ($_POST['design']);
} else {
  $d = FALSE;
  echo '<p>Please select the design you require.</p>';
}</P> <P> // Check for page titles.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['titles'])))) {
  $t = escape_data($_POST['titles']);
} else {
  $t = FALSE;
  echo '<p>Please enter your titles for each page!</p>';
}

// Check for a header colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['header'])))) {
  $h = escape_data($_POST['header']);
} else {
  $h = FALSE;
  echo '<p>Please enter a colour for your header section!</p>';
}

// Check for a left column colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['left'])))) {
  $l = escape_data($_POST['left']);
} else {
  $l = '<i>No left column required!</i>';
}

// Check for a centre section colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['centre'])))) {
  $c = escape_data($_POST['centre']);
} else {
  $c = FALSE;
  echo '<p>Please enter a colour for your centre section!</p>';
}

// Check for a right column colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['right'])))) {
  $r = escape_data($_POST['right']);
} else {
  $r = '<i>No right column required!</i>';
}

// Check for a footer colour.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['footer'])))) {
  $f = escape_data($_POST['footer']);
} else {
  $f = '<i>No footer section required!</i>';
}

// Check for extra auxillary pages.

if (isset($_POST['extra'])) {
  $x = ($_POST['extra']);
} else {
  $x = FALSE;
  echo '<p>Please choose from one of the options available!</p>';
}

// Determine the Price per page.
if ($_POST['pages'] < 4) {
  $cost = 30;
} elseif ($_POST['pages'] >= 4 && $_POST['pages'] < 8) {
  $cost = 25;
} elseif ($_POST['pages'] >= 8) {
  $cost = 22.50;
}

$total = ($_POST['pages'] * $cost);
if ($e && $p && $d && $t && $h && $l && $c && $r &&  $f && $x && $cost && $total) {

$query = "SELECT user_id FROM users WHERE email='$e'";
$result = mysql_query ($query) or trigger_error("Query: $query\n
MySQL Error: " . mysql_error());
  
if (mysql_num_rows($result) < 1) {
  echo 'Only members can request this facility, please register with us before requesting a site to be built.';
} else {

// Add the request to the database.
$query = "INSERT into site_request (email, pages, design, titles, header, `left`, `centre`, `right`, `footer`, extra, cost, total, request_date) VALUES('$e', $p, '$d', '$t', '$h', '$l', '$c', '$r', '$f', '$x', $cost, $total, NOW() )";
$result = mysql_query ($query) or trigger_error("Query: $query\n
MySQL Error: " . mysql_error());

if (!$result){
  echo("Update unsuccessful");
}
$subject = "Site Creation Request";
$body = "Thank you for requesting us to build a site for you.  Although you have told us that you would like us to create $p pages at a cost of £$cost per page, there are still some details we would require from you which we will request in an forthcoming email.  The pages will be designed in the $d style, with each page using the titles, $t.  The colour scheme for the site will be $h for the header, $l for the left column, $c for the centre, $r for the right column, and $f for the footer.  The site will also contain $x supplementary page(s).";
if(!mail($e, $subject, $body)){
  print 'Your message has not been received, please try contacting us later.';
}
  
$subject = "Site Creation Request";
$body = "A request for a site to be created has been received.  The site consists of $p pages, in the $d style, using the following colour scheme: header, $h, left column, $l, centre, $c, right column, $r and footer, $f.  $x supplementary page(s) are also required.";
$recipient = "<A href="mailto:myemail@address.com">myemail@address.com</A>";

$didit = mail($recipient, $subject, $body);
if (!$didit){
  echo("Your request has not been received, please try contacting us later");
} else {
  echo("Thank you for your web site creation request, we will get back to you about further details at $e.");
}
}
}
mysql_close(); // Close the database connection.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"<A href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</A>">
<html xmlns="<A href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</A>" xml:lang="en">
<head>
<title>Site Creation Request</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/></P> <P><meta name="keywords" content="Home-Groan, Music downloads, MP3 downloads, MP3, Music, MP3 Music downloads, Accident downloads, Accident Music downloads, Accident MP3 downloads, Accident MP3 Music downloads, HG 001, Accident Albums, Home of Accident Recordings, Alley Cat, Brill O'Padd, Alley Cat and Brill O'Padd, Alley Cat and Brill O'Padd Song Writers, Accident Fated to Happen album, Child of War, Dearest Helen, Indian Lament, Sleepless Nights, Graveyard Sign, Help Me Nurze, Harmony in B E D, Glencoe, Remembering, Lambs to the Slaughter, Girl When I Loved You, Pretty Princess, See The City, Symphony of Romance, Dancing Between Silk Sheets, Is This Our Future" /></P> <P><link href="error.css" rel="stylesheet" type="text/css"/>
</head></P> <P><body></P> <P><div class="header">
<img'><img</A> src="members/images/logo2.JPG" alt="Accident Recordings" /><p>Site Creation
Request Form</p></P> <P></div></P> <P><div class="leftcolumn">
<a href="members/index.php"><img src="members/images/logo_button.JPG" alt="Home-Groan Home" />Home</a>



<a href="members/albums.php"><img src="members/images/logo2_button.JPG" alt="Accident Albums" />Accident Albums</a>



<a href="members/screensavers.php"><img src="members/images/screen-saver_button.JPG" alt="Home-Groan Screen Savers" />Screen Savers</a>



<a href="<A href="http://jigsaw.w3.org/css-validator/">http://jigsaw.w3.org/css-validator/</A>">
  <img style="border:0;width:88px;height:31px"
       src="<A href="http://jigsaw.w3.org/css-validator/images/vcss">http://jigsaw.w3.org/css-validator/images/vcss</A>"
       alt="Valid CSS!"></img>
</a>
</p>
  
</div>
<div class="centre">
<form method="POST" action="site_request.php">
<fieldset>
<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p>How many HTML pages would you require?
<b>Number of Pages:</b> <input type="text" name="pages" size="3" maxlength="3" value="<?php if (isset($_POST['pages'])) echo $_POST['pages']; ?>" /> </p>
<p>Please choose the design type you require!</p>
<p><img src="members/images/page1.JPG" alt="Surround Style" />Surround Style <input type="radio" name="design" value="Surround Style" /></p>

<p><img src="members/images/page2.JPG" alt="Alternative Surround Style" />Alternative Surround Style <input type="radio" name="design" value="Alternative Surround Style" /></p>

<p><img src="members/images/page3.JPG" alt="3 Rows Style" />3 Rows Style <input type="radio" name="screen_resolution" value="3 Rows Style" /></p>

<p><img src="members/images/page4.JPG" alt="Triangle Style" />Triangle Style <input type="radio" name="design" value="Triangle Style" /></p>

<p><img src="members/images/page5.JPG" alt="Alternative Triangle Style" />Alternative Triangle Style <input type="radio" name="design" value="Alternative Triangle Style" /></p>

<p><img src="members/images/page6.JPG" alt="Left Right Style" />Left Right Style <input type="radio" name="design" value="Left Right Style" /></p>

<p><img src="members/images/page7.JPG" alt="Picture Page" />Picture Page <input type="radio" name="design" value="Picture Page" /></p>

<p><img src="members/images/page8.JPG" alt="Full Page" />Full Page <input type="radio" name="design" value="Full Page" /></p>

<p>Please enter your page titles here, separated by commas.
<b>Page Titles:</b> <textarea name="titles" cols="60" rows="5"></textarea></p>
<p>Please select the colour you require for each section of your site, you can choose either the colour name or hexadecimal number.
</p>
<p><b>Header:</b> <input type="text" name="header" size="15" maxlength="30" /></p>
<p><b>Left Column:</b> <input type="text" name="left" size="15" maxlength="32" /></p>
<p><b>Centre:</b> <input type="text" name="centre" size="15" maxlength="30" /></p>
<p><b>Right Column:</b> <input type="text" name="right" size="15" maxlength="32" /></p>
<p><b>Footer:</b> <input type="text" name="footer" size="15" maxlength="32" /></p>
<p>Do you require a Search or Contact Page?

Contact Page &nbsp; <input type="radio" name="extra" value="contact" />&nbsp; &nbsp;
Search Page &nbsp; <input type="radio" name="extra" value="search" />&nbsp; &nbsp;
Both Pages &nbsp;<input type="radio" name="extra" value="both" />&nbsp; &nbsp;
No Pages &nbsp;<input type="radio" name="extra" value="no" /></p>
</fieldset>
<p><input type="submit" name="Send" value="Place Request" /> <input type="reset" name="Submit2" value="Amend Request" /></p></form>

</body>
</html>
<?php
ob_end_flush();
?>


This post has been edited by Rakuli: Feb 17 2008, 06:33 PM
Reason for edit: Removed [quote] tag from user text -- it looked confusing :)
Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   5 Blake121 282 15th February 2008 - 09:41 AM
Last post by: Blake121
No New Posts   4 Sleaklight 283 15th February 2008 - 03:25 PM
Last post by: Marc
No New Posts 7 Webmaster 750 27th August 2008 - 12:40 PM
Last post by: rich97
No New Posts   3 mcdanielnc89 341 23rd February 2008 - 08:14 AM
Last post by: Marc
No New Posts   1 gribble 364 5th March 2008 - 06:08 PM
Last post by: delusion