user3600707
user3600707

Reputation: 27

PHP Edit Form Not Sending to MySql properly

I am using a php script to allow my friend to edit pages on our web server. The code seems to work and the success message shows but when I go into the mysql database sectionone is empty.

Form:

<?php
require '/home/factcats/public_html/admin/connection2.php';
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$result = mysql_query("SELECT * FROM `background`");
while($row = mysql_fetch_assoc($result)){
?>
<section>
<div class='row'>
<form action="process.php" method="post"> 
<div>
<label for="sectionone">Section One</label>
<textarea value="" class="form-control" type="text" size="300" name rows="20" = "sectionone"><?php
echo "".$row['sectionone'].""; ?> </textarea>
</div>
<div>
<label for="sectiontwo">Section Two</label>
<textarea value="" class="form-control" type="text" size="300" rows="20" name = "sectiontwo"><?php
echo "".$row['sectiontwo'].""; ?></textarea>
</div>
<br>
<input class="btn btn-primary" name="submit" type="submit" value="Update"/>
</form>
</div>
</DIV>
<?php
}
?>

Process.PHP:

<?php
$sectionone=addslashes($_POST['sectionone']);
$sectiontwo=addslashes($_POST['sectiontwo']); 
if(isset($_POST['submit'])) {
   require '/home/factcats/public_html/admin/connection2.php';
   mysql_connect($host, $user, $pass);
   mysql_select_db($db);
   mysql_query("UPDATE `background` SET sectionone='$sectionone', sectiontwo='$sectiontwo' WHERE id=1");    
 } else {
    Print "Something went wrong please go back!";
 }
 ?>

What's even stranger is that section two saves fine.

Upvotes: 1

Views: 41

Answers (2)

Jens
Jens

Reputation: 69440

You split the name attribute in your html:

name rows="20" = "sectionone"><?

chnage it to:

name = "sectionone"  rows="20"><?

and it will work.

Also stop using deprecated mysql_* API. Use mysqli_* or PDOwith prepared statements.

Upvotes: 3

low_rents
low_rents

Reputation: 4481

you got a typo in your html:

change

<textarea value="" class="form-control" type="text" size="300" name rows="20" = "sectionone"><?php
echo "".$row['sectionone'].""; ?> </textarea>

to

<textarea value="" class="form-control" type="text" size="300" rows="20" name="sectionone"><?php
    echo "".$row['sectionone'].""; ?> </textarea>

Upvotes: 1

Related Questions