Jump to content

dadedidhodong

New Members
  • Posts

    8
  • Joined

  • Last visited

dadedidhodong's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello people! Yes, I'm here again for a serious mattter. I've been trying to display a value from the table I've created in my database, it's teacher profiling system which functions enables the user to ADD, UPDATE, and VIEW the teacher's profile. So first let me introduce my novice codes... First, I let the user to insert data into table with this- <form method=post action=process_add_tchr_profile.php> <p align="left"><input type=number name=tchr_id placeholder="Teacher ID" required></p> <p><input type=text name=tchr_lname placeholder="Last Name" required> <p><input type=submit value=Submit><input type=reset value=Reset></p> </form> Second, after submission it will be processed and stored in- $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("snnhs_db", $connection); $sql="INSERT INTO snnhs_db.tbl_tchr_profl( `tchr_id`, `tchr_lname`,) VALUES ('".$_POST["tchr_id"]."', '".$_POST["tchr_lname"]."',)"; $result = mysql_query($sql); Third, in my html, I put an action where user can update the profile of the teacher- $dbconnect = mysql_connect("localhost","root",""); mysql_select_db("snnhs_db",$dbconnect); $sql = "SELECT * FROM tbl_tchr_profl"; $result = mysql_query($sql); $ctr = 0; while($row = mysql_fetch_array($result,MYSQL_NUM)){ for($x=0;$x<count($row);$x++){ $tchr_profl[$ctr][$x] = $row[$x]; } $ctr++; } <h3>List of Accounts</h3> <a href=#>Add New Account</a> <table border=1 cellpadding=5> <tr> <th>No</th> <th>Teacher ID</th> <th>Last Name</th> <th>Action</th> </tr> <?php $ctr = 1; for($x=0;$x<count($tchr_profl);$x++){ echo "<tr>"; echo "<td>".$ctr++."</td>"; echo "<td>".$tchr_profl[$x][0]."</td>"; echo "<td>".$tchr_profl[$x][1]."</td>"; echo "<td><a href=update_tchr_profl.php?id={$tchr_profl[$x][0]}>UPDATE</td>" } Fourth, after clicking the UPDATE it will be redirected to update_tchr_profl.php where I have this code- <?php $dbconnect = mysql_connect("localhost","root",""); mysql_select_db("snnhs_db",$dbconnect); $sql = "SELECT * FROM tbl_tchr_profl WHERE tchr_id ={$_GET["id"]}"; $result = mysql_query($sql); $ctr = 0; while($row = mysql_fetch_array($result,MYSQL_NUM)){ for($x=0;$x<count($row);$x++){ $tchr_profl[$ctr][$x] = $row[$x]; } $ctr++; ?> <p align="left">"<?php ".$_POST["tchr_id"]."?>"</p> -- here I want to display the ID since it can't be updated. <p><input type=text name=tchr_lname value=<?php '".$_POST["tchr_lname"]."' ?> required> -- here I want to display the current data of the last name from the first time it registers to the system This is my problem, I don't if it's possible or what. I've searched through the internet but I don't seem to understand much about what they're saying so I decided to post my codes for me to better understands it. Sorry about codes and if you ask me who teach me why did I came up with such code, well, it's just what I thought to be, because I thought it would work.
  2. Yes, but the program I'm working is actually just a practice. Thank you by the way for your advice :] Really, they are annoying, but the program don't seem to work whenever I remove single quotes. But I'll try your codes, thank you! :]
  3. This code is to let user add a new record <form action="processAdd.php" method="post"> <tr><td></td><td><input type="text" placeholder="Last Name" name="lname" value="" required></td></tr></br> <tr><td></td><td><input type="text" placeholder="First Name" name="fname" value="" required></td></tr></br> <tr><td></td><td><input type="text" placeholder="Course" name="course" value="" required></td></tr></br> <tr><td colspan=2><input type="submit" name="submit" value="Submit"></td></tr> </form> The codes below is where the user inputs are being processed. But I don't want a duplicate record of the last name and the first name. I can always do that by altering the table I've created in the database and set it to UNIQUE so that no similar record can be inserted. But what I wanna do is when the user inputs a similar records (i.e. last name and firt name) it will display an error message. I don't know what's wrong with my codes, it doesn't display a syntax error though when I run it, but it keeps on adding similar records on my database. I've tried the <?php session_start(); $dbconnect = mysql_connect("localhost","root",""); $db = mysql_select_db("web", $dbconnect); $sql = mysql_query("SELECT * FROM tbl_student WHERE stud_laneme = '".$_POST["lname"]."' AND stud_fname = ".$_POST["fname"]."',"); $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { echo "Record already exists"; } else { $sql="INSERT INTO `web`.`tbl_student`( `stud_id`, `stud_lname`, `stud_fname`, `stud_course` ) VALUES( NULL, '".$_POST["lname"]."', '".$_POST["fname"]."', '".$_POST["course"]."' )"; $result = mysql_query($sql); header("location:displayRecord.php"); } ?>
  4. function makePass($word=''){ $dbSalt = '$2a$07.substr(hash('whirlpool',$word),0,22); $dbPass = crypt($word, $dbSalt); return substr($dbPass,12); } I'm not sure but I guess this code is for password. My problem is, how can I make the program to prohibit adding records that does exist (i.e. Last Name and First Name).
  5. I have this HTML FORM <form action="check_record.php" method="post"> <input type="text" placeholder=""Last Name" name="lname"></input> <input type="text" placeholder=""First Name" name="fname"></input> SUBMIT or CLEAR </form> once the user submits the form I point it to the check_record.php to check if the record already exist or not <?php //check_record.php session_start(); $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("web", $connection); $sql="SELECT * FROM `web`.`tbl_student` WHERE lname = '".$_POST["lname].'", fname = '".$_POST["fname"]."' $result = mysql_query($sql); $row = (I forgot the next codes :\) header("Location:add_record.php"); ?> <?php //add_record.php session_start(); $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("web", $connection); $sql="INSERT INTO `web`.`tbl_student` (`lname`, `fname`) VALUES ('".$_POST["lname].'", '".$_POST["fname"]."')"; $result = mysql_query($sql); header("Location:index.php"); ?> I am totally new to PHP, my problem here is, once the user submits the form, it will check if the last name or the first name already exist, if it exist it will not allow to add the record and displays a message "Record alreadys exist" if it's not an existing record, it will display a message saying "Record saved." I have no problem with adding, updating, or deleting a record. During our lab activity I figured out how to check if the record already exist but I'm not sure about because after the record has been check and it's not existing it will add though but the last name and the first name are blank :/ please help
  6. I have a php program which accepts the input of the YYYY-MM-DD as the date format and stores it to the database. As soon as the user enters the date with YYYY-MM-DD format (e.g 1990-06-22) how can I convert the 06 (or the MM part) to June as in the 6th month of the year?
×
×
  • Create New...

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.