1

So ive been at this for hours trying to get my editindex.php to update to my home table in mysql. So ive created a form which displays all the information I have in the colmns in the database and have all these in textarea so the user can edit the homepage information and then click update and it should change the homepage information. But when I go to update it gives me no errors but doesnt update the homepage.. Below is my index.php which shows all info in a form in textarea and editindex.php which the form is sent to, hopefully update my database.

index.php Head

<?php
include('../connect.php');


 $query = "SELECT * FROM home";

 $display = mysql_query($query) or die (mysql_error());
 ?>

Body

  <?php 



         $i=0;
     $num = mysql_numrows($display);


    $id = mysql_result($display, 0, 'id');    
    $h1 = mysql_result($display, 0, 'h1');
    $p1 = mysql_result($display, 0, 'p1');
    $p2 = mysql_result($display, 0, 'p2');
    $img1 = mysql_result($display, 0, 'img1');
    $h2 = mysql_result($display, 0, 'h2');
    $p3 = mysql_result($display, 0, 'p3');
    $li1 = mysql_result($display, 0, 'li1');
    $li2 = mysql_result($display, 0, 'li2');








    ?>

    <form enctype='multipart/form-data' action='editindex.php' method='POST'>
    Heading 1: <textarea name="h1" id="h1" rows="5" cols="40"><?php echo  $h1;?></textarea><br/><br/><br/>
    Paragraph 1: <textarea name="p1" id="p1" rows="5" cols="40"><?php echo $p1;?></textarea><br/><br/><br/>
    paragraph 2: <textarea name="p2" id="p2" rows="5" cols="40"><?php echo $p2;?></textarea><br/><br/><br/>
    Image 1:     <textarea name="img1" id="img1" rows="5" cols="40"><?php echo $img1;?></textarea><br/><br/>
    Heading 2: <textarea name="h2" id="h2" rows="5" cols="40"><?php echo $h2;?></textarea><br/><br/><br/>
    Paragraph 3: <textarea name="p3" id="p3" rows="5" cols="40"><?php echo $p3;?></textarea><br/><br/><br/>
    Line 1: <textarea name="li1"  id="li1" rows="5" cols="40"><?php echo $li1;?></textarea><br/><br/><br/>
    Line 2: <textarea name="li2" id="li2"  rows="5" cols="40"><?php echo $li2;?></textarea>
    <input name='id' id="id" value=$id hidden/>

    <input type='image' img src='../img/update.png' border='0' height='50px' alt='Update'/>
      </form>

editindex.php head

<?php
include('../connect.php');




    $id = $_POST['id'];    
    $updateh1 = $_POST['h1'];
    $updatep1 = $_POST['p1'];
    $updatep2 = $_POST['p2'];
    $updateimg1 = $_POST['img1'];
    $updateh2 = $_POST['h2'];
    $updatep3 = $_POST['p3'];
    $updateli1 = $_POST['li1'];
    $updateli2 = $_POST['li2'];


$query = "Update home set h1='$updateh1', p1='$updatep1',p2='$updatep2',h2='$updateh2',p3='$updatep3',li1='£updateli1',li2='$updateli2',img1='$updateimg1' WHERE id='$id'";
$display = mysql_query($query) or die(mysql_error());
?>
Kevin
  • 41,694
  • 12
  • 53
  • 70
Dougiee
  • 19
  • 8

3 Answers3

3

If this is intentional li1='£updateli1' // pound sign, then most likely that is the problem.

li1='$updateli1'

Obligatory Note:

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Properly build your markup in your hidden field:

<input name="id" id="id" value="<?php echo $id; ?>" type="hidden" />
Community
  • 1
  • 1
Kevin
  • 41,694
  • 12
  • 53
  • 70
  • sorry didnt notice that but i fixed it and still no luck on updating the database – Dougiee Dec 14 '14 at 02:48
  • 1
    @Dougiee and your html input hidden is badly malformed fix it as well. – Kevin Dec 14 '14 at 02:51
  • Thankyou!!! sorry for the silly mistakes just starting to use this a few weeks back for university assignment! Thanks for the help much appreciated. – Dougiee Dec 14 '14 at 02:56
0

Could try,

$query = mysql_query("Update home set h1='$updateh1',p1='$updatep1',p2='$updatep2',h2='$updateh2',p3='$updatep3',li1='$updateli1',li2='$updateli2',img1='$updateimg1' WHERE id='$id' LIMIT 1");
Jon Snow
  • 123
  • 2
  • 11
  • throws me this error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1". – Dougiee Dec 14 '14 at 02:51
  • got it sorted thanks for taking the time to help :) needed to properly build my hidden field – Dougiee Dec 14 '14 at 03:01
0

Everything looks ok from what I can understand. The only thing that I can see may be the values in your text area fields. Any single or double quotes inside these may be breaking the query call. Are you also able to let us know your table structure?

scottw33
  • 96
  • 4