Please help me about update profile TT_TT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tsuoshiro
Forum Newbie
Posts: 1
Joined: Mon Aug 24, 2009 10:01 pm

Please help me about update profile TT_TT

Post by tsuoshiro »

I have a problem in update profile. Whenever i update my first name and last name it is updatable, and when i add the middle name in the code the middle name doesnt search and updates the file. is it in the database or my code..can my codes can update only 2 ~the last name and first name~ please tell..thx in advance ^^

my first code for first name and last name ~working code~

<?php

class Database
{
var $config=Array();
var $link="";

function getConfig()
{
$config['dbhost']="localhost";
$config['dbuser']="root";
$config['dbpass']="change";
$config['dbname']="studentsprofile";

return $config;
}

function openDB()
{

$mydb=Database::getConfig();
// Connect to the database
$link = mysql_connect($mydb['dbhost'], $mydb['dbuser'], $mydb['dbpass'])
or die("Unable to connect to database");
mysql_select_db($mydb['dbname'],$link);

return ($link);
}

function setQuery($sql)
{
return mysql_query($sql);
}

}

function showSearch()
{

echo ("<form name='frm_search' action='updateupdatelive.php' method='post'>");
echo ("<input type='hidden' name='action' value='detail'>");
echo ("Student Number : <input type='text' name='Student_Number'><br>");
echo ("<input type='submit' name='f_submit' value='Search'>");
echo ("<input type='reset' name='f_submit' value='Reset'>");
echo ("</form>");
}

function showRecord()
{

if (!$link=Database::openDB()){
exit("Unable to connect to the database");
}

$sql="select * from tblstudentsinformation where Student_Number='".$_POST['Student_Number']."'";
$result=Database::setQuery($sql);

$row=mysql_fetch_array($result);

if (mysql_affected_rows()>0){

echo ("<form name='frm_details' action='updateupdatelive.php' method='post'>");
echo ("<input type='hidden' name='action' value='update'>");
echo ("Student Number <input type='text' name='Student_Number' readonly value='".$row["Student_Number"]."'><br>");
echo ("Last Name : <input type='text' name='Last_Name' value='".$row["Last_Name"]."'><br>");
echo ("First Name : <input type='text' name='First_Name' value='".$row["First_Name"]."'><br>");
echo ("<input type='submit' name='f_submit' value='Update'>");
echo ("</form>");

}else{

echo ("No record found");

}

mysql_close($link);

}

function updateRecord()
{
$Last_Name=$_POST['Last_Name'];
$First_Name=$_POST['First_Name'];
$Student_Number=$_POST['Student_Number'];

if (!$link=Database::openDB()){
exit("Unable to connect to the database");
}

$sql="update tblstudentsinformation set " .
" Last_Name = '$Last_Name'," .
" First_Name = '$First_Name' " .
" where Student_Number='$Student_Number'";
$result=Database::setQuery($sql);

if (mysql_affected_rows()>0){
echo "Record is updated";
}else {
echo ("Unable to update record");
}

mysql_close($link);

unset($_POST);

?>
<script language="javascript" type="text/javascript">
<!--
alert('Press a key to continue');
window.location = "./updateupdatelive.php"
-->
</script>

<?php



}

if (!$_POST){
showSearch();
} elseif ($_POST['action']=='detail'){
showRecord();
} elseif ($_POST['action']=='update'){
updateRecord();
}

?>


my code w/middle name ~no search found <---have problems whenever im adding middle name~


<?php

class Database
{
var $config=Array();
var $link="";

function getConfig()
{
$config['dbhost']="localhost";
$config['dbuser']="root";
$config['dbpass']="change";
$config['dbname']="studentsprofile";

return $config;
}

function openDB()
{

$mydb=Database::getConfig();
// Connect to the database
$link = mysql_connect($mydb['dbhost'], $mydb['dbuser'], $mydb['dbpass'])
or die("Unable to connect to database");
mysql_select_db($mydb['dbname'],$link);

return ($link);
}

function setQuery($sql)
{
return mysql_query($sql);
}

}

function showSearch()
{

echo ("<form name='frm_search' action='updatedddddddddddd.php' method='post'>");
echo ("<input type='hidden' name='action' value='detail'>");
echo ("Student Number : <input type='text' name='Student_Number'><br>");
echo ("<input type='submit' name='f_submit' value='Search'>");
echo ("<input type='reset' name='f_submit' value='Reset'>");
echo ("</form>");
}

function showRecord()
{

if (!$link=Database::openDB()){
exit("Unable to connect to the database");
}

$sql="select * from tblstudentsinformation where Student_Number='".$_POST['Student_Number']."'";
$result=Database::setQuery($sql);

$row=mysql_fetch_array($result);

if (mysql_affected_rows()>2){

echo ("<form name='frm_details' action='updatedddddddddddd.php' method='post'>");
echo ("<input type='hidden' name='action' value='update'>");
echo ("Student Number <input type='text' name='Student_Number' readonly value='".$row["Student_Number"]."'><br>");
echo ("Last Name : <input type='text' name='Last_Name' value='".$row["Last_Name"]."'><br>");
echo ("Middle Name : <input type='text' name='Middle_Name' value='".$row["Middle_Name"]."'><br>");
echo ("First Name : <input type='text' name='First_Name' value='".$row["First_Name"]."'><br>");
echo ("<input type='submit' name='f_submit' value='Update'>");
echo ("</form>");

}else{

echo ("No record found");

}

mysql_close($link);

}

function updateRecord()
{
$Last_Name=$_POST['Last_Name'];
$Middle_Name=$_POST['Middle_Name'];
$First_Name=$_POST['First_Name'];
$Student_Number=$_POST['Student_Number'];

if (!$link=Database::openDB()){
exit("Unable to connect to the database");
}

$sql="update tblstudentsinformation set " .
" Last_Name = '$Last_Name'," .
" Middle_Name = '$Middle_Name' " .
" First_Name = '$First_Name' " .
" where Student_Number='$Student_Number'";
$result=Database::setQuery($sql);

if (mysql_affected_rows()>2){
echo "Record is updated";
}else {
echo ("Unable to update record");
}

mysql_close($link);

unset($_POST);

?>
<script language="javascript" type="text/javascript">
<!--
alert('Press a key to continue');
window.location = "./updatedddddddddddd.php"
-->
</script>

<?php



}

if (!$_POST){
showSearch();
} elseif ($_POST['action']=='detail'){
showRecord();
} elseif ($_POST['action']=='update'){
updateRecord();
}

?>




hope u can help me.... thx again ^^
Post Reply