0

Everyone!

In my admin area, of a small CMS, I am creating an admin home page, and an edit page.

In my admin home, the admin user, can see what pages exists on the site, by clicking an html drop down menu.

All pages are stored in mysgl database, so the site is completely dynamic, or going to be..

I have retrieved the name of the links, to show in the drop down menu by adding this code to the form

in the admin_home.php:
"<form action=\"../edit_page.php\" method=\"$_GET\">";
$result = mysqli_query ($myConnection, $query);
echo "<select class=\"boxstyles\" name='linklabel'><option>Choose A Page To Edit&nbsp;&nbsp;</option>";
// printing the list box select command

while($nt=mysqli_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[linklabel]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 
echo "<input type=\"submit\" name=\"formSubmit\" value=\"Go\">";
"</form>";
mysqli_free_result($result);
?>

What I want to happen is, when the admin have chosen a page from the list, and clicked the submit button, the page should redirect to: edit_page.php - but nothing happens, and I dont have a lot of experience in php, so I simply cant find out what i am doing wrong..

Also very important in what i want to happen: I want to prepopulate the form in the edit_page.php, with the existing data from the database. This is why I have tried to use the unique id from the mysql table, both in the dropdown menu, and in the edit_page.php. Somehow I think that is how I can get the form to display the relevant info after the page has been submitted, or??

The code below must have several error in it, and I hope someone can point them out to help me out here!
The code I have in edit_page.php looks like this:

if (isset($_GET['formSubmit'] == "Go")) {

// Query the body section for the proper page
include_once "connect_to_mysql.php";
$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id='$nt' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $pagetitle = $row["pagetitle"];
	$linklabel = $row["linklabel"];
	$heading = $row["heading"];
	$pagebody = $row["pagebody"];
	$pagebody = str_replace("<br />", "", $pagebody);
} 
mysqli_free_result($query); 
}
?>

Bottom line: After hitting the submit button, nothing happens at all....
Can someone assitst me in how I can achieve what I have tried to describe above?

I think is a i really user friendly way to let the admin choose which site to edit, and therefor I hope it can be implemented the right way!

Good night all, I am looking very much forward to get some assistance from you!

Klemme

7
Contributors
20
Replies
21
Views
6 Years
Discussion Span
Last Post by klemme
0

Hey chrishea,

Thanks for your reply!

Well the form is inside php tags, so with my limited experience, i thought i should escape double qoutes like this: form action=\"../edit_page.php\" - or not needed?

I have tried to change the line to:

"<form action=../edit_page.php method=$_GET>";

And still nothing happens after the submit button has been clicked..

Any idea what I am doing wrong?

0

Opps i changed it tio the correct now:

method=get

..

But still nothing happens when the submit button is clicked?

0

If you were to do a View Source in your browser and see what the <form> tag looked like, it would be clear.

The method attribute should be set to method=get, not $_Get, which is what chrishea is getting at.

Also, when you want to emit HTML code easily in the middle of a php block of code, just close off the php, write the HTML, then reopen php:

<?  
   //some php code here 
?>
<form action="../edit_page.php" method="get">
<?
$result = mysqli_query ($myConnection, $query);
// more php here
?>
0

Hi, I'm not sure about <option></option>
I don't think <option> can use in input form.
If you want to use radio or check box
use <input type="radio" value=".."/>
or <input type="checkbox" value="../>
otherwise, when you click submit, there's actually no value input for your edit_page.php
Or you can keep your doing, use javascript to paste the data when you select something into <input type="hidden" value="your javascript function() " />
Second,
your code (isset($_GET[".."]==something)) is not the right way to do since
$_GET[".."]==something return true or false then it can be read isset(true) or isset(false).
You can try out by checking (isset($_GET) && $_GET == 'something').
Hope it helps.

0

Hi again,
Thanks for your answers, itsw been helpfull allready!

I have made more small php blocks of code, and now the form is outside, just as pure html, and it submits after the button has been clicked.

Allthough now, I get this error after submitting:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\wamp\www\mycms\administrator\edit_page.php on line 11

My edit_page.php looks like this: (In my query from to the database, I am sure something is wrong? My intention is to use the $nt value from the drop down list, so the fields in my edit form will echo out the relevant information for editing..)

include_once "connect_to_mysql.php";
if ($_GET['formSubmit']) {

// Query the body section for the proper page

$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id=$nt[id] //Here I am trying to get the info from the dropdown list.. LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $pagetitle = $row["pagetitle"];
	$linklabel = $row["linklabel"];
	$heading = $row["heading"];
	$pagebody = $row["pagebody"];
	$pagebody = str_replace("<br />", "", $pagebody);
} 
mysqli_free_result($query); 
}
?>

I am not sure how to pass the value from the chosen title in the admin.php:

"<option value=$nt[id]>$nt[linklabel]</option>";

?

I know maybe its really easy questions, but I havent tried this before, so I hope you have some patience out there :-)

Klemme

0
$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id={$nt['id']} LIMIT 1";
0

Thanks ardav and the rest out there!

I changed the line to:

$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id={$nt['id']} LIMIT 1";

// And also inserted this line..
<?php error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); ?>

The page is redirecting to the right page, but it doesnt display, it is just a blank screen, but the url is: edit_page.php :-)

So far so good, only again..I dont see why the page content doesnt show after submitting?

0

You haven't echoed anything from what I can see:

include_once "connect_to_mysql.php";
if ($_GET['formSubmit']) {
 
// Query the body section for the proper page
 
$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id=$nt[id] //Here I am trying to get the info from the dropdown list.. LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $pagetitle = $row["pagetitle"];
	$linklabel = $row["linklabel"];
	$heading = $row["heading"];
	$pagebody = $row["pagebody"];
	$pagebody = str_replace("<br />", "", $pagebody);
} 
mysqli_free_result($query); 
}
?>
0

Sorry, I never put this in, but further down the page, I have the form for editing the pagers content etc, It looks like this:

<p class="required">*Be sure to fill in all fields, as they are required to process your request!</p>
   <br />
    <form id="form" name="form" method="post" action="page_new_parse.php" 
    onsubmit="return validate_form ( );">
   <p><b>Page Full Title:</b></p><input name="pagetitle" type="text" id="pagetitle" 
   size="65" maxlength="65" value="<?php echo $pagetitle; ?>"  />&nbsp;<i>(This is the title as it is seen in the browser)</i><br />	    <br />
    
    <p><b>Link Label:</b></p><input name="linklabel" type="text" id="linklabel" 
    size="65" maxlength="24" value="<?php echo $linklabel ?>"  />&nbsp;<i>(What the link to this page will display as in the navigation)</i><br /><br />
    
    <p><b>Heading:</b></p><input name="heading" type="text" id="heading" size="70" maxlength="60" value="<?php echo $heading; ?>" />
     <i>(The heading will show on the top of every page!)</i><br /><br />

    <p><b>Pagebody:</b></p><textarea name="msgpost" id="msgpost" cols="100" rows="18"><?php echo $pagebody; ?></textarea><br />

    <input name="pid" type="hidden" value="<?php echo $pid; ?>" />
    <input type="submit" name="button" id="button" value="Submit Page Edit" />
    </form>
0

You have method="post" in your form. BUT you're trying to access the $_GET. Change this to $_POST. You're also not referencing the id from the POST variable. SO how does the SQL know which value to place for id?

0

ardav,

Thats the core of my problem..

I know how to display text from an input text field, but i havent tried to use:

"<option value=$nt[id]>$nt[linklabel]</option>";

As far as I understand, I have the unique id from the database, inside the variable $nt here, right?

On the edit_page.php, where I want to prepopulate the form with the relevant info, refering back to $nt[id], from the option tags, well this is where things stop running for me..

I have tried different things, to get "access" to $nt[id] in $_POST after submitting, but I seem to getting it wrong the whole time.

Here is the edit_page.php again, where I want to use the $nt[id], as you can see, nothing is in the $_post because as i explained above, im a twat that doesnt know how to pull the right id, from the option tags and process it further in edit_page.php..I am probably going to kick myself hard, when figuring this out, but at the moment, im lost here!

<?php
include_once "connect_to_mysql.php";
if (isset($_POST['formSubmit'])) {

// Query the body section for the proper page
$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id={$nt['id']} LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $pagetitle = $row["pagetitle"];
	$linklabel = $row["linklabel"];
	$heading = $row["heading"];
	$pagebody = $row["pagebody"];
	$pagebody = str_replace("<br />", "", $pagebody);
} 
mysqli_free_result($query); 
}
?>
0

OK, I'm afraid I don't really follow what's going on here, but I'll try.

If you're populating a series of radiobuttons:

(get id and label from DB)
$options="";
$check=' checked="checked"';
while($data = mysql_fetch_array($resultset){
  $options .="\n<input id=\"myoption{$data['id']}\" type="radio" name=\"myoption\" value=\"{$data['id']}\"{$check} /> <label for="myoption{$data['id']}">$data['label']</label>"
  if($check != "")$check=""; //this just stops eaach radio having checked status
}

Where appropriate in your code:

<?php echo $options;?>

When the form is submitted:

$chosen_id = mysql_real_escape_string($_POST['myoption']);

//you now use this in your SQL

0

Yes., In your edit.php page, there is no line for displaying anything [no echo statement]... So only you are having blank screen... Try with some conditional statements here to display a message or redirect from here to another page showing your desired message..

Thanks..,

0

Right..

Well thanks for all your replies, but I still havent found the solution.

I will try one last time, and show ALL the code, together! I do echo the variables out, in the form on edit_page.php.

This is my admin.home.php - Here I have a drop-down list (Not radio buttons), with the name of the allready existing links in the database. When an option is chosen, and submit is hit, I am redirecting to edit_page.php, ok..

MY PROBLEM IS THAT I DONT KNOW HOW I CAN RECIEVE/USE THE UNIQUE ID IN EDIT_PAGE.PHP, WHICH YOU CAN SEE I HAVE USED IN THE DROPDOWN LIST, THE PRIMARY KEY FROM THE DATABSE, TO IDENTIFY WHAT PAGE HAS BEEN CHOSEN FOR EDITING! (SO THE FORM FIELDS IN EDIT_PAGE.PHP CAN BE PREPOPULATED WITH THE RELEVANT INFO. AFTER THE PAGE HAS BEEN REDIRECTED FROM ADMIN.PHP)

Here is admin.php where the admin choses what page to edit:

<form action="../edit_page.php" method="post">
<?php
$result = mysqli_query ($myConnection, $query);
echo "<select class=\"boxstyles\" name='linklabel'>";
echo "<option>Choose A Page To Edit</option>";
// printing the list box select command
while($nt=mysqli_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[linklabel]</option>"; This is the id i want to pass and use in edit_page.php....
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 
?>
<input type="submit" name="formSubmit" value="Go">
</form>
<?php
mysqli_free_result($result);
?>

My problem here is that I dont know how I get access to the information/the unique id that i want to process from what ever page what chosen in admin.php

The chosen option and clicking SUBMIT, does submit to edit_page.php (I can see in the URL that is has changed) But the page is blank..

Here is my code for edit_page.php - Including the form I am using to edit/prepopulate:

<?php
include_once "connect_to_mysql.php";
if (isset($_POST['formSubmit'])) {

// Query the body section for the proper page
$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id={$nt['id']} LIMIT 1"; [B]// THIS LINE IS IMPORTANT/WRONG I THINK???[/B]
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $pagetitle = $row["pagetitle"];
	$linklabel = $row["linklabel"];
	$heading = $row["heading"];
	$pagebody = $row["pagebody"];
	$pagebody = str_replace("<br />", "", $pagebody);
} 
mysqli_free_result($query); 
}
?>

//Further down edit_page.php I echo out the relevant information from the form [B](WELL THIS IS WHAT I WANT TO DO, BUT IT IS WHAT I DONT KNOW HOW TO DO....)[/B]
<form id="form" name="form" method="post" action="page_new_parse.php" 
    onsubmit="return validate_form ( );">
   <p><b>Page Full Title:</b></p><input name="pagetitle" type="text" id="pagetitle" 
   size="65" maxlength="65" value="<?php echo $pagetitle; ?>"  />&nbsp;<i>(This is the title as it is seen in the browser)</i><br />	    <br />
    
    <p><b>Link Label:</b></p><input name="linklabel" type="text" id="linklabel" 
    size="65" maxlength="24" value="<?php echo $linklabel ?>"  />&nbsp;<i>(What the link to this page will display as in the navigation)</i><br /><br />
    
    <p><b>Heading:</b></p><input name="heading" type="text" id="heading" size="70" maxlength="60" value="<?php echo $heading; ?>" />
     <i>(The heading will show on the top of every page!)</i><br /><br />

    <p><b>Pagebody:</b></p><textarea name="msgpost" id="msgpost" cols="100" rows="18"><?php echo $pagebody; ?></textarea><br />

    <input name="pid" type="hidden" value="<?php echo $pid; ?>" />
    <input type="submit" name="button" id="button" value="Submit Page Edit" />
    </form>

I hope this is explained okay, as I am sure there are many experienced programmers out there, that easily can see what I want to do..

Basically: Just a drop down list, with the names of existing pages in the database, that after being chosen, submits to a new page = edit_page.php, where I want the form fields to be prepopulated, and ready for being edited.

But I get a blank page after I have hit submit, AND I am not sure how to display the relevant information in the form fields according to what was chosen.

I think I have explained myself badly several times, so this is the reason for this longer story!

Regards, Jan

i MIGHT BE

0

OK, your dropdown/form looks OK. So for your form processing code:

<?php
include_once "connect_to_mysql.php";
if (isset($_POST['formSubmit'])) {
//get id from dropdown and clean it
 $id = mysql_real_escape_string($_POST['linklabel']);

// Query the body section for the proper page
//use $id
$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id=$id LIMIT 1"; 


$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $pagetitle = $row["pagetitle"];
	$linklabel = $row["linklabel"];
	$heading = $row["heading"];
	$pagebody = $row["pagebody"];
	$pagebody = str_replace("<br />", "", $pagebody);
} 
mysqli_free_result($query); 
}
?>

I haven't looked at the rest of the code too closely, but if you get the code above to work, the rest should follow.

0

Thanks Ardav,

It makes sense to me, what you have written above - and I have made the small changes to the edit_page.php! Only to run into the same blank screen, where I get these error messsages:

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\wamp\www\mycms\administrator\edit_page.php on line 6

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\wamp\www\mycms\administrator\edit_page.php on line 11

Anybody knows what the missing parameter is?
Here is the code again, from the form processing page:

<?php require_once('login/auth.php'); ?>
<?php // error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); ?>
<?php
include_once "connect_to_mysql.php";
if (isset($_POST['formSubmit'])) {//get id from dropdown and clean it
$id = mysqli_real_escape_string($_POST['linklabel']); This is the line with the error, line 6

// Query the body section for the proper page//use $id
$sqlCommand = "SELECT pagetitle, linklabel, heading, pagebody FROM pages WHERE id=$id LIMIT 1"; 
}
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); //Here is the other line with an error message, line 11
while ($row = mysqli_fetch_array($query)) { 
    $pagetitle = $row["pagetitle"];
	$linklabel = $row["linklabel"];
	$heading = $row["heading"];
	$pagebody = $row["pagebody"];
	$pagebody = str_replace("<br />", "", $pagebody);
} 
mysqli_free_result($query); 

?>

Anyone sees what I could do to make these error messages go away and process the rest of the script?

Jan

0

JUst for now, change all mysqli to mysql to see if it works. The mysqli function need to include the link (connection object) variable.

Edited by diafol: n/a

0

sorry posted on wrong post :P I can't delete it so just editing n sorry....

Edited by TechySafi: n/a

0

SOLVED!!

Thanks Ardav, you have led me the way!! It is now working..

I kept the mysqli, and inserted the link identifier, which almost made it work.

I had to change a variable in the hidden field, for the form processing, and then it worked :-)

So about to missing words, can result in more than a weeks wondering on what is going on, haha - Anyways thank you very much, im sure ill come back one day soon with another newbie problem to be solved!! I allready have a small issue actually..

Klemme

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.