Jump to content

pritam79

Members
  • Content Count

    92
  • Joined

  • Last visited

Community Reputation

1 Neutral

About pritam79

  • Rank
    Newbie
  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.
×
×
  • Create New...