Okay,i try to call a function of mysql_prep() that i made in functions.php.
I try to call this function at the page of create_subjects.php by typing this
<?php require_once("includes/functions.php");
into the create_subjects.php.
and this is the full code of create_subjects.php :
<?php require_once("includes/functions.php");
?>
<?php
$connection = mysql_connect("localhost","root","mypassword");
if (!$connection) {
die ("database failed to connect " . mysql_error());
}
$db_select = mysql_select_db("newcompany");
if (!$db_select) {
die ("database failed to connect " . mysql_error());
}
// a page ridirected using header : cnnt contain spaces or anything between PHP tag
$menu_name = mysql_prep($_POST['menu_name']);
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$query = "INSERT INTO subjects (
menu_name, position, visible
) VALUES (
'{$menu_name}', {$position}, {$visible}
)"; // not neccessarily nd to put { symbol when inserting values.
$result = mysql_query($query, $connection);
if ($result) {
// Success!
header("Location: content.php");
exit;
} else {
// Display error message.
echo "<p>Subject creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}
mysql_close($connection);
?>
This is the error that i got from my browser when i try to create a new page :
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\newcompany\includes\functions.php:50) in C:\xampp\htdocs\newcompany\create_subjects.php on line 28
and this is the full code of functions.php :
<?php
function mysql_prep( $value ) {
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0 ,this func oli exist 4 PHP above v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
// if magic quotes are active, then the slashes already exist
}
return $value;
}
function get_all_subjects() {
global $connection;
$subject_set = mysql_query("SELECT * FROM subjects", $connection);
if (!$subject_set) {
die ("database failed to connect " . mysql_error());
}
return $subject_set;
}
function get_pages_for_subject($subject_id) {
global $connection;
$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject_id}");
if (!$page_set) {
die ("x leh connect!!!! : " . mysql_error());
}
return $page_set;
}
?>
help please..
Thank You...