Jump to content

pritam79

Members
  • Content Count

    92
  • Joined

  • Last visited

Everything posted by pritam79

  1. pritam79

    php image handling

    I have a php site. I also have images stored in folders to be displayed in those pages. But i wanted to know how do i store those images in mysql and display them in my php pages by extracting them from mysql database. please give some scripts to display those image from mysql by the help of php script.
  2. pritam79

    PHP form

    <?phpsession_start();if(isset($_SESSION['userid'])) { if($_SESSION['level']==1) { echo "<div id='navbar'></div>"; header('Refresh: 5; URL=admin.php'); echo "<div id='content'>"; echo "<p><br>You are already logged-in as admin, and will be re-directed to your home page.</br>"; echo "If your browser doesnot redirect you automatically, <a href='admin.php'>click here</a>.</p>"; include "footer.php"; exit; } if($_SESSION['level']==2) { echo "<div id='navbar'></div>"; header('Refresh: 5; URL=mypage.php'); echo "<div id='content'>"; echo "<p><br>You are already logged-in as a contractor, and will be re-directed to your home page.</br>"; echo "If your browser doesnot redirect you automatically, <a href='mypage.php'>click here</a>.</p>"; include "footer.php"; exit; } }if($_SERVER['REQUEST_METHOD'] == 'POST') { if(strlen($_POST['contractor_name']) !='' && strlen($_POST['contractor_password']) !='' && strlen($_POST['address']) !='' && strlen($_POST['tin_no']) !='') { require("db-connect.php"); $db = db_connect(); if($db) { $contractor_name = mysql_real_escape_string($_POST['contractor_name'], $db); $contractor_password = mysql_real_escape_string($_POST['contractor_password'], $db); $contractor_type = mysql_real_escape_string($_POST['contractor_type'], $db); $address = mysql_real_escape_string($_POST['address'], $db); $tin_no = mysql_real_escape_string($_POST['tin_no'], $db); $sql = "INSERT INTO contractor (contractor_id, contractor_name, contractor_password, contractor_type, address, tin_no, level) VALUES ('', '$contractor_name', '$contractor_password', '$contractor_type', '$address', '$tin_no', 2)"; mysql_query($sql, $db) or die(mysql_error($db)); $_SESSION['contractor_id'] = mysql_insert_id($db); $_SESSION['level'] = 2; $_SESSION['contractor_name'] = $contractor_name; } header('Location: mypage.php'); exit(); } }include "header.php";?><body><div id="navbar"><table align="center"> <tr> <td><a href="index.html">Home</a></td> <td><a href="about.php">About Us</a></td> <td><a href="contact.php">Contact us</td> <td><a href="register.php">Register</a></td> <td><a href="login.php">Login</a></td> </tr></table></div> <div id="content"><br><div id="msg">Fill in your details to register. Use lowercase 'username' and 'password'</div><br><form name="register" method="POST" action="register.php"><table align="center"> <tr> <td>Username:</td><td><input type="text" name="contractor_name" value="<?php if(isset($_POST['submit']) && (strlen($_POST['contractor_name']) > 0 || strlen($_POST['contractor_name']) < 11)) echo $_POST['contractor_name']; ?>"></td><?php if(isset($_POST['submit']) && (strlen($_POST['contractor_name']) < 1 || strlen($_POST['contractor_name']) >10)) echo "<div id='rusr-err'>Username must be 1 to 10 chars<div>"; ?> </tr> <tr> <td>Password:</td><td><input type="password" name="contractor_password"></td><?php if(isset($_POST['submit']) && (strlen($_POST['contractor_password']) < 1 || strlen($_POST['contractor_password']) > 10)) echo "<div id='rpas-err'>Password must be 1 to 10 chars<div>"; ?> </tr> <tr> <td>Contractor type:</td><td><input name="contractor_type" type="radio" checked="checked" value="1" style="width: 20px">Firm <input name="contractor_type" type="radio" value="2">Company <input name="contractor_type" type="radio" value="3">Individual </tr> <tr><td>Address:</td> <td><textarea name="address" cols="20" rows="2"></textarea></td><?php if(isset($_POST['submit']) && strlen($_POST['address']) < 1) echo "<div id='raddress-err'>Address cannot be blank.<div>"; ?> </tr> <tr> <td>Tin no:</td><td><input type="text" name="tin_no" value="<?php if(isset($_POST['submit']) && (strlen($_POST['tin_no']) == 18)) echo $_POST['tin_no']; ?>"></td><?php if(isset($_POST['submit']) && (strlen($_POST['tin_no']) != 18)) echo "<div id='rtin-err'>Tin number must be 18 digits.<div>"; ?> </tr> <tr> <td></td><td align="center"><input name="submit" type="submit" value="Register"> <input type="reset"></td> </tr></table></form></div><?phpinclude "footer.php";?> This is a register.php page, and what I want is this- "When the user (contractor) selects any of the "contractor_type" radio button a new textbox should be displayed next to the 3rd radio button enabling the contractor to enter the 'company name' or 'firm name' dependind on the selected radio button.
  3. pritam79

    insert error

    its all working now. just had some problem with the database table structure. Now when I register, I am trying to execute multiple insert queries at the same time as given below. $sql = "INSERT INTO company_com (id_com, idusr_com) VALUES ('', '".$_SESSION['id_usr']."')"; mysql_query($sql, $result) or die(mysql_error($result)); $_SESSION['id_com'] = mysql_insert_id($result); $sql = "INSERT INTO domain_dom (id_dom) VALUES ('')"; mysql_query($sql, $result) or die(mysql_error($result)); $sql = "INSERT INTO location_loc (id_loc) VALUES ('')"; mysql_query($sql, $result) or die(mysql_error($result)); $sql = "INSERT INTO job_job (id_job, idcom_job, iddom_job, idloc_job) VALUES ('', '".$_SESSION['id_com']."', '".$_SESSION['id_dom']."', '".$_SESSION['id_loc']."')"; mysql_query($sql, $result) or die(mysql_error($result)); But i get the error - Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\Job-site\register_company.php on line 45. Any help in identifying it?
  4. pritam79

    insert error

    I tried the following for user registration.$sql = "INSERT INTO user_usr (id_usr, username_usr, password_usr, level_usr, email_usr) VALUES ('', '$username', '$password', '1', '$email')"; mysql_query($sql, $result) or die(mysql_error($result)); echo $sql; exit; The user was registered as before with the values getting inserted into MySql as earlier. But on echoing $sql I get this output in the browser window-INSERT INTO user_usr (id_usr, username_usr, password_usr, level_usr, email_usr) VALUES ('', 'User7', 'User7', '1', 'user7@gmail.com')
  5. pritam79

    insert error

    I removed the apostrophes from ‘1’ and ‘2’ (int type) of the two insert queries, but even now only zeros are getting inserted in MySql. But when I echo $_SESSION['level_usr'] on the page where a user is redirected after registration, I get the proper output as 1 or 2 depending on who registered (user or company). Its showing 0 in the table evertime I register be it a user or a company.Also, the length of the email field is varchar(25), but still the problem persists.
  6. pritam79

    insert error

    This is register_company.php<?phpsession_start();if(isset($_SESSION['id_usr'])){ if($_SESSION['level_usr']=1) { header('Location:user/index.php'); exit; } if($_SESSION['level_usr']=2) { header('Location:company/index.php'); exit; }}if($_SERVER['REQUEST_METHOD'] == 'POST'){ if(strlen($_POST['txtusername']) !='' && strlen($_POST['txtpassword']) !='' && strlen($_POST['txtemail']) !='') { require("db-connect.php"); $result = db_connect(); if($result) { $username = mysql_real_escape_string($_POST['txtusername'], $result); $password = mysql_real_escape_string($_POST['txtpassword'], $result); $email = mysql_real_escape_string($_POST['txtemail'], $result); $sql = "INSERT INTO user_usr (id_usr, username_usr, password_usr, level_usr, email_usr) VALUES ('', '$username', '$password', '2', '$email')"; mysql_query($sql, $result) or die(mysql_error($result)); $_SESSION['id_usr'] = mysql_insert_id($result); $_SESSION['level_usr'] = 2; $_SESSION['username'] = $username; $sql = "INSERT INTO company_com (id_com, idusr_com) VALUES ('', '".$_SESSION['id_usr']."')"; mysql_query($sql, $result) or die(mysql_error($result)); $_SESSION['id_com'] = mysql_insert_id($result); // $sql = "INSERT INTO company_com (id_com, idusr_com) VALUES ('', '".$_SESSION['id_usr']."')"; // mysql_query($sql, $result) or die(mysql_error($result)); // $sql = "INSERT INTO job_job (id_job, idcom_job) VALUES ('', '".$_SESSION['id_com']."')";// mysql_query($sql, $result) or die(mysql_error($result)); } header('Location: company/index.php'); exit(); } } include "header.php";?><body><div id="navbar"><table align="center"><tr> <td><a href="index.php">Home</a></td> <td><a href="about_us.php">About Us</a></td> <td><a href="register_user.php">Register User</a></td> <td><a href="register_company.php">Register Company</a></td> <td><a href="login.php">Login</a></td></tr></table></div><div id="content"><br><div id="msg">Fill in your details below to register as a company</div><br><form name="company_registration_form" method="post" action="register_company.php"><table align="center"><tr> <td>Username:</td><td><input type="text" name="txtusername" value="<?php if(isset($_POST['submit']) && (strlen($_POST['txtusername']) > 0 || strlen($_POST['txtusername']) < 7)) echo $_POST['txtusername']; ?>"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtusername']) < 1 || strlen($_POST['txtusername']) >6)) echo "<div id='rusr-err'>Username must be 1 to 6 chars<div>"; ?></tr><tr> <td>Password:</td><td><input type="password" name="txtpassword"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtpassword']) < 1 || strlen($_POST['txtpassword']) >6)) echo "<div id='rpas-err'>Password must be 1 to 6 chars<div>"; ?></tr><tr> <td>E-mail:</td><td><input type="text" name="txtemail" value="<?php if(isset($_POST['submit']) && isset($_POST['txtemail'])) echo $_POST['txtemail']; ?>"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtemail']) < 10 || strlen($_POST['txtemail']) > 25)) echo "<div id='remail-err'>Email must be at least 14 chars<div>"; ?></tr><tr> <td></td><td align="center"><input type="submit" value="Submit" name="submit"> <input type="reset"></td></tr></table></form></div><?phpinclude "footer.php";?> This is register_user.php <?phpsession_start();if(isset($_SESSION['id_usr'])){ if($_SESSION['level_usr']=1) { header('Location:user/index.php'); exit; } if($_SESSION['level_usr']=2) { header('Location:company/index.php'); exit; }}if($_SERVER['REQUEST_METHOD'] == 'POST'){ if(strlen($_POST['txtusername']) !='' && strlen($_POST['txtpassword']) !='' && strlen($_POST['txtemail']) !='') { require("db-connect.php"); $result = db_connect(); if($result) { $username = mysql_real_escape_string($_POST['txtusername'], $result); $password = mysql_real_escape_string($_POST['txtpassword'], $result); $email = mysql_real_escape_string($_POST['txtemail'], $result); $sql = "INSERT INTO user_usr (id_usr, username_usr, password_usr, level_usr, email_usr) VALUES ('', '$username', '$password', '1', '$email')"; mysql_query($sql, $result) or die(mysql_error($result)); $_SESSION['id_usr'] = mysql_insert_id($result); $_SESSION['level_usr'] = 1; $_SESSION['username'] = $username; } header('Location: user/index.php'); exit(); } }include "header.php";?><body><div id="navbar"><table align="center"><tr> <td><a href="index.php">Home</a></td> <td><a href="about_us.php">About Us</a></td> <td><a href="register_user.php">Register User</a></td> <td><a href="register_company.php">Register Company</a></td> <td><a href="login.php">Login</a></td></tr></table></div><div id="content"><br><div id="msg">Fill in your details below to register as an applicant</div><br><form name="user_registration_form" method="post" action="register_user.php"><table align="center"><tr> <td>Username:</td><td><input type="text" name="txtusername" value="<?php if(isset($_POST['submit']) && (strlen($_POST['txtusername']) > 0 || strlen($_POST['txtusername']) < 7)) echo $_POST['txtusername']; ?>"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtusername']) < 1 || strlen($_POST['txtusername']) >6)) echo "<div id='rusr-err'>Username must be 1 to 6 chars<div>"; ?></tr><tr> <td>Password:</td><td><input type="password" name="txtpassword"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtpassword']) < 1 || strlen($_POST['txtpassword']) >6)) echo "<div id='rpas-err'>Password must be 1 to 6 chars<div>"; ?></tr><tr> <td>E-mail:</td><td><input type="text" name="txtemail" value="<?php if(isset($_POST['submit']) && isset($_POST['txtemail'])) echo $_POST['txtemail']; ?>"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtemail']) < 10 || strlen($_POST['txtemail']) > 25)) echo "<div id='remail-err'>Email must be at least 14 chars<div>"; ?></tr><tr> <td></td><td align="center"><input type="submit" value="Submit" name="submit"> <input type="reset"></td></tr></table></form></div><?phpinclude "footer.php";?>
  7. pritam79

    insert error

    I have two pages ‘register_user.php’ which allows job-applicants to register, and ‘register_company.php’ which allows the companies to register. I am using wamp. A job-applicant or Company gets registered properly, but the only errors I get are- level_usr gets inserted in the tables as 0 in both cases whereas it should have inserted a 1 for an applicant, and 2 for a company. Also, the email field value of the table is inserted as - it begins with some weird character and then the address followed by a dot, but the com after the dot is absent.
  8. pritam79

    insert error

    I have two pages ‘register_user.php’ which allows job-applicants to register, and ‘register_company.php’ which allows the companies to register. I am using wamp. A job-applicant or Company gets registered properly, but the only errors I get are- level_usr gets inserted in the tables as 0 in both cases whereas it should have inserted a 1 for an applicant, and 2 for a company. Also, the email field value of the table is inserted as illustrated in the image. (attachment)
  9. pritam79

    Php Mysql Error

    I created this mysql table using WAMP server's PHPMyAdmin interface- id_com (pk), idusr_com(fk),name_com, address_comAlso there is some PHP code as shown below- require("db-connect.php"); $db = db_connect(); $name_com = mysql_real_escape_string($_POST['txtname_com'], $db); $address_com = mysql_real_escape_string($_POST['txtaddress_com'], $db); if($db) { if(isset($_POST['Add'])) { // insert company name and location in company_com $sql = "INSERT INTO company_com(name_com, address_com) VALUES ('$name_com', '$address_com') WHERE idusr_com = ".$_SESSION[id_usr]; mysql_query($sql, $db) or die(mysql_error($db)); header('Location: company/index.php'); exit(); } if(isset($_POST['Update'])) { // update company name and location in company_com $sql = "UPDATE company_com SET name_com = $name_com, address_com = $address_com WHERE idusr_com = ".$_SESSION[id_usr]; mysql_query($sql, $db) or die(mysql_error($db)); header('Location: company/index.php'); exit(); } } But, on Inserting a record I am getting this error.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versionfor the right syntax to use near 'WHERE idusr_com = 92' at line 2And on updating I get this error.Unknown column 'Apple1' in 'field list'This is the table 'company_com' on browsing--___________________________________________id_com | idusr_com | name_com | address_com| PK- id_com, FK- id_usr___________________________________________| 7 | 88 | Apple | LA | 11 | 92 | | |-------------------------------------------This is the table 'user_usr' on browsing-- PK- id_usr____________________________________________________________________ id_usr | username_usr | password_usr | level_usr | email_usr |____________________________________________________________________| 88 | com1 | **** | 2 | com1gmail.com | 92 | com2 | **** | 2 | com2gmail.com |---------------------------------------------------------------------
  10. The above script uses sessions to track a user throughout the site. But as I close the browser, the next time the user has to log in again. I want the 'remember me' checkbox to work. That is if a user logs in by checking 'remember me' and then closes the browser, the next time the same user requests the page he need not enter the username and password and is automatically redirected to his home page.
  11. Hi all,I am using the following login script that uses just sessions. Even in the other pages, which a user views after logging in, use sessions. I want to use sessions and cookies together in the login script as well as in all the later pages, which would lessen the server load. I want to include cookies as well, so that the two (cookies+sessions) function together. How can I do so? Please illustrate. Thanks.. <?phpsession_start();if(isset($_SESSION['id_usr'])){ if($_SESSION['level_usr']==1) { include "header.php"; echo "<div id='navbar'></div>"; header('Refresh: 5; URL=user/index.php'); echo "<div id='content'>"; echo "<p><br>You are already logged-in as an applicant, and will be re-directed to your home page.</br>"; echo "If your browser doesnot redirect you automatically, <a href='user/index.php'>click here</a>.</p>"; include "footer.php"; exit; } if($_SESSION['level_usr']==2) { include "header.php"; echo "<div id='navbar'></div>"; header('Refresh: 5; URL=company/index.php'); echo "<div id='content'>"; echo "<p><br>You are already logged-in as a company, and will be re-directed to your home page.</br>"; echo "If your browser doesnot redirect you automatically, <a href='company/index.php'>click here</a>.</p>"; include "footer.php"; exit; }}if($_SERVER['REQUEST_METHOD'] == 'POST') { if(strlen($_POST['txtusername']) !='' && strlen($_POST['txtpassword']) !='' && strlen($_POST['txtemail'] !='')) { require("db-connect.php"); $db = db_connect(); if($db) { $username = mysql_real_escape_string($_POST['txtusername'], $db); $password = mysql_real_escape_string($_POST['txtpassword'], $db); $email = mysql_real_escape_string($_POST['txtemail'], $db); $level_usr = mysql_real_escape_string($_POST['level_usr'], $db); if($level_usr==1) // if user is an applicant { $query = "SELECT * FROM user_usr WHERE username_usr = '$username' AND password_usr = '$password' AND email_usr = '$email' AND level_usr = '$level_usr'"; $result = mysql_query($query, $db); if($row = mysql_fetch_array($result)) { if($_POST['chkrem'] == "REMEMBER") // if company logs in for the first time { setcookie("login[username]", $username, time()+3600); setcookie("login[password]", $password, time()+3600); setcookie("login[ulevel]", $level_usr, time()+3600); } $_SESSION['id_usr'] = $row['id_usr']; $_SESSION['username'] = $row['username_usr']; $_SESSION['level_usr'] = $row['level_usr']; header('location:user/index.php'); exit; } } if($level_usr==2) // if user is a company { $query = "SELECT * FROM user_usr WHERE username_usr = '$username' AND password_usr = '$password' AND email_usr = '$email' AND level_usr = '$level_usr'"; $result = mysql_query($query, $db); if($row = mysql_fetch_array($result)) { if($_POST['chkrem'] == "REMEMBER") // if company logs in for the first time { setcookie("login[username]", $username, time()+3600); setcookie("login[password]", $password, time()+3600); setcookie("login[clevel]", $level_usr, time()+3600); } $_SESSION['id_usr'] = $row['id_usr']; $_SESSION['username'] = $row['username_usr']; $_SESSION['level_usr'] = $row['level_usr']; header('location:company/index.php'); exit; } } } }}include "header.php";?><body><div id="navbar"><table align="center"><tr> <td><a href="index.php">Home</a></td> <td><a href="about_us.php">About Us</a></td> <td><a href="register_user.php">Register User</a></td> <td><a href="register_company.php">Register Company</a></td> <td><a href="login.php">Login</a></td></tr></table></div><div id="content"><br><div id="msg">Fill in your details to login.</div><br><form name="login_form" method="POST" action="login.php"><table align="center"><tr> <td>Username:</td><td><input type="text" name="txtusername" value="<?php if(isset($_POST['submit']) && (strlen($_POST['txtusername']) > 0 || strlen($_POST['txtusername']) < 7)) echo $_POST['txtusername']; ?>"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtusername']) < 1 || strlen($_POST['txtusername']) >6)) echo "<div id='usr-err'>Username must be 1 to 6 chars<div>"; ?></tr><tr> <td>Password:</td><td><input type="password" name="txtpassword"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtpassword']) < 1 || strlen($_POST['txtpassword']) >6)) echo "<div id='pas-err'>Password must be 1 to 6 chars<div>"; ?></tr><tr> <td>E-mail:</td><td><input type="text" name="txtemail" value="<?php if(isset($_POST['submit']) && (strlen($_POST['txtemail']) > 0 || strlen($_POST['txtemail']) < 26)) echo $_POST['txtemail']; ?>"></td><?php if(isset($_POST['submit']) && (strlen($_POST['txtemail']) < 10 || strlen($_POST['txtemail']) > 25)) echo "<div id='email-err'>Email must be at least 14 chars<div>"; ?></tr><tr> <td>You are:</td><td><input name="level_usr" type="radio" checked="checked" value="1">An Applicant <input name="level_usr" type="radio" value="2">A Company</tr> <tr><td>Remember me</td><td><input name="chkrem" type="checkbox" value="REMEMBER"></td><div id="forgot-pass"><a href="forgot_password.php">forgot password?</a></div></tr><tr> <td></td><td align="center"><input name="submit" type="submit" value="Login"> <input type="reset"></td></tr></table></form></div><?phpinclude "footer.php";?>
  12. pritam79

    Foreign Keys

    Hi all,I have the following two tables in MySQL. When I insert a record in the ‘user-usr’ table, I want the foreign key ‘idusr_com’ to get inseted in the company_com table accordingly. What is the appropriate SQL statement to do so? Do I need two queries? What happens when I need to insert foreign key values in many tables at a time?1. company_com - to store the company main information. id_com - the primary key for the company table. No two companies can have the same ID. idusr_com - a foreign key to the company's entry in the users table below. Login and access restrictions are stored there. name_com - the company's name (Amazon, Best Buy etc.) address_com - stores the company address2. user_usr - stores the user data: e-mail, password etc. id_usr - the primary key for the user table. No two users can have the same ID. password_usr - stores user password. active_usr - a boolean variable (Y/N) based on whether the user account is active or not. level_usr - either a 1 or a 0 depending on whether the user is a company or an applicant.
  13. pritam79

    Php V/s Javascript

    Hi all, My question is related to both PHP and JavaScript, and as such didn’t know the forum where to post my query.Firstly, I would like to know if JavaScript can be totally done away with from a PHP page. That is, can a site,developed entirely in PHP (minus JavaScript), perform all functions that could otherwise be performed by using JavaScript embedded into the PHP pages? Secondly, what choice does a developer have in case he does not want to include JavaScript at all in a site developed entirely in PHP? Would the exclusion of JavaScript make the site less functional? Is there anything that JavaScript can, but PHP cannot? Thanks to all,
  14. pritam79

    PHP login

    I want the scripts to do the following.1. Accept a valid username and password.2. Authenticate the user against the database and serve the ‘authormaster.php’ page if validated.3. If the REMEMBER ME option is selected on the login page, then the next time the user logs-in the server should directly serve the user with ‘authormaster.php’.4. The ‘authormaster.php’ page should allow users to do the following- a) Sign Out – brings the user back to login.php and populates the ‘username’ field with the last username used to login. Change User – allows the user to login as a different user by bringing back the login page with nothing populated in the text boxes.--- What are the changes that need to be made in order to function in the way mentioned in steps 1 to 4?????
  15. pritam79

    PHP login

    I got the code in a book. I doubt the code would work but the functioning is such that the user will first login through 'login.php', which will use the script 'setme.php' to verify if the username and password are in the database, and if so will redirect the user to 'authormaster.php'. But the script is not working.
  16. pritam79

    PHP login

    Hi all, I have the following three pages, setme.php, login.php and authormaster.php. This is login.php <?phpif($state == 'cu') { setcookie("login[username]", "", time()-360); setcookie("login[password]", "", time()-360); header('Location:login.php'); exit; }else if($state == 'so') { setcookie("login[password]", "", time()-3600); header('Location:login.php'); exit; }if(isset($_COOKIE['login']['username']) && isset($_COOKIE['login']['password'])) { header('Location:authormaster.php'); }?><html><body><form action="setme.php" method="post" name="frmLogin">Username:<input name="txtusername" type="text" value="<?php if(isset($_COOKIE['login']['username'])) echo $_COOKIE['login']['username']; ?>"><br><br>Password:<input name="txtpassword" type="password"><br><br><input name="chkrem" type="checkbox" value="REMEMBER">Remember<br><input name="submit" type="submit" value="Sign In"></form></body></html> This is setme.php <?php$result = mysql_pconnect("localhost","root","");mysql_select_db("users");$qry="SELECT * FROM Users WHERE Username='$_POST[txtusername]' AND Password='$_POST[txtpassword]'";$res=mysql_query($qry);$numrows=mysql_numrows($res);if($numrows == 1) { if($_POST['chkrem']=="REMEMBER") { setcookie("login[Username]",$_POST['txtusername'], time()+360); setcookie("login[Password]",$_POST['txtpassword'], time()+360); } header('Location:authormaster.php'); } else { $msg = "Invalid Username/Password"; header("Location:login.php?msg=".msg); }?> This is authormaster.php <html><head><title>Untitled 1</title></head><body><a href="login.php?state=so">Sign Out</a> <a href="login.php?state=cu">Change user</a></body></html> A user has to first open 'login.php' which should provide the user with textboxes to enter their username and password. But on loading login.php I do get a login form with textboxes, but along with the textboxes I also get to see errors which say-Notice: Undefined variable: state in C:\wamp\www\KKHSOU\login\login.php on line 3Notice: Undefined variable: state in C:\wamp\www\KKHSOU\login\login.php on line 11
  17. pritam79

    Form

    Hi again I have now included an ‘UPDATE’ link at the end of each displayed record on the ‘BookMasterform.php’ page like <a href="edit.php?id=<?php echo $row['BookID'];?>">EDIT</a>, and when I click any record I am also directed to a different page ‘edit.php’, which provides all the corresponding fields in individual text boxes, so that I can ‘modify’ the records and update them. But how do I proceed? I am ‘passing variables through a URL’ but I am unable to further use this option in the page where I need to modify the records. Which method would be the best, pass the variables in a URL, through a session, via a cookie, or with an HTML form?This is edit.php <body><div id="header"> <h2>BOOK MASTER</h2></div><?php require("db-connect.php");$result = db_connect();if(isset($_POST['Update'])) { echo $_GET['id']; // do updation here }elseif(!isset($_POST['Update'])) { $sql = mysql_query("SELECT * FROM bookmastertable WHERE BookID = '$_GET[id]'"); while($row = mysql_fetch_array($sql)) { $BookID = $row['BookID']; $BookName = $row['BookName']; $Synopsis = $row['Synopsis']; $AuthorName = $row['AuthorName']; $PublisherName = $row['PublisherName']; }?> <form action="edit.php" method="post"> <div id="left"> <p>Book Name:</p> <p>Synopsis:</p> <p>Author name:</p> <p>Publisher name:</p> </div> <div id="right"> <p><input type="text" name="BookName" value="<?php echo $BookName; ?>"></p> <p><input type="text" name="Synopsis" value="<?php echo $Synopsis; ?>"></p> <p><input type="text" name="AuthorName" value="<?php echo $AuthorName; ?>"></p> <p><input type="text" name="PublisherName" value="<?php echo $PublisherName; ?>"></p> <p><input type="submit" name="Update" value="Update"> <input name="reset" type="reset" value="reset"></p> </div> </form><?php}?> </body>
  18. pritam79

    Form

    Thanks, its working now..
  19. pritam79

    Form

    I have been able to modify my script, and now i just have one problem. The insertion of records, display of records and error detection for erroneous input works well. Even when I select the checkboxes and press delete button the records get deleted.The problem I am having is that in case I do not select any checkboxes and then press the ‘delete’ button, I get the error message which says “Select record(s) to delete” as expected, but I also get this error message at the top of the page which says- “Undefined index: checkbox in C:\wamp\www\MasterPG442\BookMasterform.php on line 135. This is the code..please help.<html><head><title>bookmaster form</title><style type="text/css">body { background: #fff; font-family: Arial; margin: 0 0 0; padding: 0;}div { margin: 0; padding: 0;}#header { margin-left: 225px; margin-right: 225px; text-align: center; background-color: black; font-weight: bold; font-family: Arial; color: white; height: 40px; }#left { width: 150px; height: 195px; position: absolute; background-color:silver; margin-left: 225px; margin-top:-35px; }#right { width: 680px; height: 195px; position: absolute; margin-left: 375px; background-color:silver; margin-top:-35px; }#left p { text-align: right; margin-right: 10px; padding-top: 3px;}#right p { text-align: left; margin-left: 20px; padding-top: 0px;}#list-header { width:830px; position: relative; margin-top: 160px; margin-left: 225px; height: 40px; background-color:black; }#book-list { width:830px; position: relative; margin-top: 0px; margin-left: 225px; height: 30px; background-color: silver; }.style1 { color: #FFFFFF; text-align:center; width:410px; height:40px;}.style2 { width: 350px; text-align:center; height: 10px;}#delmsg { position:absolute; margin-left:30px; margin-top:150px;}#delmsg p { color:red;} </style></head><body><div id="header"> <h2>BOOK MASTER</h2></div><?php require("db-connect.php"); $result = db_connect(); $count=mysql_num_rows($result); global $insert, $delresult; // Check if delete button active, start thisif(isset($_POST['save'])) { $allFieldRecords=TRUE; $BookName = $_POST['BookName']; $Synopsis = $_POST['Synopsis']; $AuthorName = $_POST['AuthorName']; $PublisherName = $_POST['PublisherName']; if(strlen($_POST['BookName'])==0) { $allFieldRecords=FALSE; } if(strlen($_POST['Synopsis'])==0) { $allFieldRecords=FALSE; } if(strlen($_POST['AuthorName'])==0) { $allFieldRecords=FALSE; } if(strlen($_POST['PublisherName'])==0) { $allFieldRecords=FALSE; } if($allFieldRecords==TRUE) { $result = mysql_query("INSERT into bookmastertable(BookID, BookName, Synopsis, AuthorName, PublisherName) values('', '$_POST[BookName]', '$_POST[Synopsis]', '$_POST[AuthorName]', '$_POST[PublisherName]')"); if($result) { $insert = TRUE; } } }if(isset($_POST['delete'])) { $checkboxes=$_REQUEST["checkbox"]; for($i=0; $i<count($checkboxes); $i++) { if(!(isset($checkboxes[$i]))) { $checked == FALSE; } elseif(isset($checkboxes[$i])) { $del_id = $checkboxes[$i]; $sql = "DELETE FROM bookmastertable WHERE BookID='$del_id'"; $delresult = mysql_query($sql); } } }?><form action="BookMasterform.php" method="post"> <div id="left"> <p>Book Name:</p> <p>Synopsis:</p> <p>Author name:</p> <p>Publisher name:</p> </div> <div id="right"> <p><input type="text" name="BookName" value="<?php if($insert) echo ''; elseif(isset($_POST['BookName'])) echo $_POST['BookName']; ?>"><?php if(isset($_POST['save']) && strlen($_POST['BookName'])==0) echo "<font color=red>Book Name cannot be empty.</font>"; ?></p> <p><input type="text" name="Synopsis" value="<?php if($insert) echo ''; elseif(isset($_POST['Synopsis'])) echo $_POST['Synopsis']; ?>"><?php if(isset($_POST['save']) && strlen($_POST['Synopsis'])==0) echo "<font color=red>Synopsis cannot be empty.</font>"; ?></p> <p><input type="text" name="AuthorName" value="<?php if($insert) echo ''; elseif(isset($_POST['AuthorName'])) echo $_POST['AuthorName']; ?>"><?php if(isset($_POST['save']) && strlen($_POST['AuthorName'])==0) echo "<font color=red>Author Name cannot be empty.</font>"; ?></p> <p><input type="text" name="PublisherName" value="<?php if($insert) echo ''; elseif(isset($_POST['PublisherName'])) echo $_POST['PublisherName']; ?>"><?php if(isset($_POST['save']) && strlen($_POST['PublisherName'])==0) echo "<font color=red>Publisher Name cannot be empty</font>"; ?></p> <p><input type="submit" name="save" value="Save"> <input name="reset" type="reset" value="reset"></p> </div> </form><div id="delmsg"><?php if(isset($_POST['delete']) && $delresult==FALSE) echo "<p>Select record(s) to delete</p>"; ?></div> <form method="post" action="BookMasterform.php"> <div id="list-header"> <table width="830px" align="center" height="40px"> <tr> <td style="width: 80px" align="left"> <input name="delete" type="submit" id="delete" value="Delete" style="width: 50px"></td> <td class="style1"><b>BOOK NAME</b></td> <td class="style1"><b>SYNOPSIS</b></td> <td class="style1"><b>AUTHOR NAME</b></td> <td class="style1"><b>PUBLISHER NAME</b></td> <td style="width: 80px" align="center"> <input name="edit" type="submit" id="edit" value="Edit" style="width: 50px"></td> </tr> </table> </div> <?php $result = mysql_query("SELECT * FROM bookmastertable ORDER BY BookID"); while($row = mysql_fetch_array($result)) { $BookName = $row['BookName']; $Synopsis = $row['Synopsis']; $AuthorName = $row['AuthorName']; $PublisherName = $row['PublisherName'];?> <div id="book-list"> <table width="830px" align="center" bgcolor="silver"> <tr><td width="70px" bgcolor="black" align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['BookID']; ?>"></td> <td class="style2"><?php echo $BookName; ?></td> <td class="style2"><?php echo $Synopsis; ?></td> <td class="style2"><?php echo $AuthorName; ?></td> <td class="style2"><?php echo $PublisherName; ?></td> <td width="70px" bgcolor="black" align="center"><input name="Radio" type="radio" checked="checked" value="<?php echo $row['BookID']; ?>"></td></tr> </table> </div> <?php }?></form></body></html>
  20. pritam79

    Form

    I am done with my insertion error handling. Now I am trying to include error handling for the delete button. When I select the checkboxes corresponding to the records that I need to delete, they get deleted properly from the database as well as from the page where the records are displayed. But in case I donot select any of the checkboxes and click on the delete button, I get an error message which says- Notice: Undefined index: checkbox in C:\wamp\www\BookMasterform.php on line 140.I want an error message which says- "No records selected"..The following is the code for the delete button.<?php if(isset($_POST['delete'])) { $checkboxes=$_REQUEST["checkbox"]; for($i=0; $i<count($checkboxes); $i++) { if(isset($checkboxes[$i])) { $del_id = $checkboxes[$i]; $sql = "DELETE FROM bookmastertable WHERE BookID='$del_id'"; $result = mysql_query($sql); } } } $result = mysql_query("SELECT * FROM bookmastertable ORDER BY BookID"); while($row = mysql_fetch_array($result)) { $BookName = $row['BookName']; $Synopsis = $row['Synopsis']; $AuthorName = $row['AuthorName']; $PublisherName = $row['PublisherName'];?> <div id="list"> <table> <tr><td width="70px" bgcolor="black"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['BookID']; ?>"></td> <td class="style2"><?php echo $BookName; ?></td> <td class="style2"><?php echo $Synopsis; ?></td> <td class="style2"><?php echo $AuthorName; ?></td> <td class="style2"><?php echo $PublisherName; ?></td></tr> </table> </div><?php }?>
  21. pritam79

    Form

    How do I RESET the fields after inserting the data in MySql then?
  22. pritam79

    Form

    I have this form that submits to itself and the data inserted into the fields get displayed on the same page below the form. but I am having problems-When the input boxes are filled with correct data and I click the Save button, the data gets inserted in MySQL, but the form input fields do not get emptied automatically. I have to clear each record from the input fields manually and even the Reset button doesnot work. But the reset button works well only in case the page loads in localhost for the very first time, i.e before submitting any data for the very first time.I don't want to use JavaScript for validation. But I am not able to do everything in PHP either. Is there no way to do this in PHP, and use JavaScript? <body><div id="header"> <h2>BOOK MASTER</h2></div><?php $result = mysql_pconnect("localhost","root",""); if(!$result) { echo "Could not connect to database server"; exit; } mysql_select_db("bookmaster"); $result = mysql_query("SELECT * FROM bookmastertable"); $count=mysql_num_rows($result); // Check if delete button active, start thisif(isset($_POST['delete'])) { $checkboxes=$_REQUEST["checkbox"]; for($i=0; $i<count($checkboxes); $i++) { if(isset($checkboxes[$i])) { $del_id = $checkboxes[$i]; $sql = "DELETE FROM bookmastertable WHERE BookID='$del_id'"; $result = mysql_query($sql); } } }?> <?php $result = mysql_pconnect("localhost","root",""); if(!$result) { echo "Could not connect to database server"; exit; } mysql_select_db("bookmaster"); $result = mysql_query("SELECT * FROM bookmastertable"); if(isset($_POST['save'])) { $allFieldRecords=TRUE; $BookName = $_POST['BookName']; $Synopsis = $_POST['Synopsis']; $AuthorName = $_POST['AuthorName']; $PublisherName = $_POST['PublisherName']; if(strlen($_POST['BookName'])==0) { $allFieldRecords=FALSE; } if(strlen($_POST['Synopsis'])==0) { $allFieldRecords=FALSE; } if(strlen($_POST['AuthorName'])==0) { $allFieldRecords=FALSE; } if(strlen($_POST['PublisherName'])==0) { $allFieldRecords=FALSE; } if($allFieldRecords==TRUE) { $result = mysql_query("INSERT into bookmastertable(BookID, BookName, Synopsis, AuthorName, PublisherName) values('', '$_POST[BookName]', '$_POST[Synopsis]', '$_POST[AuthorName]', '$_POST[PublisherName]')"); } }?> <form action="BookMasterform.php" method="post"> <div id="left"> <p>Book Name:</p> <p>Synopsis:</p> <p>Author name:</p> <p>Publisher name:</p> </div> <div id="right" style="left: 0px; top: 0px"> <p><input type="text" name="BookName" value="<?php if(isset($_POST['BookName'])) echo $_POST['BookName']; ?>"><?php if(isset($_POST['save']) && strlen($_POST['BookName'])==0) echo "<font color=red>Book Name cannot be empty.</font>"; ?></p> <p><input type="text" name="Synopsis" value="<?php if(isset($_POST['Synopsis'])) echo $_POST['Synopsis']; ?>"><?php if(isset($_POST['save']) && strlen($_POST['Synopsis'])==0) echo "<font color=red>Synopsis cannot be empty.</font>"; ?></p> <p><input type="text" name="AuthorName" value="<?php if(isset($_POST['AuthorName'])) echo $_POST['AuthorName']; ?>"><?php if(isset($_POST['save']) && strlen($_POST['AuthorName'])==0) echo "<font color=red>Author Name cannot be empty.</font>"; ?></p> <p><input type="text" name="PublisherName" value="<?php if(isset($_POST['PublisherName'])) echo $_POST['PublisherName']; ?>"><?php if(isset($_POST['save']) && strlen($_POST['PublisherName'])==0) echo "<font color=red>Publisher Name cannot be empty</font>"; ?></p> <p><input type="submit" name="save" value="Save"> <input name="reset" type="reset" value="reset"></p> </div> </form><form method="post" action="BookMasterform.php"><div id="list"> <table> <tr> <td style="width: 80px" bgcolor="black"> <input name="delete" type="submit" id="delete" value="Delete" style="width: 54px"></td> <td class="style1"><b>BOOK NAME</b></td> <td class="style1"><b>SYNOPSIS</b></td> <td class="style1"><b>AUTHOR NAME</b></td> <td class="style1"><b>PUBLISHER NAME</b></td> </tr> </table></div><?php $result = mysql_query("SELECT * FROM bookmastertable ORDER BY BookID"); while($row = mysql_fetch_array($result)) { $BookName = $row['BookName']; $Synopsis = $row['Synopsis']; $AuthorName = $row['AuthorName']; $PublisherName = $row['PublisherName'];?> <div id="list"> <table> <tr><td width="70px" bgcolor="black"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['BookID']; ?>"></td> <td class="style2"><?php echo $BookName; ?></td> <td class="style2"><?php echo $Synopsis; ?></td> <td class="style2"><?php echo $AuthorName; ?></td> <td class="style2"><?php echo $PublisherName; ?></td></tr> </table> </div><?php }?></form> </body>
  23. pritam79

    Form

    Hi all, I have a PHP page where I have included two submit buttons. Before processing with the code associated with any of the two submit buttons I have to check as to which one gets clicked. How do I determine as to which one of the two is clicked?Hi all, I have a PHP page where I have included two submit buttons. One is for inserting data into MySQL and one is for deleting data displayed one that same page using checkboxes. With the code that I have the insertion and display of all the data along with checkboxes is working well. But the thing that I am not able to do is the deletion part. I have included everything in a single php page that posts to itself. <form action="BookMasterform.php" method="post"><table style="width: 100%; height: 151px" class="style1"> <tr> <td style="width: 210px; height: 37px" class="style2">Book Name:</td> <td style="height: 37px"> <input type="text" name="BookName" style="width: 210px"></td> </tr> <tr> <td style="width: 210px; height: 38px" class="style2">Synopsis:</td> <td style="height: 38px"> <input type="text" name="Synopsis" style="width: 300px"></td> </tr> <tr> <td style="width: 210px; height: 38px" class="style2">Author Name:</td> <td style="height: 38px"> <input type="text" name="AuthorName" style="width: 297px"></td> </tr> <tr> <td style="width: 210px; height: 38px" class="style2">Publisher Name:</td> <td style="height: 38px"><input type="text" name="PublisherName"></td> </tr> <tr> <td style="width: 210px; height: 22px" class="style2"></td> <td style="height: 22px" align="right"><input type="submit" name="save" value="Save"> <input type="reset" value="Clear"></td> </tr> </table></form></div><form method="post" action="BookMasterform.php"><div id="list"><table><tr> <td class="style3" style="width: 147px"> <input name="delete" type="submit" id="delete" value="Delete" style="width: 54px"></td> <td class="style3" style="width: 353px">Book Name</td> <td class="style3" style="width: 403px">Synopsis</td> <td class="style3" style="width: 467px">Author Name</td> <td class="style3" style="width: 416px">Publisher Name</td></tr></table></div><?php $result = mysql_pconnect("localhost","root",""); if(!$result) { echo "Could not connect to database server"; exit; } mysql_select_db("bookmaster"); $result = mysql_query("SELECT * FROM bookmastertable");// if ok put in db if(isset($_POST['save'])) { $result = mysql_query("INSERT into bookmastertable(BookID, BookName, Synopsis, AuthorName, PublisherName) values('', '$_POST[BookName]', '$_POST[Synopsis]', '$_POST[AuthorName]', '$_POST[PublisherName]')"); } $result = mysql_query("SELECT * FROM bookmastertable"); while($row = mysql_fetch_array($result)) { $BookName = $row['BookName']; $Synopsis = $row['Synopsis']; $AuthorName = $row['AuthorName']; $PublisherName = $row['PublisherName']; ?> <div id="list"> <table> <tr><td class="style4" style="width: 100px"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['BookID']; ?>"></td> <td class="style4" style="width: 353px"><?php echo $BookName; ?></td> <td class="style4" style="width: 403px"><?php echo $Synopsis; ?></td> <td class="style4" style="width: 467px"><?php echo $AuthorName; ?></td> <td class="style4" style="width: 416px"><?php echo $PublisherName; ?></td></tr> </table> </div> <?php } ?><?php $result = mysql_pconnect("localhost","root",""); if(!$result) { echo "Could not connect to database server"; exit; } mysql_select_db("bookmaster"); $result = mysql_query("SELECT * FROM bookmastertable"); $count=mysql_num_rows($result); // Check if delete button active, start thisif(isset($_POST['delete'])){ for($i=0;$i<$count;$i++) { $del_id = $checkbox[$i]; $sql = "DELETE FROM bookmaster WHERE BookID='$del_id'"; $result = mysql_query($sql); }}?> </form></body></html>
  24. pritam79

    CS5 vs CS3

    someone plz reply.... :-(
  25. pritam79

    CS5 vs CS3

    I am using flash CS5 now. I am already accustomed to using flash CS3, but I find a lot of difference among the two (as far as finding commands and options in CS5 is concerned). Are there major differences among the two? I also need some tutorial for CS5, because the w3 tutorials here are for the CS3 version I guess, because when I go through the tutorials of w3 and try to implement those in CS5, its difficult to find a counterpart for the CS3 tools in CS5.
×
×
  • Create New...