Need help Updating database via form....

Discussion in 'Programming' started by livingearth, Aug 28, 2011.

  1. #1
    Ok heres my issue...
    I have set up a database and a form to input data. All works fine. I set up an additional form and query to populate it with info from database and set the action to go to a php page which writes a MySQL query to make the neccesary updates... Doesn't work. Everything looks right. I get no errors. The data simply is not updated in the database...

    Heres the code to the update form...

    
     <?php  include("settings_theblacksmithsanvil.inc");
      $db = mysql_connect("$dbhost", "$dblogin", "$dbpass");
    mysql_select_db("$dbname",$db);
    $result = mysql_query("SELECT * FROM members WHERE num = '$entry'",$db); 
    $num_rows = mysql_num_rows($result); echo "showing $num_rows results<hr><center>"; while ($row = mysql_fetch_array($result)) { $field1 = $row["num"]; $field2 = $row["name"]; $field3 = $row["address"]; $field4 = $row["city"]; $field5 = $row["state"]; $field6 = $row["zip_code"]; $field7 = $row["phone"]; $field8 = $row["email"]; $field9 = $row["coord"]; $field10 = $row["mapit"]; $field11 = $row["additional"]; $field12 = $row["profilepic"];$field13 = $row["occupation"]; $field14 = $row["description"];$field15 = $row["Image1"];$field16 = $row["Image2"];$field17 = $row["Image3"];$field18 = $row["Image4"];echo "<font face=arial size=+1><b>Editing Record number <u>$field1</u> for<u> $field2</u> </b></font>"; } ?><p>
    
    
    
    <html><body bgcolor=#000000 text=#ffffff link=#aaaaff font face=arial>
    
    <img src="wplogo.jpg" width="100%">
    
    <form action="submitUpdate.php?editthis=<?php echo"$field1";?>" method="POST" enctype="multipart/form-data">
    
    <center>
    
    <table><tr><td valign=top>
    
    <table width=""><tr><td colspan=2 bgcolor="#eeeeff"><b><font face=arial color='#0000cc'> Information:</td></tr><tr><td align=right>
    Entry Number:</td><td> <input align=right type=text name=num value="<?php echo"$field1";?>" size=30 maxlength=100></td></tr><tr><td align=right>
    
    Name:</td><td> <input align=right type=text name=name value="<?php echo"$field2";?>" size=30 maxlength=100></td></tr><tr><td align=right>
    
    Address:</td><td><input type=text name=address value="<?php echo"$field3";?>" size=30 maxlength=100></td></tr><tr><td align=right>
    City:</td><td><input type=text border=3 name=city value="<?php echo"$field4";?>" size=30 length=35></td></tr><tr><td align=right>
    
    State:</td><td><INPUT TYPE="text" border=3 NAME="state" value="<?php echo"$field5";?>" SIZE="30"length=25></td></tr><tr><td align=right>
    Zip:</td><td><INPUT TYPE="text" border=3 NAME="zip_code" value="<?php echo"$field6";?>" SIZE="30"length=25></td></tr><tr><td align=right>
    
    Phone:</td><td><input type=text name=phone value="<?php echo"$field7";?>" size=30 maxlength=100></td></tr><tr><td align=right>
    
    Email:</td><td><input type=text name=email value="<?php echo"$field8";?>" size=30 maxlength=100></td></tr><tr><td align=right>
    
    Coord:</td><td><input type=text name=coord value="<?php echo"$field9";?>" size=30 maxlength=100><a href="http://www.gpsvisualizer.com/geocode" target=_new>Get Coordinates</a></td></tr><tr><td align=right>
    
    Map It:</td><td><input type=text name=mapit value="<?php echo"$field10";?>"size=30 maxlength=100></td></tr><tr><td align=right>
    Additional:</td><td><input type=text name=additional value="<?php echo"$field11";?>"size=30 maxlength=500></td></tr><tr>
    
    
    <td colspan=2 bgcolor="#eeeeff"><b><font face=arial color='#0000cc'></td></tr>
    
    <tr><td align=right>
    
    Profile Image:</td><td><input type=text name=profilepic value='<?php echo "$field12"; ?>' size=30 maxlength=120></td></tr><tr><td align=right>
    
    Occupation:</td><td><INPUT TYPE="text" NAME="occupation" value="<?php echo"$field13";?>" SIZE="30"></td></tr><tr><td align=right>
    Description:</td><td><input type=text name=description  value="<?php echo"$field14";?>"size=30 maxlength=500> </td></tr>
    
    <tr><td align=right>
    Additional Image1:</td><td><input type=text name=Image1 value='<?php echo "$field15"; ?>' size=30 maxlength=120></td></tr>
    
    <tr><td align=right>
    Additional Image2:</td><td><input type=text name=Image2 value='<?php echo "$field16"; ?>' size=30 maxlength=120></td></tr>
    <tr><td align=right>
    Additional Image3:</td><td><input type=text name=Image3 value='<?php echo "$field17"; ?>' size=30 maxlength=120></td></tr>
    <tr><td align=right>
    Additional Image4:</td><td><input type=text name=Image4 value='<?php echo "$field18"; ?>' size=30 maxlength=120></td></tr>
    <tr><td align=right>
    
    
    <input type=submit name="Submit"></td></tr></table>
    
    </td>
    
    <TD WIDTH=60%><center><font size="+1"face=arial><b>Attached Images: <?php echo "$img1_name"; ?></b><br> <IMG SRC='../uploads/<?php echo "$field12"; ?> 'height=150> <br> 
    
    <?php echo "$field15"; ?></b><br> <IMG SRC='../uploads/<?php echo "$field15"; ?> 'height=150> <br> 
    
    <?php echo "$field16"; ?></b><br> <IMG SRC='../uploads/<?php echo "$field16"; ?> 'height=150> <br>
    
    <?php echo "$field17"; ?></b><br> <IMG SRC='../uploads/<?php echo "$field17"; ?> 'height=150> <br> 
    
    <?php echo "$field18"; ?></b><br> <IMG SRC='../uploads/<?php echo "$field18"; ?> 'height=150> <br> 
    
    </TD></tr></table>
    </form>
    
    
    
    </body></html>
    
    
    
    
    PHP:


    And here is the page it sends the data to that sets up the MySQL query....

    
    <html>
    <body>
    <?php
    $num = ($_POST['num']);
    $name = ($_POST['name']);
    $address = ($_POST['address']);
    $city = ($_POST['city']);
    $state = ($_POST['state']);
    $zip_code = ($_POST['zip_code']);
    $phone = ($_POST['phone']);
    $email = ($_POST['email']);
    $coord = ($_POST['coord']);
    $mapit = ($_POST['mapit']);
    $additional = ($_POST['additional']);
    $profilepic = ($_POST['profilepic']);
    $occupation = ($_POST['occupation']);
    $description = ($_POST['description']);
    $Image1 = ($_POST['Image1']);
    $Image2 = ($_POST['Image2']);
    $Image3 = ($_POST['Image3']);
    $Image4 = ($_POST['Image4']);
    
    
    
    include("settings_theblacksmithsanvil.inc");
    mysql_connect ($dbhost, $dblogin,$dbpass) or die("<b><font face=arial 
    
    size='+1'color='#000000'> Unable to connect to MySQL Server<br>");
    echo("<b><font face=arial size='+1'color='#0000bb'> connected to MySql Server at 
    
    $dbhost<br>");
    mysql_select_db ($dbname) or die("<b><font face=arial size='+1'color='#000000'> Unable to 
    
    connect to Database<br>");
    
    mysql_query ("UPDATE `sbayley_theblacksmithsanvil`.`members` SET `name` = \'$name\', 
    
    `address` = \'$address\', `city` = \'$city\', `state` = \'$state\', `zip_code` = 
    
    \'$zip_code\', `phone` = \'$phone\', `email` = \'$email\', `coord` = \'$coord\', `mapit` = 
    
    \'$mapit\', `additional` = \'$additional\', `profilepic` = \'$profilepic\', `occupation` = 
    
    \'$occupation\', `description` = \'$description\', `Image1` = \'$Image1\', `Image2` = 
    
    \'$Image2\', `Image3` = \'$Image3\', `Image4` = \'$Image4\' WHERE 
    
    `sbayley_theblacksmithsanvil`.`members`.`num` = \'$num\'");
    
    
    print (" <b><font face=arial size='+1'color='#000000'> <font color='#aa0000'>You have 
    
    submitted the following information...<p></font>");
    print ("<table> <tr><td align=right><b><font face=arial size='+1'color='#000000'> Number: 
    
    </td><td> <font color='#0000aa'><b> $num <br> </font> </td></tr> ");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> Name: </td><td> 
    
    <font color='#0000aa'><b> $name <br> </font> </td></tr> ");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> 
    
    Address:</td><td><font color='#0000aa'><b>$address<br></font> </td></tr>");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> 
    
    City:</td><td><font color='#0000aa'><b>$city<br></font> </td></tr>");
    print ("<tr><td align=right> <b><font face=arial 
    
    size='+1'color='#000000'>state:</td><td><font color='#0000aa'><b>$state<br></font> 
    
    </td></tr>");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> Zip:</td><td><font 
    
    color='#0000aa'><b>$zip_code<br></font> </td></tr>");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> 
    
    Phone:</td><td><font color='#0000aa'><b>$phone<br></font> </td></tr>");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> 
    
    Email:</td><td><font color='#0000aa'><b>$email<br></font> </td></tr>");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> 
    
    Coord:</td><td><font color='#0000aa'><b>$coord<br></font> </td></tr>");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> Add to 
    
    map?:</td><td><font color='#0000aa'><b>$mapit<br></font></td></tr> ");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> 
    
    Additional:</td><td><font color='#0000aa'><b>$additional<br></font> </td></tr>");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> Profile 
    
    Image:</td><td><font color='#0000aa'><b>$profilepic<br></font></td></tr> ");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> 
    
    Occupation:</td><td><font color='#0000aa'><b>$occupation<br></font></td></tr>");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> 
    
    Description:</td><td><font color='#0000aa'><b>$description<br></font></td></tr> ");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> Additional 
    
    Image1:</td><td><font color='#0000aa'><b>$Image1<br></font></td></tr> ");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> Additional 
    
    Image2:</td><td><font color='#0000aa'><b>$Image2<br></font></td></tr> ");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> Additional 
    
    Image3:</td><td><font color='#0000aa'><b>$Image3<br></font></td></tr> ");
    print ("<tr><td align=right><b><font face=arial size='+1'color='#000000'> Additional 
    
    Image4:</td><td><font color='#0000aa'><b>$Image4<br></font></td></tr></table> ");
    print ("<br><font color='#aa0000'>Thanks for your submission.<p><a href='getMembers.php' target=new>View</a>");
    
    ?>
    </body>
    </html>
    
    
    
    
    
    PHP:

    I have tried everything I can to find the issue. Can anyone out there enlighten me as to what I have missed?
    Thanks a bunch....
    Steve
     
    livingearth, Aug 28, 2011 IP
  2. Ciprian

    Ciprian Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Try to echo the whole mysql_query and post it here.

    You should try to copy/paste the generated query to phpMyAdmin and see the error there.
     
    Ciprian, Aug 28, 2011 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    First change:
    ("UPDATE `sbayley_theblacksmithsanvil`.`members` SET `name` = '$name', 
    `address` = '$address', `city` = '$city', `state` = '$state', `zip_code` = 
    '$zip_code', `phone` = '$phone', `email` = '$email', `coord` = '$coord', `mapit` = 
    '$mapit', `additional` = '$additional', `profilepic` = '$profilepic', `occupation` = 
    '$occupation', `description` = '$description', `Image1` = '$Image1', `Image2` = 
    '$Image2', `Image3` = '$Image3', `Image4` = '$Image4' WHERE 
    `sbayley_theblacksmithsanvil`.`members`.`num` = '$num'");
    PHP:
    (If num is a numeric field, make that num = $num")

    Second, is the name of the table actually sbayley_theblacksmithsanvil.members? That's what your code says it is. If it is, change the code to
    "UPDATE sbayley_theblacksmithsanvil.members SET ...

    If not, fix that. (SQL doesn't understand 'text1'.'text2' - it treats it as if the dot is part of the name. You have to understand which part of the string is PHP and which part is SQL.)
     
    Rukbat, Aug 31, 2011 IP
  4. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Thanks everyone for the help and suggestions...
     
    livingearth, Sep 11, 2011 IP