...

View Full Version : Updating mysql with php!! Help!!



wincode
03-18-2010, 08:39 PM
Hello. I'm new to php/mysql. But I wanted to make a page where I can update a table in mysql. The page where I would do that is /addpage.php. I'm using an editor to get the content in HTML and then put it into a table in mysql

addpage.php

<html><head><script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,previ ew,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,non breaking,xhtmlxtras,template",
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,just ifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|, undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,b ackcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,| ,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,vis ualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
template_external_list_url : "example_template_list.js"
});

</script>
</head>
<?php
include ('config.php');
if ($_GET[done] == 1) {

mysql_connect("$server", "$username", "$password") or die ($theError);
mysql_select_db("$database") or die ($theError);

mysql_query("INSERT INTO pages
(pagez)
VALUES
('$_POST[content]')");

} else {
?>
<body>
<form id="form1" name="form1" method="post" action="?done=1">
<label>
<div align="center"><span class="style1">Page name <br />

</span></div>
</label>
<p align="center" class="style1">
<label>Page content <b>(HTML)</b><br />
<textarea name="content" cols="75" rows="4"></textarea>
</label>
</p>
<p align="center" class="style1">
<label></label>
</p>
<p align="center">
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
<label>
<input type="reset" name="Submit2" value="Reset" />
</label>
</p>
</form>
<? }
?>
</body>
</html>


So when I go check the table in mysql, it's not updated.

Please help :(

Fou-Lu
03-18-2010, 08:53 PM
mysql_query("INSERT INTO pages
(pagez)
VALUES
('$_POST[content]')") or die(mysql_error());


Is it whining about a duplicate key for entry ''?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum