Jump to content

insterting content data into mysql


chandler

Recommended Posts

Hi, can some one please explain to me the best way to do this, currently I am using txt files on the server to hold the content of the webpage for example:  header, title_1, paragraph_1, title_2, paragraph_2 etc.

But with more content this is getting very tedious and I'm sure using mysql would be better

 

here's how it works now ( write to file)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="">
<meta name="description" content="  ">
<meta name="robots" content="FOLLOW,INDEX">
<title></title>
<link rel='stylesheet' href='../css/style.css' type='text/css'>
<link rel="shortcut icon" href="">
<script type="text/javascript" src="../js/ckeditor/ckeditor.js"></script>
</head>
<body>
<?php 
//This condition will check either the submit button was pressed, for such test you need to check that if there is an element which has the same name as your button.
if(isset($_POST['Submit']))
{	
	//this is just the name of the file, it can be used directly but its better to use a variable its just for convinence
	$file = "../content/menu_header_a.txt";

	if(is_writable($file))
	{

		//this is to open the file in write more 'w' says that it will open in writeable more
		$fh = fopen($file, 'w') or die("can't open file");

		//I again used a variable to store the data.... which is to be written to the file
		//The main point is to receive the data on submit, it is when submit is done, and uppon condition for submit is fulfilled
		//all the elements of the form are put in the array named $_POST and you can get their values by their names
		//in the same way I just took the value of 'editor1' it is the name for textarea in which you displayed the text
		$data = stripslashes(stripslashes($_POST['editor_header_a']));


		///This routine will just write the data to file given the file handle and the data.
		fwrite($fh, $data);

		//must close the file after all writing is done.
		fclose($fh);
	}
	else
	{
		echo "File is Not Writable<br>";
	}
}

?>
<form method="post">
		<textarea name="editor_header_a">
<?php
$file = file_get_contents('../content/menu_header_a.txt');
echo $file;
?>
</textarea>
		<script type="text/javascript">
			CKEDITOR.replace( 'editor_header_a',
    {
        toolbar : 
        [
        ['Source','-','Save','NewPage','Preview','-','Templates'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
    '/',
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    ['Link','Unlink','Anchor'],
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
    '/',
    ['Styles','Format','Font','FontSize'],
    ['TextColor','BGColor'],
    ['Maximize', 'ShowBlocks','-','About']
        ]
    });
		</script>
	</p>
	<p>
		<input name="Submit" type="submit" />
	</p>
</form>
</body>
</html>

 

display content from file.

<?php $file = file_get_contents('content/menu_header_a.txt', 'r');  if(isset($_SESSION['user_id'])){ ?><a href="javascript:open4()"><?php echo $file ?></a><?php } else { echo $file; }?>

 

js

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}

function open4(){
var open4 =
window.open('http://localhost/projects/public_html/contentscript/content_menu_header_a.php','jav','width=540,height=480,resizable=yes');
}

 

I like the way it works currently, I just have to click on the content I want to make changes to for the wysiwyg editor to open up but these txt files are doing my head in:).

btw Im a still learning all this please try to keep it simple for me

 

Thanks for you help.

Link to comment
Share on other sites

Would it work  like this? if I am editing header and the textarea box opens how does it know that im changing the header and not title_2 for example?

 

 

insert.php

mysql_query("INSERT INTO Content (Header, Title_, Paragraph_1, Title_2, Paragraph_2)
VALUES ('My Header', 'My Title', 'Paragraph 1', 'Title 2', 'Paragraph 2')");

 

 

Editor.php

<html>
<body>
<form ation="insert.php" method="post">
		<textarea name="editor_header_a"></textarea>
			<script type="text/javascript">
			CKEDITOR.replace( 'editor_header_a',
    {
        toolbar : 
        [
        ['Source','-','Save','NewPage','Preview','-','Templates'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
    '/',
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    ['Link','Unlink','Anchor'],
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
    '/',
    ['Styles','Format','Font','FontSize'],
    ['TextColor','BGColor'],
    ['Maximize', 'ShowBlocks','-','About']
        ]
    });
		</script>
	</p>
	<p>
		<input name="Submit" type="submit" />
	</p>
</form>
</body>
</html>

 

 

 

Link to comment
Share on other sites

Would it work  like this? if I am editing header and the textarea box opens how does it know that im changing the header and not title_2 for example?

 

How does it know now which file to modify?  I can't see from your code as all you have now is for menu_header_a.  Are all of these on the same form or is there a separate form for each section?

Link to comment
Share on other sites

on a separate form for each section

 

in the content.php file there is this bit of code

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="">
<meta name="description" content="  ">
<meta name="robots" content="FOLLOW,INDEX">
<title>Uni-Kitchen</title>
<link rel='stylesheet' href='../css/style.css' type='text/css'>
<link rel="shortcut icon" href="">
<script type="text/javascript" src="../js/ckeditor/ckeditor.js"></script>
</head>
<body>
<?php 

//This condition will check either the submit button was pressed, for such test you need to check that if there is an element which has the same name as your button.
if(isset($_POST['Submit']))
{	
	//this is just the name of the file, it can be used directly but its better to use a variable its just for convinence
	$file = "../content/menu_header_a.txt";

	if(is_writable($file))
	{

		//this is the open the file in write more 'w' says that it will open in writeable more
		$fh = fopen($file, 'w') or die("can't open file");

		//I again used a variable to store the data.... which is to be written to the file
		//The main point is to receive the data on submit, it is when submit is done, and uppen condition for submit is fulfilled
		//all the elements of the form are put in the array named $_POST and you can get their values by their names
		//in the same way I just took the value of 'editor1' it is the name for textarea in which you displayed the text
		$data = stripslashes(stripslashes($_POST['editor_header_a']));


		///This routine will just write the data to file given the file handle and the data.
		fwrite($fh, $data);

		//must close the file after all writing is done.
		fclose($fh);
	}
	else
	{
		echo "File is Not Writable<br>";
	}
}


?>
<form method="post">
		<textarea name="editor_header_a">

// tells us what content to edit.
<?php
$file = file_get_contents('../content/menu_header_a.txt');
echo $file;
?>
</textarea>
		<script type="text/javascript">
			CKEDITOR.replace( 'editor_header_a',
    {
        toolbar : 
        [
        ['Source','-','Save','NewPage','Preview','-','Templates'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
    '/',
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    ['Link','Unlink','Anchor'],
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
    '/',
    ['Styles','Format','Font','FontSize'],
    ['TextColor','BGColor'],
    ['Maximize', 'ShowBlocks','-','About']

        ]
    });

		</script>
	</p>
	<p>

		<input name="Submit" type="submit" />
	</p>
</form>

</body>
</html>

 

I commeted the part that I think tells the editor what part is being edited.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.