Forum Moderators: coopster

Message Too Old, No Replies

Help in inserting the data

         

uxkarnati

6:25 pm on Jul 21, 2009 (gmt 0)

10+ Year Member



Hi,
I am a beginner in PHP. I am unable to insert the data in to the database.Can anyone Help me..
My code is..

// Error Reporting is ON !
error_reporting(E_ALL^E_NOTICE);
ini_set('display_errors', '1');

// Initialize the DB Connection

$logininfo = explode("\\",$_SERVER['REMOTE_USER']);
$domainname = $logininfo[0];
$username = $logininfo[1];

$con = new COM("ADODB.Connection");
$rs = new COM("ADODB.Recordset");
$conn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:/data/gradschool/ga.mdb"; //".realpath("../ga.mdb");
$con->open($conn);

$appid = $_GET['appid'];

$sql = "UPDATE APP SET app_assigned='1' WHERE app_id=$appid";

$rs = $con->Execute($sql);

$sql = "INSERT INTO req (req_user_name, req_applicant, req_user_email) VALUES ('$username', $appid, '$useremail')";
$rs = $con->Execute($sql);

include("aas_list_req.php");

?>
Can any one help me plz...

andrewsmd

7:13 pm on Jul 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First what error are you getting? Second echo your sql query and insert it into the database manually and see if it works. ie.e echo($sql); Take that output and paste it into the sql interface of whatever version of access your using. Also, you may want to var_dump your $con $rs and $conn (probably not good naming convention to have con and conn it could mess you up later). Make sure they are accessing the database correctly.

uxkarnati

3:25 pm on Jul 22, 2009 (gmt 0)

10+ Year Member



I am not getting any error but the values are not inserting in to the database only appid is inserted and the username,useremail are not inserted.

I tried by giving manual values at the username and useremail it worked it inserted all the values.But its not working with the format that i given in the code.

I think the error may be this..I am extracting the values from the two tables,appid from one table and username,useremail from other table.Can't we extract the values more than one table.Is it correct......? If this is the problem how can i extract the values from the two tables

andrewsmd

3:48 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Executing from two tables should not be an issue. Do a var_dump on $username and see if it has a value. Also, you are trying to inserter $useremail, but I don't ever see where you give it a value. My guess is, neither are inserting anything because they are not any value. I'll bet they are but blank and thus are inserting correctly just inserting ''. That is why I mentioned echoing your query from the code to see exactly what it is executing.

uxkarnati

4:48 pm on Jul 22, 2009 (gmt 0)

10+ Year Member



yup the username and useremail are inserting but they are blank.I mean it I already specified that only appid is inserting but the username is not inserting i mean it is blank.How can I solve this problem I really don't have any Idea....Plz Help Me..

andrewsmd

5:03 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



They are blank because you haven't given them a value. Right now, you don't even define useremail until you put it in the insert query. You need to pull whatever email you want to send. Do this
$username = "testUsername";
$useremail = "testEmail";
$sql = "INSERT INTO req (req_user_name, req_applicant, req_user_email) VALUES ('$username', $appid, '$useremail')";
That will insert those values in for you. You need to give them whatever value they are supposed to be.

uxkarnati

5:48 pm on Jul 22, 2009 (gmt 0)

10+ Year Member



<?php

// Error Reporting is ON !
error_reporting(E_ALL^E_NOTICE);
ini_set('display_errors', '1');

// Initialize the DB Connection

$logininfo = explode("\\",$_SERVER['REMOTE_USER']);
$domainname = $logininfo[0];
$username = $logininfo[1];

$con = new COM("ADODB.Connection");
$rs = new COM("ADODB.Recordset");
$conn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:/data/gradschool/ga.mdb"; //".realpath("../ga.mdb");
$con->open($conn);

$username = $_GET['username'];
$appid = $_GET['appid'];

$sql = "UPDATE APP SET app_assigned='1' WHERE app_id=$appid";

$rs = $con->Execute($sql);

$sql = "INSERT INTO req (req_user_name, req_applicant) VALUES ('$username', $appid)";
$rs = $con->Execute($sql);

include("aas_list_req.php");

?>
I changed the code but still I am not able to insert the values.How can I pull the usernames in to this table.I want to pull the username from the list of users in the table.In this code username should be pulled from the list

uxkarnati

5:49 pm on Jul 22, 2009 (gmt 0)

10+ Year Member



what's the format for pulling the data..

uxkarnati

5:55 pm on Jul 22, 2009 (gmt 0)

10+ Year Member



Actually what i need is there are list of people who applied by filling a form.Now there are some users who can see the people that applied and they select the particular one.

When they selects, the user who selected and the mail and the applied # of the one who filled the form should store into a table.

I have a table with the users who can see the applied people.I want to get the username and email from that table.AppId from the table who filled the form.
If you want I can send you the tables..

andrewsmd

6:09 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to make sure that you are even getting the data you want before you run your insert command. I don't think your problem is your insert command, your problem is you are not getting the correct data for $username to begin with.

uxkarnati

6:38 pm on Jul 22, 2009 (gmt 0)

10+ Year Member



yes,I too think that may be the problem. How can I know that whether i am getting the data or not.Can you tell me how to do it.I use Dreamweaver for writing the code.

andrewsmd

7:56 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's your first problem, your using dreamweaver for server side code. That's a big no no to most back end developers. From what I can see you have this
$username = $logininfo[1]; Now I don't know how much you know about programming so I'm going to go in depth.
$logininfo[1]; tells us that logininfo is an array. If you don't know what arrays are then let me know.
Since it is an array, I'm guessing that there is nothing in that sub. You are setting username = to it but it is blank. Hence why it is inserting blank things into your db. You need to find out where your username is located. Is it in a db, a session variable? Once you have found your username, then you can assign it to $username. Also, $useremail is never defined throughout your page unless you have more code your not posting. You need to find out where the useremail is located and then you can assign that to $useremail. You may benefit from a consulting service of some kind, it doesn't sound like you have a whole lot of experience with PHP.