Re: Adding a new entry using PHP
| From: | Justin Patrin | Date: | Thu, 08 Apr 2004 00:43:53 +0000 |
| Subject: | Re: Adding a new entry using PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182761@lists.php.net to get a copy of this message | ||
Alistair Hayward wrote:
Hi,
I am an ASP user, now learning PHP.
When adding a record in ASP, I do this:
Recordset.AddNew
Field1 = whatever
RecordSet.Update
How is this done in PHP?
I have built a recordset using a query, and have all the information needed to go into the different fields, but how do I 'Edit' or 'AddNew' and 'Update'?
This is what I have:
<?php
unset($price);
$price = $_GET['Price'];
unset($id);
$id = $_GET['id'];
unset($partnumber);
$partnumber = $_GET['PartNumber'];
unset($disc);
$disc = $_GET['Disc'];
$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("order", $link);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$sql= "SELECT * FROM tborder WHERE sid='session.sessionid'";
$result = mysql_query($sql);
$total_records = mysql_num_rows($result);
?>
You need to do mysql_fetch_array() or associated methods to actually get your data back.
To update, use the UPDATE SQL syntax. To insert, use INSERT.
If you want a recordset, there are various packages in PEAR which might satisfy your needs.
http://pear.php.net
--
paperCrane <Justin Patrin>