Jump to content

Noob- to edit database text


mdfcows

Recommended Posts

Hi, very new to all this, so don't really know too much!

 

I have been trying to edit some code to be able to retrieve some blocks of text from a database, then edit them and post them back.

 

I have managed to retrieve them, however I can't seem to be able to post them back to the database edited.

 

This is the code I'm using:

<?php
			require_once('config.php');

			$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
			if (!$con){
				die('Failed to connect to server' . mysql_error());
			}

			mysql_select_db(DB_DATABASE);

			$ide15 = $_POST[idf];
			$query15 = "SELECT id,titleus,aboutus FROM about WHERE id = 1";
			$result15 = mysql_query($query15) or die ("Query:<br />$query15<br />Error:<br />".mysql_error()); 

			while ($row15 = mysql_fetch_assoc ($result15)) {
				$title15 = htmlentities ($row15['titleus']);
				$news15 = nl2br (strip_tags ($row15 ['aboutus'], '<a><b><i><u>'));


				echo "<form class ='addform' action='editabouttext.php' enctype='multipart/form-data' method='post'>";
				echo "<p>Uttsav Title:<br /><input class='titlefield' type='text' name='title' value='$title15' /></p><br />";
				echo "<p>Uttsav About:<br /> <textarea name='news' rows='1' cols='15'>$news15</textarea></p><br />";
				echo "<p><input name='submit' type='submit' value='Submit' /></p>";
				echo "</form>";
			}

			if ($_POST['submit'])
			{
			  
			  mysql_select_db(DB_DATABASE);
			  
			  $upid = $_POST[idf];
			  $uptitle = $_POST[title];
			  $upnews = $_POST[news];
			  $upimage = $_FILES['userfile']['name'];
			  
			  $sql = "UPDATE about SET titleus = '$uptitle', aboutus = '$upnews', WHERE id = '1'";
			  
			  mysql_query($sql);
			  
			  if ($_POST['submit'])
			  {
				  
				  echo "<p class='admintext'>Your project thumbnail has now been edited - <a href='about.php'>View The About Page</a></p><br />";
				  $name = $_FILES['userfile']['name'];
				  $type = $_FILES['userfile']['type'];
				  $size = $_FILES['userfile']['size'];
				  $tmpname = $_FILES['userfile']['tmp_name'];
				  $ext = substr($name, strrpos($name, '.'));
				  
				  if (strstr($type, "image"))
				  {
					  move_uploaded_file($tmpname, "images/portfolio/".$name);
				  }
				  
			  }
			}
				  
			?>

I am using an apache server at the minute and have had this code working for other pages and scenarios, yet can't get it working on this, I think it may have something to do with the id of the post, but as I am only going to be using one post that will just get edited I took out the WHERE id = $ide15 and put in WHERE id = 1 as this is the id of the only post!

 

Any help would be much appreciated! as I said, just starting to get to grips with things like this!

 

Thank you

 

Martin

Link to comment
Share on other sites

1st I dont know where you are posting "$ide15 = $_POST[idf];" from

 

but try this code:

 

<?php
			require_once('config.php');

			$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
			if (!$con){
				die('Failed to connect to server' . mysql_error());
			}

			mysql_select_db(DB_DATABASE);

			$ide15 = $_POST[idf];
			$query15 = "SELECT id,titleus,aboutus FROM about WHERE id = $ide15";
			$result15 = mysql_query($query15) or die ("Query:<br />$query15<br />Error:<br />".mysql_error()); 

			while ($row15 = mysql_fetch_array ($result15)) {
				$title15 = htmlentities ($row15['titleus']);
				$news15 = nl2br (strip_tags ($row15 ['aboutus'], '<a><b><i><u>'));
				$id15 = $row['id'];


				echo "<form class ='addform' action='editabouttext.php' enctype='multipart/form-data' method='post'>";
				echo "<p>Uttsav Title:<br /><input class='titlefield' type='text' name='title' value='$title15' /></p><br />";
				echo "<input type='hidden' name='id' value='$id15'>";
				echo "<p>Uttsav About:<br /> <textarea name='news' rows='1' cols='15'>$news15</textarea></p><br />";
				echo "<p><input name='submit' type='submit' value='Submit' /></p>";
				echo "</form>";
			}

			if ($_POST['submit'])
			{
			  
			  mysql_select_db(DB_DATABASE);
			  
			  $upid = $_POST[id];
			  $uptitle = $_POST[title];
			  $upnews = $_POST[news];
			  $upimage = $_FILES['userfile']['name'];
			  
			  $sql = "UPDATE about SET titleus = '$uptitle', aboutus = '$upnews', WHERE id = '$upid'";
			  
			  mysql_query($sql);
			  
			  if ($_POST['submit'])
			  {
				  
				  echo "<p class='admintext'>Your project thumbnail has now been edited - <a href='about.php'>View The About Page</a></p><br />";
				  $name = $_FILES['userfile']['name'];
				  $type = $_FILES['userfile']['type'];
				  $size = $_FILES['userfile']['size'];
				  $tmpname = $_FILES['userfile']['tmp_name'];
				  $ext = substr($name, strrpos($name, '.'));
				  
				  if (strstr($type, "image"))
				  {
					  move_uploaded_file($tmpname, "images/portfolio/".$name);
				  }
				  
			  }
			}
				  
			?>

 

I am not sure if this code will work for sure but its worth a try. :)

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.