Jump to content

xxreenaxx1

Members
  • Posts

    167
  • Joined

  • Last visited

    Never

Everything posted by xxreenaxx1

  1. I want to use a session to get information from mySql. Say Username and use this to do a query SELECT DISTINCT u.Use_Name, u.Use_ID, u.Use_Name, us.Sub_ID, s.Sub_NameFROM user u, user_x_subject us, subject sWHERE u.Use_Name = '[b][size=14pt]$username' [/size] [/b] AND u.Use_ID = us.Use_ID AND s.Sub_ID = us.Sub_ID Now the code work <?php MYSQL_CONNECT(localhost,'root','') OR DIE("Unable to connect to database"); @mysql_select_db(Examination) or die( "Unable to select database"); $query=("SELECT * FROM subject"); $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Sub_ID'].">".$row['Sub_Name']."</OPTION>"; } ?>
  2. How would you do a drop down box using session So far I have <?php $_SESSION['username']; $query="SELECT DISTINCT u.Use_Name, u.Use_ID, u.Use_Name, us.Sub_ID, s.Sub_Name FROM user u, user_x_subject us, subject s WHERE u.Use_Name = '$username' AND u.Use_ID = us.Use_ID AND s.Sub_ID = us.Sub_ID"; $result = mysql_query($query); while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[sub_ID]>$nt[sub_Name]</option>"; } echo "</select>";// ?>
  3. but I am getting these echo's from another table. Can I do that?
  4. I am echo information from the database now I would like to insert these to different table. I am using checkbox to echo and when the user click on the one of these the result should be saved to a new table. So far I have <?php include 'Database/connection.php'; include 'Database/question_sql.php'; while($info = mysql_fetch_array( $sql )) { echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; } ?>
  5. checkbox works. Now can I add these chosen checkbox on to mysql. Eg: if someone choose choice1 and I would like to save this onto answer1 on to my mysql if I confused you then I apologies.
  6. I am retrieving data from mysql and printing this as a table. Now I want to print this as a checkbox. But not sure how to? <?php mysql_connect("localhost", "root", "")or die("cannot connect"); mysql_select_db("Examination")or die("cannot select DB"); $sql=mysql_query("SELECT * FROM question") or die(mysql_error()); Print "<table border cellpadding=5>"; while($info = mysql_fetch_array( $sql )) { Print "<th>Question:</th> <td>".$info['Que_Question'] . "</td> "; Print "<th>Choice1:</th> <td>".$info['Que_Choice1'] . "</td> "; Print "<th>Choice2:</th> <td>".$info['Que_Choice2'] . "</td> "; Print "<th>Choice3:</th> <td>".$info['Que_Choice3'] . "</td> "; Print "<th>Choice4:</th> <td>".$info['Que_Choice4'] . "</td> "; } Print "</table>"; ?>
  7. Atleast I am getting an error message. But is says the login is failed. Even though the data does Exist.
  8. My problem has been moved on from that to getting a blank page. PHP is just killing my life <?PHP $connect = mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("Examination") or die(mysql_error()); if ($_POST['submit']) { //get data $username= $_POST['user']; $password =$_POST['pass']; if ($username && $password) { $query = mysql_query("SELECT * FROM user"); while($getrows =mysql_fetch_assoc($query)) { $dbuser = $getrows['user']; $dbpass = $getrows['pass']; } if (($username == $dbuser) &&($password == $dbpass)) { echo "welcome" . $_COOKIE['username'] . "whoever"; $_SESSION['username'] = $username; } else { echo"failed"; } } else { die("Field not empty"); } } ?>
  9. Sorry. I did that it wont work. It let everyone in. As in even if the Rol_ID was 2 <?PHP $connect = mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("Examination") or die(mysql_error()); if ($_POST['submit']) { //get data $username= $_POST['user']; $password =$_POST['pass']; if ($username && $password) { $query = mysql_query("SELECT * FROM user WHERE Rol_ID =1"); while($getrows =mysql_fetch_assoc($query)) { $dbuser = $getrows['user']; $dbpass = $getrows['pass']; } if (($username == $dbuser) &&($password == $dbpass)) { header("location:login_success.php"); } else { echo"failed"; } } else { die("Field not empty"); } } ?>
  10. So I would like to write a query on PHP but it doesnt exactly work the way I want it to work Select * FROM user WHERE Rol_ID = 1 When I run this query it work on my sql, but when I try to enter this on a php page it just wont work.
  11. How do you know its line 42. Well I got that fixed. Now I got another problem which I want to make a query ("SELECT * FROM user WHERE Rol_ID =1") But this wont work.
  12. I have a database which contains three users. But I can only access one of the user through PHP. When I try to enter other username I get a blank message. Anyone knows why??
  13. Ohh.. But I am just having trouble with PHP though someone out there could help me. Will do
  14. Thanks for that. Now I am getting an error with the last time ?>
  15. Here you go <?php //session_start();//Starting session $host="localhost"; // Host name $username="root"; // username $password=""; // password $db_name="Examination"; // Databasename $tbl_name="User"; // Tablename $username = $_POST["username"]; $password = $_POST["password"]; $login=$_GET["login"] setcookies("username","$username",time()+86400); if($login="yes"){ // Connection to the server and 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 WHERE Use_Name='$username' and Use_Password='$password'"; $result=mysql_result($sql,0); if($result!=1){ echo"invlaid login";} else{ echo"welcome".$_COOKIE["username"]."whoever"; $_SESSION["username"] = $username; } ?>
  16. When I try to run a program, I am getting an error message. Not sure why and the code that has the error is shown below. Error message is syntax error, unexpected T_STRING setcookies("username","$username",time()+86400);
  17. Thanks for the help. And Yes I am playing with the codes. Jesus commenting on all my codes and what not. I am just using them to help me learn PHP. Is that a crime now?
  18. My code work and let me log in but whether the login is correct or not it keeps on displaying "Wrong username and password" if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; }
  19. I have connected and be able to log in. Now Yes I did grab the username and try to place it on the page. Nothing display. Here is my table CREATE TABLE IF NOT EXISTS `user` ( `Use_ID` int(11) NOT NULL AUTO_INCREMENT, `Use_Name` varchar(20) NOT NULL, `Use_Password` varchar(20) NOT NULL, `Rol_ID` int(11) NOT NULL, PRIMARY KEY (`Use_ID`), Foreign KEY `Rol_ID` (`Rol_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="Examination"; // Database name $tbl_name="User"; // 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 and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE Use_Name='$myusername' and Use_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_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> <? session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <html> <head> <title>Multiple choice</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <H1> Welcome Ms <?php echo $myusername; ?> </H1> </body> <noframes><body bgcolor="#FFFFFF" text="#000000"> </body></noframes> </html>
  20. I tired to view design and connected it that way Thanks though...
  21. Hi I have created a table containing users. Now they can log in. and I want to use the username and display a welcome message. How do I display that? <H1> Welcome Ms <?php echo $myusername; ?> </H1> If I confused you then please let me know
  22. Nope doesn't work. The name wont display.
  23. I tired to create table that has a foreign key but it wont let me create it CREATE TABLE IF NOT EXISTS `user` ( `Use_ID` int(11) NOT NULL AUTO_INCREMENT, `Use_Name` varchar(20) NOT NULL, `Use_Password` varchar(20) NOT NULL, `Rol_ID` int(11) NOT NULL, PRIMARY KEY (`Use_ID`), KEY `Rol_ID` (`Rol_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; KEY 'Rol_ID'('Rol_ID') this is the foreign key. But I am not sure why its saying KEY. And when I view the design no tables are linked together.
  24. Hey, I tired to run this. It so simple but I don't know whats wrong with it <HEAD> <TITLE>Welcome</TITLE> </HEAD> <BODY> <P>Hi, <?php $firstname = 'Ragena'; echo '$firstname'; // PHP finishes here, now back to HTML ?> Your first name is <?php echo $firstname; ?>.</P> <P>The time now is <?php echo date(‘Y-m-d H: -- i:s’); ?></P> </BODY> </HTML>
×
×
  • 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.