tsuoshiro Posted August 25, 2009 Share Posted August 25, 2009 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 ^^ Link to comment https://forums.phpfreaks.com/topic/171726-please-help-me-about-update-profile-tt_tt/ Share on other sites More sharing options...
tsuoshiro Posted August 25, 2009 Author Share Posted August 25, 2009 its my first time posting to a thread thats why i reposted it... sowwee if its not clear 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 ^^ Link to comment https://forums.phpfreaks.com/topic/171726-please-help-me-about-update-profile-tt_tt/#findComment-905520 Share on other sites More sharing options...
Batosi Posted August 25, 2009 Share Posted August 25, 2009 <?php $sql="update tblstudentsinformation set " . " Last_Name = '$Last_Name'," . " Middle_Name = '$Middle_Name' " . " First_Name = '$First_Name' " . " where Student_Number='$Student_Number'"; // Should be this $sql="update tblstudentsinformation set " . " Last_Name = '$Last_Name'," . " Middle_Name = '$Middle_Name', " . " First_Name = '$First_Name' " . " where Student_Number='$Student_Number'"; ?> Link to comment https://forums.phpfreaks.com/topic/171726-please-help-me-about-update-profile-tt_tt/#findComment-905544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.