hi,

I am creating a form for user to update their details which is saved in the database. So far i can show their details in the form where i have a submit button but the updating part doesnt work(it doesnt update at all). here is the code:

<html>
<?php

session_start();

$host="localhost"; // Host name
$username="user"; // Mysql username
$password="123456"; // Mysql password
$db_name="db"; // Database name
$tbl_name="member"; // Table name

// 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 = $_SESSION['myusername'];

if(!isset($_SESSION['myusername']))
	{
   header("location: main_login.php");
}
  else
{
	$query=" SELECT * FROM $tbl_name WHERE LoginName='$username'";
	$result=mysql_query($query);
	$num=mysql_numrows($result);
	mysql_close();

$i=0;
while ($i < $num) {
$phone=mysql_result($result,$i,"telephone");
$add=mysql_result($result,$i,"address");
$town=mysql_result($result,$i,"town");
$email=mysql_result($result,$i,"email");
$city=mysql_result($result,$i,"city");
$postcode=mysql_result($result,$i,"postcode");
++$i;
}
$u_phone=$_POST['phone'];
$u_add=$_POST['add'];
$u_town=$_POST['town'];
$u_city=$_POST['city'];
$u_postcode=$_POST['postcode'];
$u_email=$_POST['email'];


$query1="UPDATE $tbl_name SET memberNo = NULL, LoginName=NULL, title=NULL, firstName=NULL, lastName=NULL, gender= NULL, address='$u_add', town='$u_town', city='$u_city', postcode='$u_postcode', telephone='$u_phone',  email='$u_email', mshipType = NULL";
mysql_query($query1);
echo "Record Updated";
mysql_close();
}
?>
<form action="changedetails.php" method="post">
<table>
<tr>
	<td>Phone Number :</td>
	<td><input type="text" name="phone" size="30" value="<?php echo $phone; ?>"></td>
</tr>
<tr>
	<td>Address :</td>
	<td><input type="text" name="add" size="30" value="<?php echo $add; ?>"></td>
</tr>
<tr>
	<td>Town :</td>
	<td><input type="text" name="town" size="30" value="<?php echo $town; ?>"></td>
</tr>
<tr>
	<td>City :</td>
	<td><input type="text" name="city" size="30" value="<?php echo $city; ?>"></td>
</tr>
<tr>
	<td>Post Code :</td>
	<td><input type="text" name="postcode" size="30" value="<?php echo $postcode; ?>"></td>
</tr>
<tr>
	<td>E-mail Address :</td>
	<td><input type="text" name="email" size="30" value="<?php echo $email; ?>" ></td>
</tr>
</table>

 <p>

<input type="Submit" value="Update">
<input type="Submit" value="Cancel">
</form>
</html>

here is the table:

CREATE TABLE Member(
 memberNo       INT(8) UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
 LoginName 	VARCHAR(6)  NOT NULL UNIQUE,
 title          VARCHAR(5),
 firstName      VARCHAR(20) NOT NULL,
 lastName       VARCHAR(20) NOT NULL,
 gender         VARCHAR(6)  NOT NULL
                             CHECK(gender IN('MALE','FEMALE')),
 address        VARCHAR(30), 
 town           VARCHAR(20),
 city           VARCHAR(20),
 postcode       VARCHAR(8)  NOT NULL,
 telephone      INT(11),
 email          VARCHAR(50) NOT NULL,
 mshipType      VARCHAR(15) NOT NULL 
                             CHECK(mshipType IN('STUDENT','STAFF','ALUMNI')),
 password       VARCHAR(20) NOT NULL,
 PRIMARY KEY(memberNo)
);

According to the UPDATE syntax, I observe that your $query1 is missing the WHERE clause to select the record or records to be updated.

The specification says that if the WHERE is missing, every row in the table will be updated!.

I do not thik that that is what you want.

i i am correct, you should add to $query1 the following text:
WHERE LoginName='$username'';

how did you solve it? I really need to know...our project is due next week,,,please...

Hi,

if you don't have the WHERE clause in your sql script, your entire table will be update, but if you don't see this you probably have some other errors. try use:
mysql_query($sql) or die(mysql_error());

also try to use addslashes() function to escape some chars.

as said above just use the where clause and u should be fine mate

is there any code of adding record using drop down menu? or should i say,the <select><option> function?all i know is input text area..tnx..

its the same as u would do for input text...
just access the data from ur post variable as $_POST["yourSelectName"] and u can very well add it to ur record as u do for text. the post variable will contain the value of option which user selected...

is there any code of adding record using drop down menu? or should i say,the <select><option> function?all i know is input text area..tnx..

its the same as u would do for input text...
just access the data from ur post variable as $_POST["yourSelectName"] and u can very well add it to ur record as u do for text. the post variable will contain the value of option which user selected...

>> so the code will be <select name="sample here">
<option value="<?php echo $row_sample here?>" ?
i used the this array > while ($row= mysql_fetch_array($result)); before declaring the <select name =" "> and it's value..there's an error with that. the error was "< and >" but i can't find which "< and >" is wrong.

its the same as u would do for input text...
just access the data from ur post variable as $_POST["yourSelectName"] and u can very well add it to ur record as u do for text. the post variable will contain the value of option which user selected...

>> or i mean
<option value="<?php $row?>" ></option>
is this correct?

well this code doesnt looks gud... could you be more specific with what code u r using... paste the exact code here and use [code] tags.. also post the exact error u r stuck with...
I will write an example to make myself clear

<select name="sample_select">
      <option value="<?php echo $row['sample_field']; ?>">option1</option>
      </select>

and when u trying to use the selected value just retrieve it like this..

$selected = $_POST['sample_select']; //POST or GET whatever u have used in ur form 

this way u can use this variable $selected wherever required..
Hope this clarifies ur doubt..

so the code will be

<select name="sample here">
<option value="<?php echo $row_sample here['sample here']?>" ?
i used the this array > while ($row= mysql_fetch_array($result)); before declaring the <select name =" "> and it's value..there's an error with that. the error was "< and >" but i can't find which "< and >" is wrong.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

well this code doesnt looks gud... could you be more specific with what code u r using... paste the exact code here and use [code] tags.. also post the exact error u r stuck with...
I will write an example to make myself clear

<select name="sample_select">
      <option value="<?php echo $row['sample_field']; ?>">option1</option>
      </select>

and when u trying to use the selected value just retrieve it like this..
$selected = $_POST['sample_select']; //POST or GET whatever u have used in ur form
this way u can use this variable $selected wherever required..
Hope this clarifies ur doubt..

hmmm i see..i saw the error..let me fix again..but here's my code..

<?php
    include('connect-db.php');


    $result = mysql_query("SELECT * FROM courses") 
        or die(mysql_error());  

    echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name=course>";
    while($row = mysql_fetch_array( $result )) { 

        echo '<option>' . $row['course'] . '</option>';  

       }

    echo "</select>"; 


?>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

well this code doesnt looks gud... could you be more specific with what code u r using... paste the exact code here and use [code] tags.. also post the exact error u r stuck with...
I will write an example to make myself clear

<select name="sample_select">
      <option value="<?php echo $row['sample_field']; ?>">option1</option>
      </select>

and when u trying to use the selected value just retrieve it like this..
$selected = $_POST['sample_select']; //POST or GET whatever u have used in ur form
this way u can use this variable $selected wherever required..
Hope this clarifies ur doubt..

and the changes i made last night..

<?php
    include('connect-db.php');


    $result = mysql_query("SELECT * FROM courses") 
        or die(mysql_error());  

    echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="course">
    while($row = mysql_fetch_array( $result )) { 

        <option value=' <?php . $row['course'] . ?>'></option>

       }

    </select> 


?>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

use code tags when posting here... ur code is barely readable without it..

>> and the changes i made last night..

<?php
    include('connect-db.php');

   
    $result = mysql_query("SELECT * FROM courses") 
        or die(mysql_error());  
 
	echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="course">
    while($row = mysql_fetch_array( $result )) { 

        <option value=' <?php . $row['course'] . ?>'></option>
	
       }
        
    </select> 

    
?>

your selectbox should be created this way..

echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="course">';
   while($row = mysql_fetch_array( $result )) { 

      echo '<option value='.$row['course'].'>'.$row['course'].'</option>';  //the second $row['course'] is the text which is actually going to be displayed to user.. u can use course title or whatever u have in ur db
	
       }
        
   echo '</select>';

hope this will solve it

Edited 7 Years Ago by venkat0904: n/a

use code tags when posting here... ur code is barely readable without it..

your selectbox should be created this way..

echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="course">';
   while($row = mysql_fetch_array( $result )) { 

      echo '<option value='.$row['course'].'>'.$row['course'].'</option>';  //the second $row['course'] is the text which is actually going to be displayed to user.. u can use course title or whatever u have in ur db
	
       }
        
   echo '</select>';

hope this will solve it

> oOpss sorry..this is the first time i used and joined in this forum...
ok i'll try to change my code on that part and try to run it.hope it wil run..
Parse Error: Unexpected syntax error '>'...tnx..

use code tags when posting here... ur code is barely readable without it..

your selectbox should be created this way..

echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="course">';
   while($row = mysql_fetch_array( $result )) { 

      echo '<option value='.$row['course'].'>'.$row['course'].'</option>';  //the second $row['course'] is the text which is actually going to be displayed to user.. u can use course title or whatever u have in ur db

       }

   echo '</select>'; 

hope this will solve it

echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="course">';
   while($row = mysql_fetch_array( $result )) { 

      echo '<option value='.$row['course'].'>'.$row['course'].'</option>';  //the second $row['course'] is the text which is actually going to be displayed to user.. u can use course title or whatever u have in ur db

       }

   echo '</select>'; 

hope this will solve it

still the same error..here's the error..
Parse error: syntax error, unexpected '<' in C:\wamp\www\41e1\thesis_draft\add_students.php on line 138...

i used these code from you...still there's an error occured.

<?php
    include('connect-db.php');


    $result = mysql_query("SELECT * FROM courses") 
        or die(mysql_error());  

    <select name="course">

      while($row = mysql_fetch_array( $result )) {


   <option value="<?php echo .$row['course'].; ?>">.$row['course'].</option>//the second $row['course'] is the text which is actually going to be displayed to user.. u can use course title or whatever u have in ur db

      }

      </select>
?>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

u messed it up pretty bad...
Look at the code i pasted and then look what u have used... I can see hell lot of difference.
just try the code i provided and once u get it working then try to make whatever changes u want to have...
As of now ur syntax itself is wrong... where are all the echo statements i wrote? u cant use html tags without echo'ing them

start quote:

echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="course">';
   while($row = mysql_fetch_array( $result )) { 

      echo '<option value='.$row['course'].'>'.$row['course'].'</option>';  //the second $row['course'] is the text which is actually going to be displayed to user.. u can use course title or whatever u have in ur db

       }

   echo '</select>';

hope this will solve it

<?php
    include('connect-db.php');


    $result = mysql_query("SELECT * FROM courses") 
        or die(mysql_error());  

    <select name="course">

      while($row = mysql_fetch_array( $result )) {


   <option value="<?php echo .$row['course'].; ?>">.$row['course'].</option>//the second $row['course'] is the text which is actually going to be displayed to user.. u can use course title or whatever u have in ur db

      }

      </select>
?>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

u messed it up pretty bad...
Look at the code i pasted and then look what u have used... I can see hell lot of difference.
just try the code i provided and once u get it working then try to make whatever changes u want to have...
As of now ur syntax itself is wrong... where are all the echo statements i wrote? u cant use html tags without echo'ing them

<?php
    include('connect-db.php');


    $result = mysql_query("SELECT * FROM courses") 
        or die(mysql_error());  

    <select name="course">

      while($row = mysql_fetch_array( $result )) {


   <option value="<?php echo .$row['course'].; ?>">.$row['course'].</option>//the second $row['course'] is the text which is actually going to be displayed to user.. u can use course title or whatever u have in ur db

      }

      </select>
?>

yap..i know..i used your code just like what you've said..i already run it..but when i add new name and course,when i click add button,succesfully added appeared but the data didn't add from the database itself...that's why i change some code..(and that's the code i posted)sorry for statement(code).it's just a misinterpretation...

Edited 3 Years Ago by mike_2000_17: Fixed formatting

then wy dont u post up the code used for database insertion... coz i guess thats wher d problem lies..

then wy dont u post up the code used for database insertion... coz i guess thats wher d problem lies..

i don't know if the problem is in inserting records...

hope this will solve for me and clear from you..tnx :)

Godbless!
here's the code i used...

<?php

    function renderForm($studno, $name, $course, $year, $department, $error)
    {
        ?>
               
            <form action="" method="post">
           
                <strong><center><br>Student no:</strong>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="studno" value="<?php echo $studno; ?>" /><br/>
                <strong><center><br>Name:</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="name" value="<?php echo $name; ?>" /><br/>
		<strong><center><br>Course:</strong>

<?php
    include('connect-db.php');

   
    $result = mysql_query("SELECT * FROM courses") 
        or die(mysql_error());  
 
	echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name=course>";
    while($row = mysql_fetch_array( $result )) { 

        echo '<option>' . $row['course'] . '</option>';  
	
       }
        
    echo "</select>"; 

    
?>
                
                <center><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Add">
            
            </form>    
        
        <?php    
    }

    // connect to the database
    include('connect-db.php');
    
       if (isset($_POST['submit']))
    {    
        // get form data, making sure it is valid
        $studno = htmlspecialchars($_POST['studno']);
            $name = htmlspecialchars($_POST['name']);
	    $course = htmlspecialchars($_POST['course']);
            $year = htmlspecialchars($_POST['year']);
	    $department = htmlspecialchars($_POST['department']);
	
        
        // check to make sure both fields are entered
        if ($studno == '' || name == '' || course == '' || year == '' || department == '')
            {
              $error = 'ERROR: Please fill in all required fields!';
            
            // if either field is blank, display the form again
             renderForm($id, $studno, $name, $course, $year, $department, $error);
            }
        else
        {
                        mysql_query("UPDATE students SET studno='$studno', name='$name', course='$course', year='$year', department='$department' WHERE id='$id'")
                    or die(mysql_error()); 
            
            echo"<br><br><center>Succesfully added!";    
        }
    }
    else
    // if the form hasn't been submitted, display the form
    {
        renderForm('','','','','','');
    }

?>

well there are lots of issues with ur code
first and foremost, u didnt display all the fields in the form.
here is the modified code, i have commented out the fields which u didnt show in the form otherwise it will always throw error to fill up all the fields which are not even present there..

<?php
 
    function renderForm($studno, $name, $course, $year, $department, $error)
    {
        ?>
 
            <form action="" method="post">
 
                <strong><center><br>Student no:</strong>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="studno" value="<?php echo $studno; ?>" /><br/>
                <strong><center><br>Name:</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="name" value="<?php echo $name; ?>" /><br/>
		<strong><center><br>Course:</strong>
 
<?php
   
    include('connect-db.php'); 
 
    $result = mysql_query("SELECT * FROM courses") or die(mysql_error());  
 
	echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name=course>";
    while($row = mysql_fetch_assoc( $result )) { 

        echo '<option value="'.$row['course'].'">' . $row['course'] . '</option>';  
 
       }
 
    echo "</select>"; 
 
 
?>
 
                <center><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Add">
 
            </form>    
 
        <?php    
    }
 
    // connect to the database
   include('connect-db.php');
 
       if (isset($_POST['submit']))
    {    
        // get form data, making sure it is valid
        $studno = htmlspecialchars($_POST['studno']);
            $name = htmlspecialchars($_POST['name']);
	    $course = htmlspecialchars($_POST['course']);
            $year = htmlspecialchars($_POST['year']);
	    $department = htmlspecialchars($_POST['department']);
 
 
        // when u have all the fields present in ur form, just uncomment the below line to include those fields too
        if ($studno == '' || $name == '' || $course == '')// || $year == '' || $department == '')
            {
              echo 'ERROR: Please fill in all required fields!';
 
           //  if either field is blank, display the form again
             renderForm($id, $studno, $name, $course, $year, $department, $error);
            }
        else
        {
			$query = "INSERT INTO students (studno, name, course) values ('$studno','$name','$course')"; //you can add other fields too.., just the same way
			mysql_query($query)
                    or die(mysql_error()); 
 
            echo"<br><br><center>Succesfully added!";    
        }
    }
    else
    // if the form hasn't been submitted, display the form
    {
        renderForm('','','','','','');
    }
 
?>

Just try this and let me know if u face any problem...
cheers!!

<?php

    function renderForm($studno, $name, $course, $year, $department, $error)
    {
        ?>
               
            <form action="" method="post">
           
                <strong><center><br>Student no:</strong>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="studno" value="<?php echo $studno; ?>" /><br/>
                <strong><center><br>Name:</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="name" value="<?php echo $name; ?>" /><br/>
		<strong><center><br>Course:</strong>

<?php
    include('connect-db.php');

   
    $result = mysql_query("SELECT * FROM courses") 
        or die(mysql_error());  
 
	echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name=course>";
    while($row = mysql_fetch_array( $result )) { 

        echo '<option>' . $row['course'] . '</option>';  
	
       }
        
    echo "</select>"; 

    
?>
                
                <center><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Add">
            
            </form>    
        
        <?php    
    }

    // connect to the database
    include('connect-db.php');
    
       if (isset($_POST['submit']))
    {    
        // get form data, making sure it is valid
        $studno = htmlspecialchars($_POST['studno']);
            $name = htmlspecialchars($_POST['name']);
	    $course = htmlspecialchars($_POST['course']);
            $year = htmlspecialchars($_POST['year']);
	    $department = htmlspecialchars($_POST['department']);
	
        
        // check to make sure both fields are entered
        if ($studno == '' || name == '' || course == '' || year == '' || department == '')
            {
              $error = 'ERROR: Please fill in all required fields!';
            
            // if either field is blank, display the form again
             renderForm($id, $studno, $name, $course, $year, $department, $error);
            }
        else
        {
                        mysql_query("UPDATE students SET studno='$studno', name='$name', course='$course', year='$year', department='$department' WHERE id='$id'")
                    or die(mysql_error()); 
            
            echo"<br><br><center>Succesfully added!";    
        }
    }
    else
    // if the form hasn't been submitted, display the form
    {
        renderForm('','','','','','');
    }

?>

Edited 7 Years Ago by venkat0904: n/a

ok..i'll try this code..hope it will solve a lot..:)
tnx for the time ...
hmmm i saw some changes from the while function..you chose to used "assoc" and not array..


what is assoc by theway?is it associated?because all i know is using an array..because someone told me that array is easy to use rather than in any unfamiliar tags especially if you doesn't know any about the particular code tag.


hmmm anyway,,
i really appreciate it..:)
i also learned..Godbless...

Edited 7 Years Ago by takeshi: n/a

when u use fetch_array without second parameter, it's default is both, ie it will return number indexed array as well as string indexed array which i personally feel is unnecessary and will eat up space. In contrast fetch_assoc returns only string indexed array with corresponding column names in your table and that is pretty much what we require here.

ok..i'll try this code..hope it will solve a lot..:)
tnx for the time ...
hmmm i saw some changes from the while function..you chose to used "assoc" and not array..


what is assoc by theway?is it associated?because all i know is using an array..because someone told me that array is easy to use rather than in any unfamiliar tags especially if you doesn't know any about the particular code tag.


hmmm anyway,,
i really appreciate it..:)
i also learned..Godbless...

Comments
this will help me a lot! :)

when u use fetch_array without second parameter, it's default is both, ie it will return number indexed array as well as string indexed array which i personally feel is unnecessary and will eat up space. In contrast fetch_assoc returns only string indexed array with corresponding column names in your table and that is pretty much what we require here.

oh ok...and i guess the INSERT tag was the problem..coz i used UPDATE instead of using INSERT because i forgot that my task is adding records..did you noticed that code?
And thank you for this.. :) anyway,i'am currently developing a system using touch screen technology and i hope i can finish it on february..tnx again for the effort and time you've consumed..:)
Godbless

oh ok...and i guess the INSERT tag was the problem..coz i used UPDATE instead of using INSERT because i forgot that my task is adding records..did you noticed that code?
And thank you for this.. :) anyway,i'am currently developing a system using touch screen technology and i hope i can finish it on february..tnx again for the effort and time you've consumed..:)
Godbless

yeah i did noticed ur code n i guess thats why i changed it... :P
newayz glad i could help..
cheers

hi..it's me again..
i'll some question regarding my system login part..
This is my databasae connection..

<?
include("constants.php");
      
class MySQLDB
{
   var $connection;         //The MySQL database connection
      function MySQLDB(){
      /* Make connection to database */
      $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
      mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
      
      
   
   function confirmUserPass($username, $password){
      /* Add slashes if necessary (for query) */
      if(!get_magic_quotes_gpc()) {
	      $username = addslashes($username);
      }

      /* Verify that user is in database */
      $q = "SELECT password FROM ".userpass." WHERE username = '$username'";
      $result = mysql_query($q, $this->connection);
      if(!$result || (mysql_numrows($result) < 1)){
         return 1; //Indicates username failure
      }

      /* Validate that password is correct */
      if($password == $dbarray['password']){
         return 0; //Success! Username and password confirmed
      }
      else{
         return 2; //Indicates password failure
      }
   }
   
      
      $q = "SELECT id FROM ".userpass." WHERE username = '$username'";
      $result = mysql_query($q, $this->connection);
      if(!$result || (mysql_numrows($result) < 1)){
         return 1; //Indicates username failure
      }

      
?>

my system does not run well.the username as well as the password is saved on it's database.my database name is 'records' and it's table name is 'userpass'...i can't log..what do you think the problem with my code?

all i want is insert username and password from the textbox in the login menu then validate from it's database. when i click the login button,it will proceed to my main page.

Good day,
I have problem with my codes, when i update my database, all records update altogether, someone help me about this, see my codes here or click the image for the visualClick Here

  <?php
    mysql_connect("localhost", "root", "") or die("Connection Failed");
     mysql_select_db("elev8groupportal")or die("Connection Failed"); 


      if(isset($_POST)){


       $req_id= $dn1['req_code'];
       $query = "UPDATE request SET req_status = 'Waiting for note' WHERE req_code = '".$dn1['req_code']."'" ; 


     if(mysql_query($query)){
      echo "updated";
    } else{ 
      echo "fail";
    } 
     }
     ?>

              <div class="content">  
                <form method="POST" name="update">  
                   <label>Date Created: </label><input type="text" name="req_code" id="req_code" value="<?php echo ($dn1['req_code']); ?>" /><br />
                   <label>Date Created: </label><input type="text" name="req_date" id="req_date" value="<?php echo ($dn1['req_date']); ?>" /><br />
                   <label>Request By: </label><input type="text" name="empname" id="empname" value="<?php echo ($dn1['empname']) ?>" /><br />
                   <label>Form Name: </label><input type="text" name="form_name" id="form_name" value="<?php echo $dn1['form_name']?>" /><br />
                   <label>Request Type: </label><input type="text" name="itrf_type" id="itrf_type" value="<?php echo $dn1['itrf_type']?>" /><br />
                   <label>Details: </label><input type="text" name="itrf_details" id="itrf_details" value="<?php echo $dn1['itrf_details']?>" /><br />
                    <label> Date Needed:</label><input type="text" name="req_dateneeded" id="req_dateneeded" value="<?php echo $dn1['req_dateneeded']?>" /><br />

                  <button type="submit" class="btn btn-primary" name="req_code">Approved</button>
                  <button type="submit" class="btn btn-primary" name="update2">Disapproved</button>

                 </form> 


                </div>

`

This article has been dead for over six months. Start a new discussion instead.