PHP code not updating database, is it my sql or my php?
Posted: Sat Jan 10, 2004 5:47 am
Hi everyone 
i've got a snippet of my code below for you to peruse. The problem I'm having with it is the modification of the database.
If you read the section in hte large code lump below that says...
...you will see the area I'm talking about.
I press the EDIT button, the info is displayed in my input boxes, I edit those boxes but the database does not update. I've looked and looked and looked at it for days now but can't see it. I'm hoping it's something really easy.
If anyone can suggest anything I'd really appreciate some guidance.
Thanks
Rob
i've got a snippet of my code below for you to peruse. The problem I'm having with it is the modification of the database.
If you read the section in hte large code lump below that says...
Code: Select all
//if the user presses Apply changes button they update database
if ($Submit == "Apply your changes")I press the EDIT button, the info is displayed in my input boxes, I edit those boxes but the database does not update. I've looked and looked and looked at it for days now but can't see it. I'm hoping it's something really easy.
If anyone can suggest anything I'd really appreciate some guidance.
Thanks
Rob
Code: Select all
$Submit = (isset($_POST['Submit'])?$_POST['Submit']:"");
if (is_loggedin())
{
print "<form name="editentry" method="post" action="current_upload_edit.php">";
//get the number of the entry we are to edit from the form on the last page
$entrynumber = stripslashes($_POST['entrynumber']);
// connect to current table
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname);
$sql = "SELECT * FROM current WHERE id = $entrynumber";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$id = $Xcontent["id"];
$uid = $Xcontent["uid"];
$year = $Xcontent["year"];
$month = $Xcontent["month"];
$number = $Xcontent["number"];
$title = $Xcontent["title"];
$animator = $Xcontent["animator"];
$hardware = $Xcontent["hardware"];
$software = $Xcontent["software"];
$creationtime = $Xcontent["creationtime"];
$rendertime = $Xcontent["rendertime"];
$viewrecommend = $Xcontent["viewrecommend"];
$animdescription = $Xcontent["animdescription"];
$descriptionofcreation = $Xcontent["descriptionofcreation"];
$popularity = $Xcontent["popularity"];
$mpg = $Xcontent["mpg"];
$jpg = $Xcontent["jpg"];
$rating = $Xcontent["rating"];
$ratingtally = $Xcontent["ratingtally"];
$ratingavg = $Xcontent["ratingavg"];
$ratingafter = $Xcontent["ratingafter"];
//if the user presses Apply changes button they update database
if ($Submit == "Apply your changes")
{
$animator = stripslashes($_POST['animator']);
$title = stripslashes($_POST['title']);
$hardware = stripslashes($_POST['hardware']);
$software = stripslashes($_POST['software']);
$creationtime = stripslashes($_POST['creationtime']);
$rendertime = stripslashes($_POST['rendertime']);
$viewrecommend = stripslashes($_POST['viewrecommend']);
$descriptionofcreation = stripslashes($_POST['descriptionofcreation']);
$animdescription = stripslashes($_POST['animdescription']);
$forum_uid = stripslashes($_POST['forum_uid']);
$new_id = stripslashes($_POST['new_id']);
$sound_id = stripslashes($_POST['sound_id']);
$sound_year = stripslashes($_POST['sound_year']);
$sound_month = stripslashes($_POST['sound_month']);
$animdescription = nl2br($animdescription);
$descriptionofcreation = nl2br($descriptionofcreation);
//Update the database
$Update = mysql_db_query ($dbname, "UPDATE current SET animator=trim('$animator') WHERE id = $forum_uid");
$Update = mysql_db_query ($dbname, "UPDATE current SET title=trim('$title') WHERE id = $forum_uid");
$Update = mysql_db_query ($dbname, "UPDATE current SET hardware=trim('$hardware') WHERE id = $forum_uid");
$Update = mysql_db_query ($dbname, "UPDATE current SET software=trim('$software') WHERE id = $forum_uid");
$Update = mysql_db_query ($dbname, "UPDATE current SET creationtime=trim('$creationtime') WHERE id = $forum_uid");
$Update = mysql_db_query ($dbname, "UPDATE current SET rendertime=trim('$rendertime') WHERE id = $forum_uid");
$Update = mysql_db_query ($dbname, "UPDATE current SET viewrecommend=trim('$viewrecommend') WHERE id = $forum_uid");
$Update = mysql_db_query ($dbname, "UPDATE current SET descriptionofcreation=trim('$descriptionofcreation') WHERE id = $forum_uid");
$Update = mysql_db_query ($dbname, "UPDATE current SET animdescription=trim('$animdescription') WHERE id = $forum_uid");
} //end of if Submit == apply your changes
//if the user presses the edit text button they get this
if ($Submit == "Edit your text info")
{
$animator = stripslashes($_POST['animator']);
$title = stripslashes($_POST['title']);
$hardware = stripslashes($_POST['hardware']);
$software = stripslashes($_POST['software']);
$creationtime = stripslashes($_POST['creationtime']);
$rendertime = stripslashes($_POST['rendertime']);
$viewrecommend = stripslashes($_POST['viewrecommend']);
$descriptionofcreation = stripslashes($_POST['descriptionofcreation']);
$animdescription = stripslashes($_POST['animdescription']);
$forum_uid = stripslashes($_POST['forum_uid']);
$new_id = stripslashes($_POST['new_id']);
$sound_id = stripslashes($_POST['sound_id']);
$sound_year = stripslashes($_POST['sound_year']);
$sound_month = stripslashes($_POST['sound_month']);
echo "<br /> Here you can edit your animation information...<br /><br />";
$action = "";
//Name
print "<b>Your Name</b><br>";
print "<input type="text" name="animator" size="45" value="$animator"><br /><br />";
print "</text>";
//title
print "<b>Title of your animation</b><br>";
print "<input type="text" name="title" size="45" value="$title"><br /><br />";
print "</text>";
// Hardware
print "<b>What Hardware or Tools did you use?</b><br>";
print "<textarea name="hardware" cols="45" rows="5" wrap="VIRTUAL">";
print "$hardware";
print "</textarea>";
// Software
print "<br /><br /><b>What Software did you use?</b><br>";
print "<textarea name="software" cols="45" rows="5" wrap="VIRTUAL">";
print "$software";
print "</textarea>";
//Animation time
print "<br /><br /><b>How long did it take to create your animation?</b><br>";
print "<input type="text" name="creationtime" size="45" value="$creationtime"><br /><br />";
print "</text>";
//Rendertime
print "<b>How long did it take to render your animation?</b><br>";
print "<input type="text" name="rendertime" size="45" value="$rendertime"> <br /> <br />";
print "</text>";
//Viewing Recommendations
print "<b>What are your viewing recommendations? (be creative </b><br>";
print "<input type="text" name="viewrecommend" size="45" value="$viewrecommend">";
print "</text>";
//Description of creation
print "<br /> <br /><b>Description of the creation process</b><br>";
print "<textarea name="descriptionofcreation" cols="45" rows="10" wrap="VIRTUAL">";
print "$descriptionofcreation";
print "</textarea>";
//Description of animation
print "<br /> <br /><b>Description of Animation (Story/Motivation/etc)</b><br>";
print "<textarea name="animdescription" cols="45" rows="10" wrap="VIRTUAL">";
print "$animdescription";
print "</textarea>";
//extra's
print "<input type="hidden" name="forum_uid" value="$member_id" />";
print "<input type="hidden" name="new_id" value="$new_number" />";
print "<input type="hidden" name="sound_id" value="$sound_id" />";
print "<input type="hidden" name="sound_year" value="$sound_year" />";
print "<input type="hidden" name="sound_month" value="$sound_month" />";
print "<input type="hidden" name="entrynumber" value="$entrynumber" />";
//buttons
print "<br /><input type="submit" name="Submit" value="Apply your changes"><br />";
print "(If you don't want to change anything here, simply press BACK in your browser to cancel any changes)";
}
else
{
echo "<p>Your animation details</p>";
echo "<b>Animation title</b> = $title<br />";
echo "<b>Your real name</b> = $animator<br />";
echo "<b>Hardware used</b> = $hardware<br />";
echo "<b>Software used</b> = $software<br />";
echo "<b>Creation time</b> = $creationtime<br />";
echo "<b>Render time</b> = $rendertime<br />";
echo "<b>Viewing recommendations</b> = $viewrecommend<br />";
echo "<b>Animation description</b> = $animdescription<br />";
echo "<b>Description of creation</b> = $descriptionofcreation<br />";
// the values to be sent on again
print "<input type="hidden" name="animator" value="$animator" />";
print "<input type="hidden" name="title" value="$title" />";
print "<input type="hidden" name="hardware" value="$hardware" />";
print "<input type="hidden" name="software" value="$software" />";
print "<input type="hidden" name="creationtime" value="$creationtime" />";
print "<input type="hidden" name="rendertime" value="$rendertime" />";
print "<input type="hidden" name="viewrecommend" value="$viewrecommend" />";
print "<input type="hidden" name="descriptionofcreation" value="$descriptionofcreation" />";
print "<input type="hidden" name="animdescription" value="$animdescription" />";
print "<input type="hidden" name="forum_uid" value="$forum_uid" />";
print "<input type="hidden" name="new_id" value="$new_id" />";
print "<input type="hidden" name="sound_id" value="$sound_id" />";
print "<input type="hidden" name="sound_year" value="$sound_year" />";
print "<input type="hidden" name="sound_month" value="$sound_month" />";
print "<input type="hidden" name="entrynumber" value="$entrynumber" />";
print "<br /><input type="submit" name="Submit" value="Edit your text info"><br />";
echo "</form>";
//end button if else bit
}
} //end of , has user logged in?
else //user is NOT logged in
{
echo '<p>Error: you are not logged in, to edit your entry you must be logged in.</p>';
}