Forum Moderators: coopster

Message Too Old, No Replies

getting mysql database values + updating..

some code checking requested.. =)

         

panoz

9:40 pm on Dec 1, 2003 (gmt 0)

10+ Year Member



OK guys.. I'm totaly new to php and mysql. Trying to do my best and understand what I'm doing, so I jave read lots of tutorials, pdfs and using dreamweaver for some assistance.

But I have an annoying problem that I can not figure out.

It seems like the dreamweaver code is not liking a other php self inserted code. I can read and update the databse but the script displays and error that the headers have already been sent. Have narrowed it to a piece of dreamweaver redirect code when a form is processed and a login check script.

Anyway..

Is it preferable to make a simple get+show php script in one page and redirect to an other php page that checks and updates the database or have it all in one php page?

as it is now:
------------------
<snipped code dump>

Any suggestions?

Appreciate any help given!
Cheers!

[edited by: jatar_k at 4:34 pm (utc) on Dec. 2, 2003]
[edit reason] charter [webmasterworld.com] [/edit]

RonPK

10:32 pm on Dec 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it preferable to make a simple get+show php script in one page and redirect to an other php page that checks and updates the database or have it all in one php page?

I usually put it all in one script. Except when it is important to prevent multiple submits (F5).

<?php require_once('Connections/adon_admin.php');?>
<?php

/ / require our database connection

No need to close and almost immediately re-open php sections. This way, it creates a new line, which gets sent to the browser, causing your 'headers already sent' error.

panoz

4:14 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



thanks for the input!

Removed the xtra <?php +?> tags and do still get the same error:

--------------------
Warning: Cannot add header information - headers already sent by (output started at e:\phpdev\www\public\adon_admin\check_login.php:50) in e:\phpdev\www\public\adon_admin\update_test.php on line 54
--------------------

I'll try to merge the update+showing pages into one.. unless someone has a better idea.

Cheeers!

jatar_k

4:38 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld panoz,

What is the line of code that is giving the error?

I assume it is
header("Location: some/url.php");
or
session_start();

You can't have any output to the browser at all before you call these functions. This can even consist of a blank line before your opening php tag (<?). Figure out what is producing the output and that will fix your error.

panoz

4:51 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



Thanks for the welcome! =)

Line 54 in update_test.php:

--------------
$updateGoTo = "update_test.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?'))? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo)); //line 54
}
--------------

It executes the check_login.php script because it's inserted in the adon_admin.php (has the database connecttion info as well includes the check login page).

Seems like the check_login.php sends some headers when it starts a session and the dreamweaver code does not like it.

That's why it gives the following error message:

---------
Warning: Cannot add header information - headers already sent by (output started at e:\phpdev\www\public\adon_admin\check_login.php:50) in e:\phpdev\www\public\adon_admin\update_test.php on line 54
---------

Cheers!

panoz

4:53 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



edit:

------------
$updateGoTo = "show_update.php"; // the right page
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?'))? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo)); //line 54
}
------------

jatar_k

5:00 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Does anything above that line have output?
Did you check for blank lines anywhere outside of you php tags?

panoz

5:16 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



Action that is called from the form is as follows:

--------
<form action="<?php echo $editFormAction;?>" name="text_info" method="POST">
--------

And the above statement calls the code below.

--------
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . $_SERVER['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "text_info")) {
$updateSQL = sprintf("UPDATE info SET information=%s WHERE id=%s",
GetSQLValueString($HTTP_POST_VARS['text_info'], "text"),
GetSQLValueString($HTTP_POST_VARS['text_info'], "int"));

mysql_select_db($database_adon_admin, $adon_admin);
$Result1 = mysql_query($updateSQL, $adon_admin) or die(mysql_error());

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

Btw: I can do without the redict script as long it would be possible for me to have the both viewing+editing+updating functions in one page.

The main reason for me struggling with this code is because I want to show a value in a textfield, be able to alter it, post it and view the results.

Is there a easier way?