Results 1 to 6 of 6

Thread: PHP question

  1. #1
    Join Date
    Jan 2003
    Posts
    70

    PHP question

    I'm putting together a simple CMS for a site in PHP. I used Dreamweaver code for the most part, and tweaked it where necessary to get what I want.

    I've been developing and testing on my computer with a PHP/Apache/MySQL setup, and everything is working great. Upload it to my server and now I'm getting an error when I try to insert a record using a form. The thing is, though, the form data is actually getting written to the DB (I know because it's appearing on the site) and then the error is appearing. What am I doing wrong?

    The error:
    Warning: Cannot modify header information - headers already sent by (output started at /home/amumweb/public_html/cms/jobs/add.php:6) in /home/amumweb/public_html/cms/jobs/add.php on line 75

    The code:
    <?php require_once('../../Connections/jobsdb.php'); ?>
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 jobsdb (id, `position`, organization, orglink, city, `state`, description, dateposted) VALUES (%s, %s, %s, %s, %s, %s, %s, NOW())",
    GetSQLValueString($_POST['id'], "int"),
    GetSQLValueString($_POST['position'], "text"),
    GetSQLValueString($_POST['organization'], "text"),
    GetSQLValueString($_POST['orglink'], "text"),
    GetSQLValueString($_POST['city'], "text"),
    GetSQLValueString($_POST['state'], "text"),
    GetSQLValueString($_POST['description'], "text"),
    GetSQLValueString($_POST['dateposted'], "date"));

    mysql_select_db($database_jobsdb, $jobsdb);
    $Result1 = mysql_query($insertSQL, $jobsdb) or die(mysql_error());

    $insertGoTo = "index.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
    }
    ?>

  2. #2
    check and remove any blank spaces above the head tag on your page.

  3. #3
    try putting this in your .htaccess file

    PHP_FLAG output_buffering on

  4. #4
    Join Date
    Dec 2004
    Location
    Beirut
    Posts
    599

    Re: PHP question

    Originally posted by tonomud
    Warning: Cannot modify header information - headers already sent by (output started at /home/amumweb/public_html/cms/jobs/add.php:6) in /home/amumweb/public_html/cms/jobs/add.php on line 75

    blank spaces at the end !
    Check em and make sure the > is the last character on ur page.
    Most cases of that error are because spaces issue
    POINTLeb Hosting Lebanese Hosting for the Middle East
    The fact that no one understands you , does not make you an artist
    Mo Ghaoui's Personal Blog

  5. #5
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342

    Lightbulb Re: PHP question

    Originally posted by tonomud

    Warning: Cannot modify header information - headers already sent by (output started at /home/amumweb/public_html/cms/jobs/add.php:6) in /home/amumweb/public_html/cms/jobs/add.php on line 75
    ?>

    This error means that when your browser tries to relocate (via header, change page) it sees you you already have ouputed either:text, spaces ect...

    At line 6 you outputed something, at where you tried to change the headers at line 75 it wont allow you...

    Whenever you use things like: session_start or header, you must use it before you output anything to the browser..

    hope it helps,

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  6. #6
    Join Date
    Jan 2003
    Posts
    70
    saghir69,
    Thanks, the .htaccess suggestion seems to work! I appreciate your help!
    tonomud

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •