Jump to content

ifis

Members
  • Posts

    60
  • Joined

  • Last visited

    Never

Everything posted by ifis

  1. I have an array that dispalys information a specific user has inputed into the table. I want the users to be able to update the passed field if it is blank. So I want to add an if statement that says if Passed == 'null' {echo "form..."} else echo ". $row['Passed?'] . " How would I do it? Here is the code I currently have. $sql = "SELECT * FROM Endorsementlog WHERE Username= '{$_SESSION['myusername']}'"; $result=mysql_query($sql); echo "<h3>Endorsement Log:</h3>"; echo "<table border='0'> <tr> <th>Date</th> <th>Student</th> <th>Endorsement</th> <th>Passed</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Date'] . "</td>"; echo "<td>" . $row['Student'] . "</td>"; echo "<td>" . $row['Endorsement'] . "</td>"; if ( $row['Passed?'] .== 'null') echo"<form id='elog' name='form2' method='post' action=''> <select name='Passed?' id='Passed?'> <option>Yes</option> <option>No</option> </select> </form>"; else echo "<td>" . $row['Passed?'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> Any suggestions? Thanks
  2. the second response from phpsensei worked. I have not tried the other code yet, but will. Thanks again, as usual!
  3. I updated the code to: //get the first entry from the result $row = mysql_fetch_array($result); $find = array("$student","$make"); $replace = array($student,$make); echo str_replace($find,$replace,$row['end']); but it still does not replace the variables. The result is still: I certify that $student has satisfactorily completed the test for the $make. any more suggestions?
  4. I am trying to create a form were the result is a field in a MySQl database, but inside that field I have an number of variables I want to replace with variables I have previously set. I tried str_replace, but it does not seem to be working for 1 variable, and I am going to have a couple. Any suggestions? Is this not the easiest way to do it? Here is the code: <?php // Connect to server and select databse. mysql_connect("*******", "*****", "******")or die("cannot connect"); mysql_select_db("*****")or die("cannot select DB"); //get data $make=$_POST['make']; $lic = $_POST['lic']; $student=$_POST['student']; $sql = "SELECT * FROM Endorsements WHERE lic='$lic'"; $result=mysql_query($sql); //get the first entry from the result $row = mysql_fetch_array($result); echo str_replace("$student", $student,"$row[end]"); ?> The field in the MySQL database is: I certify that $student has satisfactorily completed the test for the $make.
  5. oops. that worked, it always seems like the simple things. Also, thanks much for the coding to increase the security!
  6. I am trying to create a form to update a password. I want people to enter the password twice, so it can be compared as the same before being updated, or if not the same, have the person re-enter the password. <form id='form1' name='form1' method='post' action='updatepassword.php' onsubmit='return validateForm(this)'> <table width='500' border='0' cellspacing='0' cellpadding='0'> <tr> <td>Enter new Password:</td> <td><label> <input name='Password1' type='password' id='password1' maxlength='20' /> </label></td> </tr> <tr> <td>Re-enter Password:</td> <td><input name='Password2' type='password' id='password2' maxlength='20' /></td> </tr> <tr> <td></td> <td><label> <input type='submit' name='Submit' id='Submit' value='Submit' /> </label></td> </tr> </table>"; php <?PHP // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //clean data function clean_data($string) { if (get_magic_quotes_gpc()) { $string=stripslashes($string); } return mysql_real_escape_string($string); } //password from form $password1=clean_data($_POST['password1']); $password2=clean_data($_POST['password2']); //check isfpasssword 1 and 2 are the same if (password1 == password2){ //update database mysql_query("UPDATE Member SET password='$password1' WHERE loginName='{$_SESSION['myusername']}'"); echo "Your password has been updated. It will be necessary to use it next time you login."; } else { echo "Both passwords do not match. Please re-enter password"; ?> Thanks
  7. I'm trying to check to see if a username in my databased is used before a form is submitted. I have created a simple JAVA scipt to check to see if a field in the form is filled out. I have also created a seperate php scipt to check if the username is already used. I would like to combine these two so a message is sent if the username is used before form submition to the server. Any suggestions? JAVA code: <script type='text/javascript'> function validate_required(field,alerttxt) { with (field) { if (value==null||value=='') {alert(alerttxt);return false} else {return true} } }function validate_form(thisform) { with (thisform) { if (validate_required(actype9,'actype9 must be filled out!')==false) {email.focus();return false} } } </script> <form method='POST' action='updateprofile.php' onsubmit='return validate_form(this)'> PHP code: //check is username already exists // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT loginName FROM $tbl_name WHERE loginName='$myusername'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername table row must be 1 row if($count==1){ echo "$myusername is already taken. Please choose another username."; } else { Thanks for help!
  8. Thanks for the help. I changed the session_register to $_SESSION['myusername'] but an still only getting the first row of information from my table instead of the row that is associated with the persons username. If seems like the WHERE statement is being ignored. my new code is: login page (just changed code from above): if($count==1){ // Register $myusername, $mypassword and redirect to file "login_sucesswname.php" $_SESSION['myusername']; Display users name: mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql = "SELECT * FROM Member WHERE loginName= '{$_SESSION['myusername']}'"; $result=mysql_query($sql); //get the first entry from the result $row = mysql_fetch_array($result); // print contents echo "<html><h2>my username is $myusername</h2></html>"; echo "my name is $row[firstName] $row[lastName]"; ?> any solutions?
  9. I have a password protected webpage using sessions. Once the password has been checked, I want to used the stored sessions username to get user specific information from my database. I cannot get the WHERE section of SELECT*FROM ...WHERE to work. Here is the login code: // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from signup form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE loginName='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_sucesswname.php" session_register("myusername"); session_register("mypassword"); header("location:login_sucesswname.php"); } else { echo "Wrong Username or Password"; } ?> Here is the code trying to connect to db: <?PHP session_start(); if (!session_is_registered("myusername")) { header("Location: member_login.html"); exit(); } include ("member.inc"); // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $result=mysql_query( "SELECT * FROM Member WHERE loginName= 'myusername'"); //get the first entry from the result $row = mysql_fetch_array($result); // print contents echo "<html><h2>my username is $myusername</h2></html>"; ?> The code connects to the database, but only displays the first rows infor and not the info from a specific username. thanks.
×
×
  • 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.