Page 1 of 1

ODBC insert query

Posted: Tue Apr 26, 2005 11:34 am
by rayner75
Hello i am using ODBC to connect my access database to my website, i have everything set up ok, because i have performed a query and can access information,

I am trying to add a new user, into my User table, i have a form called join.htm and the action points to newuser.php
I get the information from each field and run this query

Code: Select all

<?php
$surname = $_POST['surname'];
$forename = $_POST['forename'];
$houseNo = $_POST['houseNo'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$telephone = $_POST['telephone'];
$username = $_POST['username'];
$password = $_POST['password'];

require_once('odbc.php');
$query = "INSERT INTO User (Surname, Forename, House name/number,Address1,Address2,County,Post Code,tel) ".
	  "values ('$surname','$forename','$houseNo','$address','$address2','$county','$postcode','$telephone')";

odbc_exec($odbc, $query) or die (odbc_errormsg());
?>
I know i havent done any validation but i thought this query would work, i have an id which in my table is an autonumber so i thought it would automatically create an id for this recordset.

Am i doing something wrong?
Regards
Andy


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Wed Apr 27, 2005 12:43 am
by n00b Saibot
what error message does odbc_errormsg() prints out :?:

Posted: Wed Apr 27, 2005 5:53 am
by rayner75
i got this sorted thank, i needed to change the names of House Number/name and Post Code to one word and it seemed to work

I have one more little question if you dont mind
I am trying to delete a row from a table using
DELETE FROM tour Where TOUR_CODE = 5;

But i get this

ERROR at line 1:
ORA-02292: integrity constraint (C3042575.TOURLEG_TOUR_FK) violated - child
record found

so i try to do this

DELETE FROM tour Where TOUR_CODE = 5 CASCADE CONSTRAINTS;

and it wont let me
am i doing anything wrong?

Posted: Wed Apr 27, 2005 6:29 am
by n00b Saibot
use the 'ALTER TABLE' on the child table to add the following constraint on the referencing field > 'ON DELETE CASCADE'.

Posted: Wed Apr 27, 2005 9:42 am
by rayner75
im not too sure i understand how would i use the alter table?

Posted: Wed Apr 27, 2005 10:26 am
by n00b Saibot
See Here for usage of 'ALTER TABLE' in ORACLE :arrow: ORACLE SQL Reference