Jump to content

[SOLVED] update mysql with php


bruckerrlb

Recommended Posts

Hello All, I am trying to update mysql with php. I know very elementary, but I am still a new guy, anyway, for some reason I am not able to show my php variable in my text area where I want to actually change the info in mysql and then update it.

 

Here is my update command

 

<?php

           include('db_connect.php');

	if(isset($_POST['submitnews']))  {

	 $query="UPDATE bio SET data='$data' WHERE id='1'";
                mysql_query($query);
                   echo "Record Updated";
                      mysql_close();
                    }

	      ?>

 

This is my update command which I haven't had a chance to test yet because I just haven't been able to see the actual data in the textarea yet. It's just one record, this is the code for that.

 

<?php	

include('db_connect.php');
$query = 'SELECT * FROM bio';
           $r = mysql_query ($query);
	    if ($r = mysql_query ($query)) {

while ($row = mysql_fetch_array ($r)) {
	$data = $_POST['data'];
	$id = $_POST['id'];
	?>
	<p>
         <FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="submitnews" id="submitnews">

		<textarea rows="10" id="news" name="news"><?php echo $_POST['data']; ?></textarea>

		</FORM></p>
	<?php

	}

	}
	else{
	print 'Failed';
	}

	?>

 

I can't seem to get any data to show up in the textarea. I have also tried to use the variable I declared, $data but it shows me $data in the textarea. Any help would be much appreciated. Thanks

Link to comment
Share on other sites

<?php	

include('db_connect.php');
$query = 'SELECT * FROM bio';
           $r = mysql_query ($query);
	    if ($r = mysql_query ($query)) {

while ($row = mysql_fetch_array ($r)) {
	$data = $row['data'];
	$id = $row['id'];
	?>
	<p>
         <FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="submitnews" id="submitnews">

		<textarea rows="10" id="news" name="news"><?php echo $data; ?></textarea>

		</FORM></p>
	<?php

	}

	}
	else{
	print 'Failed';
	}

	?>

 

 

You referred to it as $_POST instead of $row.

Link to comment
Share on other sites

Excellent, thanks! I wanted to post the remaining code correctly in case anyone has a problem with updating

 

include('db_connect.php');

	if(isset($_POST['submitnews']))  {



	$data = $_POST['data'];
	 $query="UPDATE bio SET data='$data' WHERE id='1'";
mysql_query($query);
echo "Record Updated";
mysql_close();

}

 

Thanks again!

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.