Forum Moderators: coopster
I'm building a CMS for an estate agent and i'm at the editing part of the process.
Basically on the site, once a user has a done a search of specified properties they want to a view all the properties will come up (called subjects) and then every house will have their own pages (called pages)
So I want to update the subjects which doesn't work. I echo back the variable to the page and it won't show it.
<h5>Edit Subject: <?php echo $sel_subject ['menu_name']; ?></h5> If I change the $sel_subject to $sel_page it will show up the menu_name from the page. What confuses me, is they use exactly the same code and the same names in the database.
Here's the code from the database if you can see why $sel_page would work but not $sel_subject
<?php
// This file is the place to store all basic functionsfunction 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
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 redirect_to( $location = NULL ) {
if ($location != NULL) {
header("Location: {$location}");
exit;
}
}
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}
function get_all_subjects() {
global $connection;
$query = "SELECT *
FROM subjects
ORDER BY position ASC";
$subject_set = mysql_query($query, $connection);
confirm_query($subject_set);
return $subject_set;
}
function get_pages_for_subject($subject_id) {
global $connection;
$query = "SELECT *
FROM pages
WHERE subject_id = {$subject_id}
ORDER BY position ASC";
$page_set = mysql_query($query, $connection);
confirm_query($page_set);
return $page_set;
}
function get_subject_by_id($subject_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id=" . $subject_id ." ";
$query .= "LIMIT 1";
$result_set = mysql_query($query, $connection);
confirm_query($result_set);
// REMEMBER:
// if no rows are returned, fetch_array will return false
if ($subject = mysql_fetch_array($result_set)) {
return $subject;
} else {
return NULL;
}
}
function get_page_by_id($page_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM pages ";
$query .= "WHERE id=" . $page_id ." ";
$query .= "LIMIT 1";
$result_set = mysql_query($query, $connection);
confirm_query($result_set);
// REMEMBER:
// if no rows are returned, fetch_array will return false
if ($page = mysql_fetch_array($result_set)) {
return $page;
} else {
return NULL;
}
}
function find_selected_page() {
global $sel_subject;
global $sel_page;
if (isset($_GET['subj'])) {
$sel_subject = get_subject_by_id($_GET['subj']);
$sel_page = NULL;
} elseif (isset($_GET['page'])) {
$sel_subject = NULL;
$sel_page = get_page_by_id($_GET['page']);
} else {
$sel_subject = NULL;
$sel_page = NULL;
}
}
function navigation($sel_subject = null, $sel_page = null) {
$subject_set = get_all_subjects();
// 5. Use returned data
while ($subject = mysql_fetch_array($subject_set)) {
echo "<div class=\"menu-name\">"; echo "<a href=\"edit_subject.php?page=" . urlencode($subject["id"]) .
"\">{$subject["menu_name"]}</a>"; echo"</div>";
echo "<div class=\"buying-text\">"; echo "{$subject["content"]}"; echo"</div>";
echo "<div class=\"image\">"; echo"</div>";
}
}
?>
sounds to me like $_GET['subj'] is not set and $_GET['page'] is. echo out your values to see what you get.
Good luck hope this helps.