Re: Is my Hosting service full of it?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux