Jump to content

cmbcorp

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Everything posted by cmbcorp

  1. Hi, Thanks for the reply. I have put $myusername =$_POST['update.php']; $mypassword =$_POST['update.php']; In the update_ac.php And i went to update the details via update_ac.php And i went to list the table contents and it still hasnt got any values in the fields username and password. Did i do something wrong? Cheers. Thanks. Jason.
  2. Now, can you explain where the variables $id, $myusername and $mypassword are defined? They are used in your query... An answer to that question.. Hope im not repeating my self. I guess they arnt defined, how would i define them? they are the fields in my table.. Please let me know what i should do. Cheers, Jason.
  3. Hi, Thanks for the reply. Ignore the above quote... In the update_ac.php i removed the following line: $sql="UPDATE $tbl_name SET id='$id', username='$myusername', password='$mypassword' WHERE id='$id'"; And replaced it with: $sql="UPDATE $tbl_name SET id='$id', `username`='$myusername', `password`='$mypassword' WHEREid='$id'"; I went to list my table via list records.php and went to update. I entered in ID 1 and put in a new username and password and went to update. It said it was successfull. I went to list the table contents again and in the id 1, there is no username and password. Any ideas? Cheers, Jason. BTW... Thank you soooooooooo much for your help.
  4. cheers for getting back to me, i really appreciate it... im very new to this.. but im getting the hang of it.. a answer to your question: Now, can you explain where the variables $id, $myusername and $mypassword are defined? They are used in your query... im using my simple login script that im using and thats where those variables came from, im gathering that they didnt pass through to my current script? let me know your thoughts. cheers, jason.
  5. Hi Guys, I am having some issues with updating my sql table with a simple script. The table name is members, i have 3 fields in the table which are: ID username password I created the table as follows: CREATE TABLE `members` ( `id` int(4) NOT NULL auto_increment, `username` varchar(65) NOT NULL default '', `password` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2 ; I then: Dumped the data for table `members` INSERT INTO `members` VALUES (1, 'jason', 'jason''); I have 3 php files: list_records.php code is as follows: <?php $host="localhost"; // Host name $username="greenpos_admin1"; // Mysql username $password="carlo"; // Mysql password $db_name="greenpos_test"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <table width="400" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><strong>List data from user details from database. </strong> </td> </tr> <tr> <td align="center"><strong>ID</strong></td> <td align="center"><strong>Username</strong></td> <td align="center"><strong>Password</strong></td> <td align="center"><strong>Update</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><? echo $rows['id']; ?></td> <td><? echo $rows['username']; ?></td> <td><? echo $rows['password']; ?></td> <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> The second file (update.php): <?php $host="localhost"; // Host name $username="greenpos_admin1"; // Mysql username $password="carlo"; // Mysql password $db_name="greenpos_test"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>ID</strong></td> <td align="center"><strong>Username</strong></td> <td align="center"><strong>Password</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="id" type="text" id="id" value="<? echo $rows['id']; ?>"></td> <td align="center"><input name="username" type="text" id="myusername" value="<? echo $rows['username']; ?>" size="15"></td> <td><input name="password" type="text" id="mypassword" value="<? echo $rows['password']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <? // close connection mysql_close(); ?> The third file (update_ac.php): <?php $host="localhost"; // Host name $username="greenpos_admin1"; // Mysql username $password="carlo"; // Mysql password $db_name="greenpos_test"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET id='$id', username='$myusername', password='$mypassword' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='list_records.php'>View result</a>"; } else { echo "ERROR"; } ?> Basically i went to update the the username and password and it works, but when i list the table contents there is no username and password under ID 1 in the table. Any thoughts guys? btw you guys rock! i really appreciate your help. Jason.
  6. i stand corrected. i didnt copy the code properly. THANKS GUYS!!! YOU HAVE BEEN GREAT! Thanks also teng84.
  7. HI thanks once again for your help! you guys are great!. unfortunatly i replaced that code and the error message appears: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/greenpos/public_html/test4/login_success.php:2) in /home/greenpos/public_html/test4/login_success.php on line 3 Login Successful But im gathering it is working so far apart from the error. Cheers, Jason.
  8. Thanks once again. Code for login_success.php is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <? session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> Login Successful </body> </html>
  9. Hi, Thanks soooooooo much for your reply. I had added that to the start of the code and the other to the end. I think it may have worked.. It does display Login Successfull. But i still get a error message (which is new mind you). Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/greenpos/public_html/test4/login_success.php:2) in /home/greenpos/public_html/test4/login_success.php on line 3 Login Successful Please advise your thoughts. Cheers, Jason.
  10. Hi, I have been playing around with a simple php login script and im getting an error message when i attempt to log in with the username and password i set in the sql table Below is the code im using: Code: ( php ) <?php $host="localhost"; // Host name $username="greenpos_admin1"; // Mysql username $password="carlo"; // Mysql password $db_name="greenpos_test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. // Connect to server and select databse. $link=mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db($db_name, $link)or die("cannot select DB"); // username and password sent from signup form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$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_success.php" session_start(); $_SESSION['myusername']=$myusername; $_SESSION['mypassword']=$mypassword; header("location:login_success.php"); exit; } else { echo "Wrong Username or Password"; exit; } ?> This is what i did to create the table in mysql: Code: ( php ) CREATE TABLE `members` ( `id` int(4) NOT NULL auto_increment, `username` varchar(65) NOT NULL default '', `password` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2 ; I then: Dumped the data for table `members` Code: ( php ) INSERT INTO `members` VALUES (1, 'jason', 'jason''); Now when i use my login screen and type in my username and password i get this error message: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/greenpos/public_html/test4/checklogin.php:9) in /home/greenpos/public_html/test4/checklogin.php on line 37 Warning: Cannot modify header information - headers already sent by (output started at /home/greenpos/public_html/test4/checklogin.php:9) in /home/greenpos/public_html/test4/checklogin.php on line 40 line 37: session_start(); Line 40: header("location:login_success.php"); Im not sure if im diong everything right... The code for my main_login.php: Code: ( php ) <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action="checklogin.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Member Login </strong></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="myusername" type="text" id="myusername"></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="mypassword" type="text" id="mypassword"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Login"></td> </tr> </table> </td> </form> </tr> </table> All i can think of is that when i added the table members to my database, i added username and password as the fields and not myusername and mypassword? Please i would really appreciate your help. Thanks. Jason.
×
×
  • 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.