...

View Full Version : im getting an error when im submitting 'content' to my database.. need help here..



crisean
10-22-2012, 06:13 AM
Im a beginner in world of php, and i don't know how to solve this problem,can someone help me.. Please.. thanks in advance... here's my code in new_page.php,
I forgot to say the correct specification of the problem codes new_page.php I dare to do. because I'd love to add a new page in the browser does not work with the error content part and written says:
The page could not be updated.
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'' at line 6 ..
That is why I need the help of a good man who could solve my problem. thanks in Advance.. :

<?php require_once("connection.php"); ?>
<?php require_once("function.php"); ?>
<?php
// make sure the subject id sent is an integer
if (intval($_GET['subj']) == 0) {
redirect_to("content.php");
}

include_once("form_function.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 validations on the form data
$required_fields = array('menu_name', 'position', 'visible', 'content');
$errors = array_merge($errors, check_required_fields($required_fields));

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

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

// Database submission only proceeds if there were NO errors.
if (empty($errors)) {
$query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
$result = mysql_query($query);
// test to see if the update occured
if (mysql_affected_rows() == 1) {
// Success!
$message = "The page was successfully updated.";
} else {
// Failed
$message = "The page could not be updated.";
$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("header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page, $public = false); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<h2>Adding New Page</h2>
<?php if (!empty($message)) {
echo "<p class=\"message\">" . $message . "</p>";
} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>

<form action="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="edit_subject.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
</td>
</tr>
</table>
<?php include("footer.php"); ?>

abduraooft
10-22-2012, 10:46 AM
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'' at line 6 ..
Change
$query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}"; to

echo $query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}"; and post the output here.

PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.

crisean
10-22-2012, 11:18 AM
The problem is it still not working, my difficult part is i don't know how to spot the errors,here's the one I code edit_page.php, because the link still not out (forgive me if you would torture you, because I just really want to learn php, many thanks if you can help me.):
<?php require_once("connection.php"); ?>
<?php require_once("function.php"); ?>
<?php
// make sure the subject id sent is an integer
if (intval($_GET['page']) == 0) {
redirect_to("content.php");
}

include_once("form_function.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 validations 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 the database
$id = mysql_esc($_GET['page']);
$menu_name = trim(mysql_esc($_POST['menu_name']));
$position = mysql_esc($_POST['position']);
$visible = mysql_esc($_POST['visible']);
$content = mysql_esc($_POST['content']);

// Database submission only proceeds if there were NO errors.
if (empty($errors)) {
$query = "UPDATE pages SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
$result = mysql_query($query);
// test to see if the update occured
if (mysql_affected_rows() == 1) {
// Success!
$message = "The page was successfully updated.";
} else {
$message = "The page could not be updated.";
$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("header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<h2>Edit page: <?php echo $sel_page['menu_name']; ?></h2>
<?php if (!empty($message)) {echo "<p class=\"message\">" . $message .
"</p>";} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>

<form action="editing_page.php?page=<?php echo $sel_page['id']; ?>"
method="post">
<?php include "page_form.php" ?>
<input type="submit" name="submit" value="Update Page" />&nbsp;&nbsp;
<a href="delete_page.php?page=<?php echo $sel_page['id']; ?>"
onclick="return confirm('Are you sure you want to delete this page?');">Delete Page</a>
</form>
<br />
<a href="content.php?page=?php echo $sel_page['id']; ?>">Cancel</a><br />
</td>
</tr>
</table>
<?php include("footer.php"); ?>

Redcoder
10-22-2012, 11:28 AM
Crisean,
This:

Change
$query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}"; to

echo $query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}"; and post the output here.

PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.

Was not supposed to solve the problem but to shed light on the specific nature of it by echoing it out. So do as said above and post the output of the echo here.

Offtopic: Don't use $_POST['submit'] to check whether a form has been submitted. Here's why (http://www.codingforums.com/showthread.php?t=240088).

And do use [PHP] tags to wrap your code mate.

crisean
10-22-2012, 11:55 AM
ahm, should it be LIKE this?
:confused::confused::confused::confused:(I hope you forgive me because I do not immediately understand, I still make mistakes (but I really want to learn), sometimes I just do not understand ..):o:o:o :



<?php require_once("connection.php"); ?>
<?php require_once("function.php"); ?>
<?php
// make sure the subject id sent is an integer
if (intval($_GET['subj']) == 0) {
redirect_to("content.php");
}

include_once("form_function.php");

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

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

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

// clean up form data before putting it in the database
$id = mysql_esc([PHP]);
$menu_name = trim(mysql_esc(PHP));
$position = mysql_esc([PHP]);
$visible = mysql_esc([PHP]);
$content = mysql_esc([PHP]);

Redcoder
10-22-2012, 12:10 PM
Your still posting the same way as before. Use [PHP] to highlight the code and syntax.

You have not posted the error, haven't followed what Abduraooft told you. Add 'echo' where he told you to or mysql_error() to your code.

Read this thread on VBulletin [PHP] tags - http://www.codingforums.com/showthread.php?t=68462

crisean
10-23-2012, 05:42 AM
But, it still doesn't work, i guess there's a little bit problem on my syntax either on the edit_page.php(code) or new_page.php(code) or maybe in my page_form.php(a new code where my formed place):

// thanks for helping me again...
// this is my page_form.php code...

<?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>

Redcoder
10-23-2012, 10:23 AM
If this is still you errror:


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'' at line 6 ..


The problem is not in page_form.php. It's in new_page.php . If you want to get to the bottom of it, debug this :




$query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
echo $query; //Add this and then post what is echoed back here so that we can help you. We can't help you if we don't know what the query looks like
$result = mysql_query($query) or die(mysql_error()); //See the mysql_error I added here



Read the comments in the code and then post back so that we can help you

JohnRomanPHP
10-23-2012, 10:49 AM
Hi good day, i think you don't need to use braces?? It should be parentheses. Also, your code is to crowded, you can use indention's so the codes will be much clearer.

You can start from the basics before proceeding with difficult topics. You need a basic background of the topic. Well, you can find helpful tips in w3schools. It is a free web tutorial for any programming language.

Good luck and hope you find a solution to your problem. =)

crisean
10-23-2012, 11:34 AM
i already had the thoughts in my mind that the problem is the new_page.php code is the problem, but because i am a beginner i just blame edit_page.php code and page_form.php code... Sorry bout it..



ohhh by the way i add it already in my code the php code that you gave and then i started to add a new page and it echoed this error message:

UPDATE page SET menu_name = 'Test Page', position = 3, visible = 1, content = 'This is a test.' WHERE id = 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 '' at line 6

:confused::confused::confused::confused: is there a possible ways we can fix it? sometimes i always reviewed my syntax for expecting maybe that there is a lacking on my codes... sorry for the interuptions again... thanks in advance SIR REDCODER.!

Redcoder
10-23-2012, 11:46 AM
Do you see the below, id= ???? NOthing so that means that the problem is the $id variable which is empty.



UPDATE page SET menu_name = 'Test Page', position = 3, visible = 1, content = 'This is a test.' WHERE id =


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 '' at line 6



So the problem originates from:


$id = mysql_esc($_GET['page']);

You should first check whether $_GET['page'] is empty or not. So add something like :



if(!empty($_GET['page'])){
$id = mysql_esc($_GET['page']);
}
else{
//Jump everything and prompt user to enter the page input field
}

crisean
10-23-2012, 12:14 PM
sorry again if im cuddled you again for helping me...

cause i already put it in, but still it gave me back the error message that i replied to you which the $id variable is empty...


im sure that your confused also on my problem... im really really sorry SIR!
:o:o:o:o:o:o:o

Redcoder
10-23-2012, 12:45 PM
sorry again if im cuddled you again for helping me...

cause i already put it in, but still it gave me back the error message that i replied to you which the $id variable is empty...


im sure that your confused also on my problem... im really really sorry SIR!
:o:o:o:o:o:o:o

Post the new code which you have after applying the above solutions.

abduraooft
10-23-2012, 01:11 PM
How does the url in the address bar of your browser look like, when you get all these errors?

crisean
10-24-2012, 07:31 AM
Here is the new code for the new_page.php code that i apply after i read your certain solutions sir Redcoder:



<?php require_once("connection.php"); ?>
<?php require_once("function.php"); ?>
<?php
// make sure the subject id sent is an integer
if (intval($_GET['subj']) == 0) {
redirect_to("content.php");
}

include_once("form_function.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 validations on the form data
$required_fields = array('menu_name','position','visible','content');
$errors = array_merge($errors, check_required_fields($required_fields));

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

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

// Database submission only proceeds if there were NO errors.
if (empty($errors)) {
$query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
echo $query; // Add this and then post what is echoed back here so that we can help you. We can't help you if we don't know what the query looks like
$result = mysql_query($query) or die(mysql_error()); // See the mysql_error I added here
$result = mysql_query($query);

// test to see if the update occured
if (mysql_affected_rows() == 1) {
// Success!
$message = "The page was successfully updated.";
} else {
// Failed
$message = "The page could not be updated.";
$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("header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page, $public = false); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<h2>Adding New Page</h2>
<?php if (!empty($message)) {
echo "<p class=\"message\">" . $message . "</p>";
} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>

<form action="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="edit_subject.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
</td>
</tr>
</table>
<?php include("footer.php"); ?>





and here's the address "http://localhost/widget_corp/new_page.php?subj=1"
and at the browser's page i saw a big error message: "UPDATE page SET menu_name = 'Test Page', position = 3, visible = 1, content = 'This is a test.' WHERE id = 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 '' at line 6"
(no background color it's totally all white background...):(:(:(:(

abduraooft
10-24-2012, 09:09 AM
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
PS: Please edit your post and add
][/COLOR] tags around your code, to make it readable. Thanks.
http://www.codingforums.com/showthread.php?t=68462
http://www.codingforums.com/showthread.php?t=68462
........................ :(

crisean
10-24-2012, 09:20 AM
im really really sorry abduraooft, cause this is my 1st time to enter the world of php and this codingforum site... i thought that i should put
tags ON my own codes on my text editor to for launching my stupid problem.... im really apologizing you sir! i just thought that [PHP] tag is not for vbulletin i thought it should be use in my text editor.... sorry for the big embarassing mistake!!: The: The: The: The: The




Here is the new code for the new_page.php code that i apply after i read your certain solutions sir Redcoder:




[PHP]
<?php require_once("connection.php"); ?>
<?php require_once("function.php"); ?>
<?php
// make sure the subject id sent is an integer
if (intval($_GET['subj']) == 0) {
redirect_to("content.php");
}

include_once("form_function.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 validations on the form data
$required_fields = array('menu_name','position','visible','content');
$errors = array_merge($errors, check_required_fields($required_fields));

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

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

// Database submission only proceeds if there were NO errors.
if (empty($errors)) {
$query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
echo $query; // Add this and then post what is echoed back here so that we can help you. We can't help you if we don't know what the query looks like
$result = mysql_query($query) or die(mysql_error()); // See the mysql_error I added here
$result = mysql_query($query);

// test to see if the update occured
if (mysql_affected_rows() == 1) {
// Success!
$message = "The page was successfully updated.";
} else {
// Failed
$message = "The page could not be updated.";
$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("header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page, $public = false); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<h2>Adding New Page</h2>
<?php if (!empty($message)) {
echo "<p class=\"message\">" . $message . "</p>";
} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>

<form action="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="edit_subject.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
</td>
</tr>
</table>
<?php include("footer.php"); ?>





and here's the address "http://localhost/widget_corp/new_page.php?subj=1"
and at the browser's page i saw a big error message: "UPDATE page SET menu_name = 'Test Page', position = 3, visible = 1, content = 'This is a test.' WHERE id = 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 '' at line 6"
(no background color it's totally all white background...)

abduraooft
10-24-2012, 09:27 AM
$id = mysql_esc($_GET['page']);

and here's the address "http://localhost/widget_corp/new_page.php?subj=1"

How do you assume the variable $id would get some value when there's no variable named page present in the query string?

Shouldn't that url be something like
http://localhost/widget_corp/new_page.php?subj=1&page=1 ?

crisean
10-24-2012, 09:48 AM
It should be change... cause the edit page link won't work in this address(unfortunately delete page link won't also rendered):

http://localhost/widget_corp/content.php?page=1


and on adding a new page at this address:

still it won't work either...

http://localhost/widget_corp/new_page.php?subj=1



is there still a chance for me to fix this big problem, cause it's like putting a thread through a very small hole on the needle and i can't enter it for how many days now... that's why i enter this cf just needing someone who can help me...

crisean
10-24-2012, 10:24 AM
I have this new_page.php code which we thought that this code has a problem:




<?php require_once("connection.php"); ?>
<?php require_once("function.php"); ?>
<?php
// make sure the subject id sent is an integer
if (intval($_GET['subj']) == 0) {
redirect_to("content.php");
}

include_once("form_function.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 validations on the form data
$required_fields = array('menu_name','position','visible','content');
$errors = array_merge($errors, check_required_fields($required_fields));

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

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

// Database submission only proceeds if there were NO errors.
if (empty($errors)) {
$query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
echo $query; // Add this and then post what is echoed back here so that we can help you. We can't help you if we don't know what the query looks like
$result = mysql_query($query) or die(mysql_error()); // See the mysql_error I added here
$result = mysql_query($query);

// test to see if the update occured
if (mysql_affected_rows() == 1) {
// Success!
$message = "The page was successfully updated.";
} else {
// Failed
$message = "The page could not be updated.";
$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("header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page, $public = false); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<h2>Adding New Page</h2>
<?php if (!empty($message)) {
echo "<p class=\"message\">" . $message . "</p>";
} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>

<form action="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="edit_subject.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
</td>
</tr>
</table>
<?php include("footer.php"); ?>



I also think there is a problem as well edit_page.php my code:





<?php require_once("connection.php"); ?>
<?php require_once("function.php"); ?>
<?php
// make sure the subject id sent is an integer
if (intval($_GET['page']) == 0) {
redirect_to("content.php");
}

include_once("form_function.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 validations 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 the database
$id = mysql_esc($_GET['page']);
$menu_name = trim(mysql_esc($_POST['menu_name']));
$position = mysql_esc($_POST['position']);
$visible = mysql_esc($_POST['visible']);
$content = mysql_esc($_POST['content']);

// Database submission only proceeds if there were NO errors.
if (empty($errors)) {
$query = "UPDATE pages SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
$result = mysql_query($query);
// test to see if the update occured
if (mysql_affected_rows() == 1) {
// Success!
$message = "The page was successfully updated.";
} else {
$message = "The page could not be updated.";
$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("header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<h2>Edit page: <?php echo $sel_page['menu_name']; ?></h2>
<?php if (!empty($message)) { echo "<p class=\"message\">" . $message .
"</p>"; } ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>

<form action="edit_page.php?page=<?php echo $sel_page['id']; ?>"
method="post">
<?php include "page_form.php" ?>
<input type="submit" name="submit" value="Update Page" />&nbsp;&nbsp;
<a href="delete_page.php?page=<?php echo $sel_page['id']; ?>"
onclick="return confirm('Are you sure you want to delete this page?');">Delete
page</a>
</form>
<br />
<a href="content.php?page=<?php echo $sel_page['id']; ?>">Cancel</a><br />
</td>
</tr>
</table>
<?php include("footer.php"); ?>


<?php include("footer.php"); ?>



please watch this picture:

file:///var/www/widget_corp/content page 3

at the bottom of the content(this is the company history and so on) there should be a link that is written as Edit page for i to edit or delete my page, but it doesn't work...



and on this other picture:

is the edit subject page:
- file:///var/www/widget_corp/edit_subject page


it works fine totally, but when i click the link page written on it:
- add a new page on this subject(at the very bottom of the page)...


it works fine, but a little problem is that the page should be empty...

and the worst problem is when im going to add a new page and hit Create Page at the bottom, it gives me this big error which i tell you that the background on it is whole white and only this error message is written on the browser's page:

"UPDATE page SET menu_name = 'History', position = 1, visible = 1, content = 'This is the company history...\r\nAnd that\'s it.' WHERE id = 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 '' at line 6"...



that is all of details on my biggest and worst problem in my life...!!!!:(:(:(:(

Redcoder
10-24-2012, 11:19 AM
Use curly braces to cover the steps covered by the if statement.

Like this:




<?php require_once("connection.php"); ?>
<?php require_once("function.php"); ?>
<?php
// make sure the subject id sent is an integer
if (intval($_GET['subj']) == 0) {
redirect_to("content.php");
}

include_once("form_function.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 validations on the form data
$required_fields = array('menu_name','position','visible','content');
$errors = array_merge($errors, check_required_fields($required_fields));

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

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

// Database submission only proceeds if there were NO errors.
if (empty($errors)) {
$query = "UPDATE page SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
echo $query; // Add this and then post what is echoed back here so that we can help you. We can't help you if we don't know what the query looks like
$result = mysql_query($query) or die(mysql_error()); // See the mysql_error I added here
$result = mysql_query($query);

// test to see if the update occured
if (mysql_affected_rows() == 1) {
// Success!
$message = "The page was successfully updated.";
} else {
// Failed
$message = "The page could not be updated.";
$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.";
}
}
}
else{

echo "No Page Variable";
}
// END FORM PROCESSING
}
?>
<?php find_selected_page(); ?>
<?php include("header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page, $public = false); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<h2>Adding New Page</h2>
<?php if (!empty($message)) {
echo "<p class=\"message\">" . $message . "</p>";
} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>

<form action="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="edit_subject.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
</td>
</tr>
</table>
<?php include("footer.php"); ?>

crisean
10-24-2012, 11:47 AM
http://file:///var/www/widget_corp/here's what happened as I get pictures from my browser while I changed the code you've provided me Redcoder

crisean
10-24-2012, 12:06 PM
http://localhost/content%20page%203

at the bottom of the content(this is the company history and so on) there should be a link that is written as Edit page for i to edit or delete my page, but it doesn't work...


and on this other picture:

is the edit subject page:
http://localhost/edit_subject%20page


it works fine totally, but when i click the link page written on it:
- add a new page on this subject(at the very bottom of the page)...


it works fine, but a little problem is that the page should be empty...

and the worst problem is when im going to add a new page and hit Create Page at the bottom, it gives me this big error which i tell you that the background on it is whole white and only this error message is written on the browser's page:


http://localhost/new_page%20page%202



"UPDATE page SET menu_name = 'History', position = 1, visible = 1, content = 'This is the company history...\r\nAnd that\'s it.' WHERE id = 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 '' at line 6"...






here's what happened as I get pictures from my browser while I changed the code you've provided me Redcoder:

http://localhost/here's%20what%20happened%20as%20I%20get%20pictures%20from%20my%20browser%20while%20I%20changed%20the %20code%20you've%20provided%20me%20Redcoder

Redcoder
10-24-2012, 01:52 PM
We can't see files on your localhost. If you want us to see them, you need to upload them to an online server. You can try free hosts like http://1freehosting.com (http://1freehosting.com)

crisean
10-25-2012, 02:28 AM
ohhh.. GEEZ... even the picture that i paste in?? you can't even see it also??

hmmmmp.. okay, i will do your advices.... thanks!

abduraooft
10-25-2012, 09:14 AM
Could you provide the php source of the page that comes before this particular page (the one that contains the link to this page)?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum