Forum Moderators: coopster

Message Too Old, No Replies

PHP with MS Access database problem

PHP, MS, Access, database

         

harley1979

11:23 pm on Feb 26, 2007 (gmt 0)

10+ Year Member



Hi,

I am new to PHP, previously I have always programed in ASP. My syntax is suffering slightly with my PHP and I was wondering if someone could please help.

I am running a MS Access database with my PHP pages for the moment until I can figure out MySQL.

I seem to be able to use SELECT from my SQL statements fine, but INSERT or UPDATE is proving a little difficult. Here is my code:

<body>
<p>Your news item has successfully been added</p>
<?php
$date = date('M j, Y');
$title = $_REQUEST['title'];
$newsitem = $_REQUEST['newsitem'];

$sql = "INSERT INTO newsblog (date, title, news) VALUES ('$date', '$title', '$newsitem')";
$conn->Execute($sql);
?>
</body>
</html>
<?php require_once('../includes/close-connection.php');?>

The variables I am passing from my forms pick up perfectly well, I am assuming the problem is something to do with how you execute the SQL statement.

It is giving me this error message:

Fatal error: Call to a member function Execute() on a non-object in ..\..\..\news_add_insert.php on line 18

I know that it is probably just something silly I am missing, please can someone point me in the right direction?

Thanks

eelixduppy

3:34 am on Feb 27, 2007 (gmt 0)



Welcome to WebmasterWorld, harley1979!

I don't actually see where you define the $conn object. I believe this is the problem; you either didn't initiate the object correctly or it is out of scope, something along those lines. Can you please show us how you are defining this as this may be the problem? :)


until I can figure out MySQL

If you need some help with mysql, there are many great threads in our library [webmasterworld.com] that address the issue:

Good luck!

harley1979

12:35 pm on Feb 27, 2007 (gmt 0)

10+ Year Member



Sorry, yeah I should have been more clear with my code. Here is the code again,

<?php
$conn=odbc_connect('sssdb','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
?>

</head>
<body>
<h1>Short Sharp Shock</h1>
<h2>Add news</h2>
<p>Your news item has successfully been added</p>
<?php
$date = date('M j, Y');
$title = $_REQUEST['title'];
$newsitem = $_REQUEST['newsitem'];

$sql = "INSERT INTO newsblog (date, title, news) VALUES ('$date', '$title', '$newsitem')";
$conn->Execute($sql);
?>
</body>
</html>
<?php odbc_close($conn);?>

I am actually using includes to open and close the database but for the purpose of this message I have just copied in the code.

Hope that sheds some light

Birdman

4:02 pm on Feb 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try switching this line:

$conn->Execute($sql);

with:

$result = odbc_exec($sql);
if (!$result) {exit('Execution failed!');}

harley1979

9:01 pm on Feb 27, 2007 (gmt 0)

10+ Year Member



Thank you very much! You're a star...