PHP, MySQL Error

This is a discussion on "PHP, MySQL Error" within the PHP Forum section. This forum, and the thread "PHP, MySQL Error are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1  
Old Nov 14th, 2007, 09:49
Emzi's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Manchester
Age: 25
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
PHP, MySQL Error

Hi all,

I'm currently designing a jobs site which requires a lot of PHP/MySQL work.

Now, I'm not really an expert at either but as I'm the only one in our company who is more familiar with PHP (everyone else is experienced with ASP, .NET etc.) I've been given the job.

I'm using Dreamweaver to help with producing the queries, code etc. (sssh ) and I'm stuck on one particular thing.

I'm working on the newsletter page, where someone inputs their email address and submits it to the database. That all works fine, but when I click submit it throws me this error (even though the data does get stored in the database)

Quote:
Warning: Cannot modify header information - headers already sent by (output started at /home/.rover/emzi/enjoyonline.co.uk/dev/ukjobs/includes/latestjobs.php:52) in /home/.rover/emzi/enjoyonline.co.uk/dev/ukjobs/includes/newsletter.php on line 53
The PHP code is here:

PHP: Select all

<?php require_once('Connections/ukjobsite.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}
$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO tblNEWSLETTER_SIGNUP (signup_id, email_address, date_registered, client_ip, unsubscribed) VALUES (%s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['signup_id'], "int"),
                       
GetSQLValueString($_POST['email_address'], "text"),
                       
GetSQLValueString($_POST['date_registered'], "date"),
                       
GetSQLValueString($_POST['client_ip'], "text"),
                       
GetSQLValueString($_POST['unsubscribed'], "int"));
  
mysql_select_db($database_ukjobsite$ukjobsite);
  
$Result1 mysql_query($insertSQL$ukjobsite) or die(mysql_error());
  
$insertGoTo "newsletter_signup_success.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
<img src="images/grey_small_top.gif" alt="UK Jobs in Recruitment" /><div class="grey_small">
<div class="small_content_holder"><img src="images/newsletter.gif" alt="UK Jobs in Recruitment" /><br />
Submit your email address to sign up to our 
newsletter.<br />
<div class="form_text">
<div class="form_padding"><b>Email:</b></div>
</div>
<div class="form_object">
<div class="form_padding">
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1"><input name="email_address" type="text" class="textfield"/></div>
<input type="submit" class="submit" value="SUBMIT" />  <input type="hidden" name="signup_id" value="" />
  <input type="hidden" name="client_ip" value="<?php echo $_SERVER['REMOTE_ADDR'?>" />
  <input type="hidden" name="unsubscribed" value="0" />
  <input type="hidden" name="MM_insert" value="form1" />
</form></div><div class="clear"></div></div></div><img src="images/grey_small_bot.gif" alt="UK Jobs in Recruitment" />
The particular line in question is:

PHP: Select all

}
  
header(sprintf("Location: %s"$insertGoTo)); 
And the site is here: http://www.dev.enjoyonline.co.uk/ukjobs/

Thanks in advance for any help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Nov 14th, 2007, 10:31
Reputable Member
Join Date: Feb 2006
Location: London
Age: 25
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Re: PHP, MySQL Error

Hi Emzi,

You are probably echoing something or have white space in the file you are including:
Connections/ukjobsite.php

There is a way around it if you have to echo something before a redirect... but nine times out of ten, it's just from whitespace before/after php tags or outputting something before the redirect.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Nov 14th, 2007, 10:40
Emzi's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Manchester
Age: 25
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP, MySQL Error

Hi Jimz, thanks for that

I checked the Connections/ukjobsite.php file but there isn't any white space in the file.

I don't think I'm echoing anything either.

I'm confused :S
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Nov 14th, 2007, 11:05
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP, MySQL Error

Well, you've got to be outputting something before that line, because the headers are already gone.... Otherwise you wouldn't be getting the error....

BTW, this is really slow and unecessary:
PHP: Select all

header(sprintf("Location: %s"$insertGoTo)); 

I would do something like this:
PHP: Select all

header('Location: '.$insertGoTo); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keep getting error message Microsoft VBScript runtime error '800a01a8' cpando1974 Classic ASP 2 Aug 7th, 2007 12:00
mysql error csun Databases 1 Jul 24th, 2007 14:35
Error 500 - Internal server error JasonStanley PHP Forum 3 Apr 23rd, 2007 17:56
PHP/MySQL Error - won't load extension! EdgeWalker PHP Forum 1 Feb 20th, 2007 09:59
MySql error help please charter Databases 1 May 8th, 2004 22:23


All times are GMT. The time now is 15:54.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42