Jump to content

Archived

This topic is now archived and is closed to further replies.

kiwiwilliam

Update not Updating

Recommended Posts

This is starting to really annoy me.
I'm trying to setup an update page for a website with information on various people. The form to check and change comes up alright as below:

[code]
<?php
include './includes/dbconnect.php';
if(!isset($_GET["child_id"]))
{
echo "Return to <a href=\"./add_talent.php\">Add Talent </a>page as you have not chosen a record to edit.<br>";
}
else
{
$sql = "SELECT * FROM child_info WHERE child_id = ".$_GET["child_id"]."";
}
$result = mysql_query($sql, $link) or die('Child information access error' . mysql_error());
$row = mysql_fetch_array($result)
?>
<h1> Edit existing talent</h1>
<table border="0">
<form method="post" action="./edit_child_process.php">
  <tr><td>Catergory</td><td>Current Info</td><td>New Info</td></tr>
  <tr><td>Child ID</td><td><?php echo $row["child_id"] ?></td><td><?php echo $row["child_id"] ?></td></tr>
  <tr><td>First Name</td><td><?php echo $row["name_first"] ?></td><td><input type="text" name="name_first" value="<?php echo $row["name_first"] ?>"></td></tr>
  <tr><td>Last Name</td><td><?php echo $row["name_last"] ?></td><td><input type="text" name="name_last" value="<?php echo $row["name_last"] ?>"></td></tr>
  <tr><td>Age</td><td><?php echo $row["age"] ?></td><td><input type="text" name="age" value="<?php echo $row["age"] ?>"></td></tr>
  <tr><td>Singer</td><td><?php echo $row["singer"] ?></td><td><input type="checkbox" name="singer" value="Singer" <?php if ($row["singer"]=="Singer") echo "checked"; ?>></td></tr>
  <tr><td>Dancer</td><td><?php $row["dancer"] ?></td><td><input type="checkbox" name="dancer" value="Dancer" <?php if ($row["dancer"]=="Dancer") echo "checked"; ?>></td></tr>
  <tr><td>Actor</td><td><?php echo $row["actor"] ?></td><td><input type="checkbox" name="actor" value="Actor" <?php if ($row["actor"]=="Actor") echo "checked"; ?>></td></tr>
  <tr><td>Model</td><td><?php echo $row["model"] ?></td><td><input type="checkbox" name="model" value="Model" <?php if ($row["model"]=="Model") echo "checked"; ?>></td></tr>
  <tr><td>Male</td><td><?php if($row["gender"]=="Male") echo "Male"; ?></td><td><input type="radio" name="gender" value="Male" <?php if($row["gender"]=="Male" || !isset($row['Male'])) echo "checked"; ?>></td></tr>
  <tr><td>Female</td><td><?php if($row["gender"]=="Female") echo "Female" ?></td><td><input type="radio" name="gender" value="Female" <?php if($row["gender"]=="Female") echo "checked"; ?>"></td></tr>
  <tr><td>Height</td><td><?php echo $row["height"] ?></td><td><input type="text" name="height" value="<?php echo $row["height"] ?>"> in centimeters</td></tr>
  <tr><td>Weight</td><td><?php echo $row["weight"] ?></td><td><input type="text" name="weight" value="<?php echo $row["weight"] ?>"> in kilograms</td></tr>
  <tr><td>Eye Colour</td><td><?php echo $row["eye_colour"] ?></td><td><select name="eye_colour">
                                                      <option value="<?php echo $row["eye_colour"] ?>">Black</option>
                                                      <option value="Black">Black</option>
                                                      <option value="Blue">Blue</option>
                                                      <option value="Brown">Brown</option>
                                                      <option value="Green">Green</option>
                                                      <option value="Grey">Grey</option>
                                                      <option value="Hazel">Hazel</option>
                                                      <option value="Other">Other</option>
                                                      </select></td></tr>
  <tr><td>Hair Colour:</td><td><?php echo $row["hair_colour"] ?></td><td><select name="hair_colour">
                                                        <option value="<?php echo $row["hair_colour"] ?>">Auburn</option>
                                                        <option value="Auburn">Auburn</option>
                                                        <option value="Black">Black</option>
                                                        <option value="blonde">Blonde</option>
                                                        <option value="Light Brown">Light Brown</option>
                                                        <option value="Dark Brown">Dark Brown</option>
                                                        <option value="Ginger">Ginger</option>
                                                        <option value="Grey">Grey</option>
                                                        <option value="Red">Red</option>
                                                        <option value="White">White</option>
                                                        <option value="Other">Other</option>
                                                        </select></td></tr>
    <tr><td>Hair Length:</td><td><?php echo $row["hair_length"] ?></td><td><select name="hair_length">
                                                    <option value="<?php echo $row["hair_length"] ?>">Bald</option>
                                                    <option value="Bald">Bald</option>
                                                    <option value="Close Cropped">Close Cropped</option>
                                                    <option value="Short">Short</option>
                                                    <option value="Medium">Medium</option>
                                                    <option value="Shoulder Length">Shoulder Length</option>
                                                    <option value="Long">Long</option>
                                                    <option value="Very Long">Very Long</option>
                                                    </select></td></tr>
<tr><td><input type="submit" value=" Update " name="submit"></td>
<td><input type="reset" value=" Clear Form " name="reset"></td></tr>
</form>
</table>
Cancel Edit and return to <a href="./add_talent.php">Add Talent</a>
?>
[/code]

It then gives this info to my processing pag.
This page throws up it's completion message, but changes are not reflected in the database itself.

[code]
<?php

//Include config file
include './includes/dbconnect.php';

//grab variables from post

$child_id=$_POST["child_id"];
$name_first=$_POST["name_first"];
$name_last=$_POST["name_last"];
$age=$_POST["age"];
$singer=$_POST["singer"];
$dancer=$_POST["dancer"];
$actor=$_POST["actor"];
$model=$_POST["model"];
$gender=$_POST["gender"];
$height=$_POST["height"];
$weight=$_POST["weight"];
$eye_colour=$_POST["eye_colour"];
$hair_colour=$_POST["hair_colour"];
$hair_length=$_POST["hair_length"];

//Insert into Database

$query = "UPDATE child_info SET `name_first`='$name_first', `name_last`='$name_last', `age`='$age', `singer`='$singer',`dancer`='$dancer', `actor`='$actor', `model`='$model', `gender`='$gender', `height`='$height', `weight`='$weight', `eye_colour`='$eye_colour', `hair_colour`='$hair_colour', `hair_length`='$hair_length' WHERE `child_id`='$child_id'";

mysql_query($query) or die('Talent information update error due to: ' . mysql_error());

echo "<strong>";
echo "Information updated for $name_first $name_last<br>";
echo "<a href=\"./add_talent.php\">Return</a> to add new Talent";
echo "</strong>";
?>
[/code]

Any ideas or simple suggestions.
I know there are a lot of posts on this topic, but I have not been able to get the info I wanted.

Thanks.

[b]EDIT BY OBER: THE CODE TAGS USE THE WORD "CODE" INSTEAD OF "PHP".[/b]

Share this post


Link to post
Share on other sites
Welcome to the forums!

Your "completion" message is always going to show up because you run it no matter what happens with the results.

You need to do this:
[code]<?php
$result = @mysql _query($query);

if($result)
       echo '<strong>Information updated for $name_first $name_last<br><a href="./add_talent.php">Return</a> to add new Talent</strong>'
else
      echo "There was a problem with your update: " . mysql_error();
?>[/code]

As a side note, you can reduce the following:
[code]<?php
$ child_id=$_POST["child_id"];
$name_first=$_POST["name_first"];
$name_last=$_POST["name_last"];
$age=$_POST["age"];
$singer=$_POST["singer"];
$dancer=$_POST["dancer"];
$actor=$_POST["actor"];
$model=$_POST["model"];
$gender=$_POST["gender"];
$height=$_POST["height"];
$weight=$_POST["weight"];
$eye_colour=$_POST["eye_colour"];
$hair_colour=$_POST["hair_colour"];
$hair_length=$_POST["hair_length"];
?>[/code]

to this:
[code]<?php
extract($_POST);
?>[/code]

It does the same thing.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.