Forum Moderators: coopster

Message Too Old, No Replies

Re: PHP

I am unable to insert the data into the database

         

uxkarnati

4:47 pm on Jul 17, 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");

?>

andrewsmd

6:05 pm on Jul 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try this
$sql = "INSERT INTO req (req_user_name, req_applicant, req_user_email) VALUES ('{$username}', $appid, '{$useremail}');";

Another tip, a good way to debug is to echo your query like this
echo($sql); copy and paste that into a command query in your database and see if it works. I cannot tell you how many times I have had an error in the way wrote my query and not the code. You'll notice I put {} around variables in '' but also I put an extra ; in the string because you need your query to have a semicolon in it. Let me know if you need anymore help.

uxkarnati

8:22 pm on Jul 17, 2009 (gmt 0)

10+ Year Member



I can insert the appid but still I can't insert the username and useremail.In database table in appid it is showing the number and it is showing blank in the username and useremail.

andrewsmd

8:31 pm on Jul 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aha, that's why echoing things help because now you have isolated the problem. When I do a var_dump($_SERVER['REMOTE_USER']); I get string = "" what do you get when you do that? what do you want username and useremail to be.

uxkarnati

8:44 pm on Jul 17, 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 table..

andrewsmd

9:43 pm on Jul 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well if you have the users stored in a table, then getting the usernames and emails would be in that table correct? I'm not for sure what you are doing with $logininfo = explode("\\",$_SERVER['REMOTE_USER']);
If those users are stored in a table, then you have to query that table to get the user information and display it. Am I missing something here? Where did you find the information that made you think you need $_SERVER['REMOTE_USER']); maybe I'm misunderstanding something.

uxkarnati

10:01 pm on Jul 17, 2009 (gmt 0)

10+ Year Member



I referred the previous code written by some one in my school and I wrote it.but i don;t know why the data is not string in the database.I think the Query I used to insert the data is correct It becoming difficult for me what's the actual mistake is....