Re: Is my Hosting service full of it?
| From: | pthes | Date: | Sun, 09 Feb 2003 16:42:03 +0000 |
| Subject: | Re: Is my Hosting service full of it? | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-25529@lists.php.net to get a copy of this message | ||
Thanks for the comments,. I'm putting some code here to hopefully get an
idea of what is considered inefficient when dealing with mysql. I'm confused
because all I'm doing is collecting the data from a form and writing it to
the db. I have about 30 pages in the survey, so a script similar to this is
called after each page.
<?php
session_start();
include("loginfile.inc");
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$intable = "tablename";
/* this is the duplicate check section */
$sql = "SELECT * FROM $intable WHERE datein = '$datein' AND
itemID='$itemID'
";
$mysql_result = mysql_query($sql,$connection);
$num_rows = mysql_num_rows($mysql_result);
if ($num_rows == 0) {
/* insert if no dupes */
$query = "INSERT INTO itemsread (itemread,itemID,datein) VALUES
('$itemread','$itemID','$datein')";
$result = mysql_query($query);
}
else
{
/* update if existing timestamp */
$query = "UPDATE $intable SET itemread='$itemread' WHERE datein='$datein'
AND itemID='$itemID' ";
$result = mysql_query($query);
} # end else
mysql_close($connection);
It seems pretty simple to me. What am I missing?