...

View Full Version : Please help fix this page form code



aremzy
07-01-2010, 11:52 AM
Please, can someone help me with code, any time i run it, it stop at the position point.
the code is pasted below:



<?php // this page is included by new_page.php and edit_page.php?>
<?php if (!isset($new_page)) {$new_page = false;} ?>

<p>Page name: <input type="text" name="menu_name" value="<?php echo $sel_page['menu_name']; ?>" id="menu_name"/></p>

<p>Position: <select name="position">
<?php
if (!$new_page) {
$page_set = get_pages_for_subject($sel_page['subject_id']);
$page_count =mysql_num_rows($page_set);
} else {
$page_set = get_pages_for_subject($sel_subject['id']);
$page_count =mysql_num_rows($page_set) + 1;
}
for ($count=1; $count <=$page_count; $count++) {
echo "<option value=\"{$count}\"";
if ($sel_page['position'] == $count) { echo "selected";}
echo ">{$count}</option>";
}
?>
</select></p>
<p> Visible:
<input type="radio" name="visible" value="0" <?php
if ($sel_page['visible']== 0) {echo "checked";}
?> /> No
&nbsp;
<input type="radio" name="visible" value="1" <?php
if ($sel_page['visible']== 1) {echo "checked";}
?> /> Yes
</p>
<p> Content:<br />
<textarea name="content" rows="20" cols="80"><?php echo $sel_page['content']; ?></textarea>
</p>

abduraooft
07-01-2010, 01:11 PM
Please use
][/COLOR] tags to wrap your PHP codes while posting here.


it stop at the position point Hope you meant the text "Position:" near a drop down. If so, there might be some error in your query, which will not be visible to the browser output, since it breaks the drop down markup.

You may either use the "view source" option of the browser OR move the query part to the top of the <select> tag, like

<p>Position:
<?php
if (!$new_page) {
$page_set = get_pages_for_subject($sel_page['subject_id']);
$page_count =mysql_num_rows($page_set);
} else {
$page_set = get_pages_for_subject($sel_subject['id']);
$page_count =mysql_num_rows($page_set) + 1;
}
echo '<select name="position">';
for ($count=1; $count <=$page_count; $count++) {
echo "<option value=\"{$count}\"";
if ($sel_page['position'] == $count) { echo "selected";}
echo ">{$count}</option>";
}
echo '</select>';
?>
</p>

aremzy
07-01-2010, 02:13 PM
Thanks abduraooft, i tried checking the browser source code, it gave me this

"Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use"

i also tried moving the query part to the top of the <select> tag just has you said, it still not working.
It says
Position: Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY position ASC' at line 4

i still need help

Beagle
07-01-2010, 03:03 PM
Can you paste the SQL query?

abduraooft
07-01-2010, 05:19 PM
Reread the first line in my above post. Thanks!

aremzy
07-01-2010, 05:34 PM
I am sorry, i didnt take note


<?php require_once("includes/dbconnection.php");?>
<?php require_once("includes/functions.php"); ?>
<?php
//make sure the subject id sent is an integer


include_once("includes/form_functions.php");

// START FORM PROCESSING
// only execute the form processing if the form has been submitted
if (isset($_POST['submit'])) {
//initialize an array to hold our errors
$errors = array();

//perform validation on the form data
$required_fields = array('menu_name', 'position', 'visible', 'content');
$errors = array_merge($errors, check_required_fields($required_fields));

$fields_with_lengths = array('menu_name' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths));

// clean up the form data before putting it in database
$id = mysql_prep($_GET['page']);
$menu_name = trim(mysql_prep($_POST['menu_name']));
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$content = mysql_prep($_POST['content']);

// Database submission only proceeds if there were NO errors.
if (empty($errors)) {
$query = "CREATE pages SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}',
WHERE id = {$id}";
$result = mysql_query($query);
// test to see if the create occurred
if (mysql_affected_rows() == 1) {
// success!
$message = "The page was successfully created.";
} else {
$message = "The page could not be created.";
$message .= "<br />" . mysql_error();
}
} else {
if (count($errors) == 1) {
$message = "There was 1 error in the form.";
} else {
$message = "There were". count($errors) . "errors in the form.";
}
}
// END FORM PROCESSING
}

?>
<?php find_selected_page(); ?>
<?php include("includes/header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page,$public =false); ?>
<br />
<a href="/tonyson/new_page.php">+ Add a new subject</a>

</td>
<td id="page">
<h2>Add New page</h2>
<?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";}?>
<?php if (!empty($errors)) {display_errors($errors);}?>
<form action="/tonyson/new_page.php?subj=<?php echo $sel_subject['id']; ?> " method="post">
<?php $new_page = true; ?>
<?php include "page_form.php" ?>
<input type="submit" name="submit" value="create Page" />
</form>
<br />
<a href="/tonyson/edit_page.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
</td>
</tr>
</table>
<?php include("includes/footer.php"); ?>

abduraooft
07-01-2010, 05:41 PM
Can you paste the SQL query?

$page_set = get_pages_for_subject($sel_page['subject_id']);
$page_count =mysql_num_rows($page_set);
You'd need to show the query generated inside the above function, I assume.

Keleth
07-01-2010, 05:44 PM
$query = "CREATE pages SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible}, content = '{$content}', WHERE id = {$id}";

Uh... what are you attempting to do here? I'm pretty sure CREATE is used to make tables, SET is used for stuff like updates (I've never seen it used in another setting). Are you attempting to update a row?

aremzy
07-01-2010, 05:48 PM
function get_pages_for_subject($subject_id,$public = true){
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;

aremzy
07-01-2010, 05:51 PM
Keleth, i am trying to create a page with the query

Keleth
07-01-2010, 06:02 PM
Keleth, i am trying to create a page with the query

I will gladly admit I'm no pro at MySQL, but I have no idea what a MySQL page is... in fact, google has no idea what a MySQL page is... Are you trying to create a webpage dynamically populated via MySQL?

I guess I'll hold from here to where someone more experienced can comment to "MySQL page".

aremzy
07-01-2010, 06:14 PM
Keleth, sorry for the way i put it, am trying to create a webpage dynamically populated via MySQL.

Beagle
07-01-2010, 06:19 PM
Don't be so humble:p

There's no such thing. Try running that query. It's not valid.

Keleth
07-01-2010, 06:26 PM
Meh Beagle, I leave my gaps in knowledge up to better minds :p Hell, becoming active on this forum has taught me not to underestimate my lack of knowledge :D

But yah, CREATE isn't used in that way. If you want to add new data, its INSERT, to update existing data its UPDATE.

Also, in regards to the error in post #3, I suspect $subject_id isn't being set properly. Have you tested it?

abduraooft
07-02-2010, 07:58 AM
What do you get when you echo that query in your function, like

echo $query = "SELECT *
FROM pages
WHERE subject_id={$subject_id}
ORDER BY position ASC";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum