Forum Moderators: coopster

Message Too Old, No Replies

MS Access and php- insert row in a table

         

rekhad

12:02 pm on Feb 21, 2006 (gmt 0)

10+ Year Member



I am not able to insert a row through a form in my database which is in Access.Please see my code below and help..Select works O.K. but inserting through form is a problem.
This is form1.php.here I am inserting the values.This form has action process.php.
<?php
echo"
<html>

<form name=\"AccessInterface\" action=\"process.php\" method=post>
DoctorsID:<input name=\"DoctorsID\" type=\"text\" size=\"25\" ><br>
Organization:<input name=\"Organization\" type=\"text\" size=\"25\" ><br>
password:<input name=\"password\" type=\"text\" size=\"25\" ><br>
<input type=Submit value=\"insert\">
</form>
</html>
";
?>

THIS IS "PROCESS.PHP"

<html>
<?php
$cn=odbc_connect('doctordb','root',' ');
echo"connected";
if(!$cn)
Error_handler("nop connection",$cn);

$query="Select * from Table1";
$cr=odbc_exec($cn,$query);
$nbrow=0;
while( odbc_fetch_row( $cr )) {
$nbrow++;

echo"<tr><th>DoctorsID</th><th>Organization</th><th>password</th></tr>\n";
$DoctorsID=odbc_result($cr,1);
$Organization=odbc_result($cr,2);
$password=odbc_result($cr,3);
echo"<tr><td>$DoctorsID</td><td>$Organization</td><td>$password</td></tr>\n";
}
odbc_close($cn);
exit();
$cn=odbc_connect('doctordb','root',' ');
$query1="Insert into Table1 values('$DoctorsID','$Organization','$password')";
$cr1=odbc_exec($cn,$query1);
odbc_close($cn);
?>
</html>

rekhad

1:30 am on Feb 22, 2006 (gmt 0)

10+ Year Member



where are the smart guys I need help?
I saw somewhere that we need to set the register_global in php.ini to ON
I did that but still i am not able to insert a row in my db using form

please reply..

jatar_k

3:00 am on Feb 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



as opposed to turning register_globals on, which has some serious security implications, just use the $_POST superglobal array

instead of this
$query1="Insert into Table1 values('$DoctorsID','$Organization','$password')";

try it like so
$query1="Insert into Table1 values('" . $_POST['DoctorsID'] . "','" . $_POST['Organization'] . "','" . $_POST['password'] . "')";

rekhad

2:31 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



NO its not working I turned register_GLOBALS to off.
And changed my query statement to
$query1="Insert into Table1 values('" . $_POST['DoctorsID'] . "','" . $_POST['Organization'] . "','" . $_POST['password'] . "')";

But no row is inserted in my table..
I am trying this since long ...I dont know whats wrong here?

rekhad

3:05 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



If I keep my query as

$query1="Insert Into People (DoctorsID, Organization, password)Values('$DoctorsID', '$Organization', '$password')";

with register_global OFF
I get an empty row inserted in my table?

with the following messages
Notice: Undefined variable: DoctorsID in c:\program files\easyphp1-8\www\process.php on line 95

Notice: Undefined variable: Organization in c:\program files\easyphp1-8\www\process.php on line 95

Notice: Undefined variable: password in c:\program files\easyphp1-8\www\process.php on line 95

please help me ..

inveni0

3:20 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



Try:

$query1="Insert Into People (DoctorsID, Organization, password)Values($_POST['$DoctorsID'], $_POST['$Organization'], $_POST['$password'])";

rekhad

5:24 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



I have tried that.It doesn't work. Infact in all my programs I am facing the same problem .I am not able to get the values of the variables
Look at the simple form feed back.This also doesn't work I am very frustrated why its happening?

<html>
<head>
<title>feedback form</title>
</head>
<body>
<?php

if(strlen($_POST['name']>0)){
$_POST['name']=stripslashes($_POST['name']);
}
else{
$name=NULL;
echo "<p><br>Please enter your name</br></p>";
}

if($_POST['name'] ){
echo "Thank you, <b>$name</b>";
}
?>
</body>
</html>

I get the out put as

Please enter your name
Thank you

rekhad

7:32 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



help please..

jatar_k

8:25 pm on Feb 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try this then to take a look at what is being posted

place these lines in the script that your form is posting to

echo '<p>vars from POST array:<pre>';
print_r($_POST);
echo '</pre>';