Forum Moderators: coopster
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
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!
<?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