bruckerrlb Posted November 16, 2007 Share Posted November 16, 2007 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 https://forums.phpfreaks.com/topic/77558-solved-update-mysql-with-php/ Share on other sites More sharing options...
premiso Posted November 16, 2007 Share Posted November 16, 2007 <?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 https://forums.phpfreaks.com/topic/77558-solved-update-mysql-with-php/#findComment-392583 Share on other sites More sharing options...
bruckerrlb Posted November 16, 2007 Author Share Posted November 16, 2007 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 https://forums.phpfreaks.com/topic/77558-solved-update-mysql-with-php/#findComment-392595 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.