joshgarrod Posted March 23, 2008 Share Posted March 23, 2008 Hi everyone, i had a perfectly working CMS that I have built to run my website on. I had it running on the back one of my servers but the time had to come to move it pover to it's own one. Wehn I moved it I changed all the details in the script to the new settings of the new database and server but the information wil not submit to the database. I don't understand becuase it worked fine on the other server and it is the same script but now it doesn't work. below is the entire page's script and the Notice that I am gettin, can anyone offer any help please? Thanks in advance. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Add Categories</title> <style type="text/css"> a{ color:black; text-decoration:none;} a:hover {color:#809c00; text-decoration:none;} .smalblk {font-size: 7pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #252525;} .smalblk a:link {color: #252525; text-decoration:none;} .smalblk a:visited {color: #252525; te xt-decoration:none;} .smalblk a:active {color: #252525; text-decoration:none;} .smalblk a:hover {color: #809c00; text-decoration:none;} .smalblkbold {font-size: 7pt; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: left; color: #252525;} .smalblkbold a:link {color: #252525; text-decoration:none;} .smalblkbold a:visited {color: #252525; text-decoration:none;} .smalblkbold a:active {color: #252525; text-decoration:none;} .smalblkbold a:hover {color: #809c00; text-decoration:none;} .smalwht {font-size: 7pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #ffffff;} .smalwht a:link {color: #ffffff; text-decoration:none;} .smalwht a:visited {color: #ffffff; text-decoration:none;} .smalwht a:active {color: #ffffff; text-decoration:none;} .smalwht a:hover {color: #809c00; text-decoration:none;} .wht8 {font-size: 8pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #ffffff;} .wht8 a:link {color: #ffffff; text-decoration:none;} .wht8 a:visited {color: #ffffff; text-decoration:none;} .wht8 a:active {color: #ffffff; text-decoration:none;} .wht8 a:hover {color: #809c00; text-decoration:none;} .wht10 {font-size: 10pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: right; color: #ffffff;} .wht10 a:link {color: #ffffff; text-decoration:none;} .wht10 a:visited {color: #ffffff; text-decoration:none;} .wht10 a:active {color: #ffffff; text-decoration:underline;} .wht10 a:hover {color: #809c00; text-decoration:none;} .wht12 {font-size: 12pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #ffffff;} .wht12 a:link {color: #ffffff; text-decoration:none;} .wht12 a:visited {color: #ffffff; text-decoration:none;} .wht12 a:active {color: #ffffff; text-decoration:none;} .wht12 a:hover {color: #809c00; text-decoration:underline;} .wht14 {font-size: 14pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #ffffff;} .wht14 a:link {color: #ffffff; text-decoration:none;} .wht14 a:visited {color: #ffffff; text-decoration:none;} .wht14 a:active {color: #ffffff; text-decoration:none;} .wht14 a:hover {color: #809c00; text-decoration:none;} .blu14 {font-size: 14pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #809c00;} .blu14 a:link {color: #809c00; text-decoration:none;} .blu14 a:visited {color: #809c00; text-decoration:none;} .blu14 a:active {color: #809c00; text-decoration:none;} .blu14 a:hover {color: #809c00; text-decoration:none;} .wht18 {font-size: 18pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #ffffff;} .wht18 a:link {color: #ffffff; text-decoration:none;} .wht18 a:visited {color: #ffffff; text-decoration:none;} .wht18 a:active {color: #ffffff; text-decoration:none;} .wht18 a:hover {color: #809c00; text-decoration:none;} .smalblu {font-size: 8pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #809c00;} .smalblu a:link {color: #809c00; text-decoration:none;} .smalblu a:visited {color: #809c00; text-decoration:none;} .smalblu a:active {color: #809c00; text-decoration:none;} .smalblu a:hover {color: #809c00; text-decoration:none;} .productbold {font-size: 8pt; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: left; color: #252525;} .productbold a:link {color: #252525; text-decoration:none;} .productbold a:visited {color: #252525; text-decoration:none;} .productbold a:active {color: #252525; text-decoration:none;} .productbold a:hover {color: #809c00; text-decoration:none;} .product {font-size: 8pt; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; text-align: left; color: #252525;} .product a:link {color: #252525; text-decoration:none;} .product a:visited {color: #252525; text-decoration:none;} .product a:active {color: #252525; text-decoration:none;} .product a:hover {color: #809c00; text-decoration:none;} .ordercode {font-size: 7pt; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; text-align: left; color: #252525;} .ordercode a:link {color: #252525; text-decoration:none;} .ordercode a:visited {color: #252525; text-decoration:none;} .ordercode a:active {color: #252525; text-decoration:none;} .ordercode a:hover {color: #809c00; text-decoration:none;} .featuredblu {font-size: 9pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #809c00;} .featuredblu a:link {color: #809c00; text-decoration:none;} .featuredblu a:visited {color: #809c00; text-decoration:none;} .featuredblu a:active {color: #809c00; text-decoration:none;} .featuredblu a:hover {color: #809c00; text-decoration:none;} .menu {font-size: 10pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: center; color: #252525;} .menu a:link {color: #252525; text-decoration:none;} .menu a:visited {color: #252525; text-decoration:none;} .menu a:active {color: #252525; text-decoration:none;} .menu a:hover {color: #809c00; text-decoration:none;} .featuredblubold {font-size: 9pt; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: left; color: #809c00;} .featuredblubold a:link {color: #809c00; text-decoration:none;} .featuredblubold a:visited {color: #809c00; text-decoration:none;} .featuredblubold a:active {color: #809c00; text-decoration:none;} .featuredblubold a:hover {color: #809c00; text-decoration:none;} .welcome {font-size: 8pt; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left; color: #252525;} .welcome a:link {color: #252525; text-decoration:none;} .welcome a:visited {color: #252525; text-decoration:none;} .welcome a:active {color: #252525; text-decoration:none;} .welcome a:hover {color: #809c00; text-decoration:none;} .border {border: 2px solid #809c00;} .borderbottom {border-bottom: 2px solid #809c00; font-size: 8pt; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: center; color: #252525;} .mainborder {border-right: 2px solid #809c00;} </style> </head> <body> <font face="Arial, Helvetica, sans-serif"> <?php $usr = "username"; $pwd = "password"; $db = "database"; $host = "ipofserver"; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> </font> <P>Add Category</P> <P>To add a category please fill in the 'Category name' field and then click the 'Add Category' button. </P> <font face="Arial, Helvetica, sans-serif"> <?php # this is processed when the form is submitted # back on to this page (POST METHOD) if ($REQUEST_METHOD=="POST") { # double-up apostrophes $Catname = str_replace("'","''",$Catname); # setup SQL statement $SQL = " INSERT INTO Categories "; $SQL = $SQL . " (Catname) VALUES "; $SQL = $SQL . " ('$Catname') "; #execute SQL statement $result = mysql_db_query($db,"$SQL",$cid); $ID=mysql_insert_id(); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo ("<P>New Category $Catname added</P>\n"); } ?> </font> <FORM NAME="fa" ACTION="addCat.php" METHOD="POST"> <TABLE width="392"> <TR> <TD width="133"><font face="Arial, Helvetica, sans-serif"><B>Category name :</B> </font></TD><TD width="247"><font face="Arial, Helvetica, sans-serif"> <INPUT NAME="Catname" TYPE="text" id="Catname" SIZE=40> </font></TD></TR> <TR> <TH COLSPAN=2><font face="Arial, Helvetica, sans-serif"> <input name="submit" type="submit" value="Add Category" /> </font></TH> </TR> </TABLE> <p align="center"> </p> </FORM> <font face="Arial, Helvetica, sans-serif"> <?php mysql_close($cid); ?> </font> </BODY> </HTML> </body> </html> Notice: Undefined variable: REQUEST_METHOD in e:\domains\e\site\user\htdocs\admin\addCat.php on line 121 Link to comment https://forums.phpfreaks.com/topic/97476-adding-data-to-database/ Share on other sites More sharing options...
wildteen88 Posted March 23, 2008 Share Posted March 23, 2008 That script appears to rely on register_globals. Register_globals has been depreciated and is turned off by default, this is why your script is not working. You should attempt to update your script so it doesn't rely on register_globals. $REQUEST_METHOD should be $_SERVER['REQUEST_METHOD']; $Catname should be $_POST['Catname']; Also the following is not secure enough: Catname = str_replace("'","''",$Catname); I'd change it to: Catname = mysql_real_escape_string($_POST['Catname']); $_SERVER and $_POST are predefined variables called superglobals. Link to comment https://forums.phpfreaks.com/topic/97476-adding-data-to-database/#findComment-498740 Share on other sites More sharing options...
joshgarrod Posted March 23, 2008 Author Share Posted March 23, 2008 So where you have said '$REQUEST_METHOD should be $_SERVER['REQUEST_METHOD'];' how does that go into the script and when you say '$Catname should be $_POST['Catname'];' does that mean every mention of '$Catname' or just one particular time. thanks Link to comment https://forums.phpfreaks.com/topic/97476-adding-data-to-database/#findComment-498745 Share on other sites More sharing options...
wildteen88 Posted March 23, 2008 Share Posted March 23, 2008 Sorry for the confusion, yes any instance of $REQUEST_METHOD you should change to $_SERVER['REQUEST_METHOD']; As for "$Catname should be $_POST['Catname'];" I forgot to delete that part. Instead do the following: Also the following is not secure enough: $Catname = str_replace("'","''",$Catname); I'd change it to: $Catname = mysql_real_escape_string($_POST['Catname']); Link to comment https://forums.phpfreaks.com/topic/97476-adding-data-to-database/#findComment-498759 Share on other sites More sharing options...
joshgarrod Posted March 23, 2008 Author Share Posted March 23, 2008 Ok, great thanks, that has solved one probelm but also created another lol. when ever i load the page it automatically runs the script and add a new category, i have similar scripts that d other thngs like i have a script that displays my welcome message for my homepage and i can edit it and resubmit it but before it can select the data from the database it has already updated it as blank. Also I am getting this notice: Notice: Undefined index: Catname in e:\domains\e\site\user\htdocs\admin\addCat.php on line 124 Link to comment https://forums.phpfreaks.com/topic/97476-adding-data-to-database/#findComment-498761 Share on other sites More sharing options...
wildteen88 Posted March 23, 2008 Share Posted March 23, 2008 Before using any variables which come from the user ($_POST, $_GET or $_COOKIE) then you should always check that they exist first before using then and apply some validation/varification, eg: if(isset($_POST['Catname']) && !empty($_POST['Catname'])) { $Catname = $_POST['Catname']; // place your code here. } Link to comment https://forums.phpfreaks.com/topic/97476-adding-data-to-database/#findComment-498766 Share on other sites More sharing options...
joshgarrod Posted March 24, 2008 Author Share Posted March 24, 2008 please could you show me the example in my code as i am not to sure how you mean. thanks Link to comment https://forums.phpfreaks.com/topic/97476-adding-data-to-database/#findComment-499413 Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 I have, look at my code example above. If you do not understand if statements then you should have a read of the manaul Link to comment https://forums.phpfreaks.com/topic/97476-adding-data-to-database/#findComment-499542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.