Topic: need some help with writing to database (Read 617 times)
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« on: Jan 13, 2006, 07:00:52 PM »
problem with this code is that it only writes the url, title, and short_desc to the database, it wont write the category(s) when selected.
Code:
<?php include('submit/config.php'); $include_dir = "include"; $settings_dir = "settings"; $template_dir = "templates"; include "$settings_dir/conf.php"; include "$include_dir/commonfuncs.php"; if ($_POST[submit]) { // the above line checks to see if the html form has been submitted $url = $_POST[url]; $title = $_POST[title]; $short_desc = $_POST[short_desc];
//the above lines set variables with the user submitted information if($url==NULL|$title==NULL|$short_desc==NULL) { //checks to make sure no fields were left blank echo "A field was left blank."; }else{ $query = mysql_query("INSERT INTO sites (url, title, short_desc) VALUES('$url','$title','$short_desc')"); // inserts the information into the database. echo "You have successfully submitted your site to the Leet Link directory. Your site will appear automatically after we pick a category based on the content of your site. We will index your site as soon as possible, please make sure you have a sitemap.xml file and robots.txt file for the best possible index of your site!"; } } else { // the form has not been submitted...so now we display it.
function addsite ($url, $title, $short_desc, $cat) { global $mysql_table_prefix; $short_desc = addslashes($short_desc); $title = addslashes($title); $compurl=parse_url("".$url); if ($compurl['path']=='') $url=$url."/"; $result = mysql_query("select site_ID from sites where url='$url'"); echo mysql_error(); $rows = mysql_numrows($result); if ($rows==0 ) { mysql_query("INSERT INTO sites (url, title, short_desc) VALUES ('$url', '$title', '$short_desc')"); echo mysql_error(); $result = mysql_query("select site_ID from sites where url='$url'"); echo mysql_error(); $row = mysql_fetch_row($result); $site_id = $row[0]; $result=mysql_query("select category_id from categories"); echo mysql_error(); while ($row=mysql_fetch_row($result)) { $cat_id=$row[0]; if ($cat[$cat_id]=='on') { mysql_query("INSERT INTO site_category (site_id, category_id) values ('$site_id', '$cat_id')"); echo mysql_error(); } } If (!mysql_error()){ $message = "<br/><center><b>Site added</b></center>" ; } else { $message = mysql_error(); }
} else { $message = "<center><b>Site already in database</b></center>"; } return $message; } function walk_through_cats($parent, $lev, $site_id) { global $mysql_table_prefix; $space = ""; for ($x = 0; $x < $lev; $x++) $space .= " ";
$query = "SELECT * FROM categories WHERE parent_num=$parent ORDER BY category"; $result = mysql_query($query); echo mysql_error(); if (mysql_num_rows($result) <> '') while ($row = mysql_fetch_array($result)) { $id = $row['category_id']; $cat = $row['category']; $state = ''; if ($site_id <> '') { $result2 = mysql_query("select * from site_category where site_id=$site_id and category_id=$id"); echo mysql_error(); $rows = mysql_num_rows($result2);