1

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.

2
  • 1
    Well firstly, move away from the mysql library and use mysqli or PDO. There are too many reasons why you should do this. Secondly you say that the section is empty. Make sure that there is already a row in the database that has an ID of 1. If the table is empty then there would be no updates made. Commented Sep 9, 2015 at 8:35
  • @JacquesKoekemoer I have a row with the id of 1. Its just section one that doesnt update. All the information is in the same row just in different columns Commented Sep 9, 2015 at 8:37

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I totally did not see that. Thanks. I check everything with phpcodechecker.com and it came up fine.
@user3600707 because this is a html problem, not a php problem.
1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.