Jump to content


Problem


1 reply to this topic

#1 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 21 July 2005 - 01:01 PM

Okay I have been pulling out my hair for a wile trying to figure this out so I decided to ask you guys. Okay I am working a tutorials script and I am trying to make it so that when the user submits the script, if they have the avatar typed in it will show it but if they don't it will show the default one. Here is a part of the script:

	if($_POST)
	{
  if((!$tut_name) || (!$tut_discription) || (!$site_homepage) || (!$tut_page))
  {
 	 echo 'Please go back and fill out everything. (You do not have to fill out avatar)';
  }
  else
  {
 	 if((!$avatar_link))
 	 {
    require ('config.php');
    $result = mysql_query("SELECT * FROM ". $table_prefix ."_categories ORDER BY ID ASC");
    while($row = mysql_fetch_array($result))
    {
   	 $menu = $_POST['menu'];
   	 $name = $_POST['tut_name'];
   	 $category = $_POST['select'];
   	 $tutorial_description = $_POST['tut_description'];
   	 $site_homepage = $_POST['site_homepage'];
   	 $tut_page = $_POST['tut_page'];
   	 $avatar_link = $row['avatar'];
    }
    require('config.php');
    mysql_query("INSERT INTO ". $table_prefix ."_tutorials (name, category, date, descrip, url2, url, previews, active)
    VALUES('$name', '$cateogry', now(), '$tutorial_discription', '$site_homepage', '$tut_page', '$avatar_link', '0')")or die (mysql_error());
    echo 'Thank you, your tutorial has been submited. If your tutorial is not on in 7 days it has been declined';
 	 }
 	 else
 	 {
    $menu = $_POST['menu'];
    $name = $_POST['tut_name'];
    $category = $_POST['select'];
    $tutorial_description = $_POST['tut_description'];
    $site_homepage = $_POST['site_homepage'];
    $tut_page = $_POST['tut_page'];
    $avatar_link = $_POST['avatar_link'];
    require('config.php');
    mysql_connect($dbhost, $dbusername, $dbpassword);
    mysql_select_db($dbname);
    mysql_query("INSERT INTO ". $table_prefix ."_tutorials (name, category, date, descrip, url2, url, previews, active)
    VALUES('$name', '$cateogry', now(), '$tutorial_discription', '$site_homepage', '$tut_page', '$avatar_link', '0')")or die (mysql_error());
 	 echo 'Thank you, your tutorial has been submited. If your tutorial is not on in 7 days it has been declined';
 	 }
  }
	}
	else
	{
  $request_id = $_REQUEST['id'];
  $form = '<form name="submit" method="post" action="submit.php?submit=2&id='. $request_id .'">
  <p>Tutorial Name:	
  <input type="text" name="tut_name">
  </p>
  <p>Tutorial Discription:
  <input type="text" name="tut_discription"> 
  </p>
  <p>Site Hompage(with http://):
  <input type="text" name="site_homepage">
  </p>
  <p>Tutorial Page (with http://): 
  <input type="text" name="tut_page">
  </p>
  <p>Avatar Link (with http://): 
  <input type="text" name="avatar_link"> (not needed)
  </p>
  <p>
  <input type="submit" value="Submit" name="Submit">
  </p>
  </form>';
  echo $form;
	}


Okay at the else part is were it would go if the user did not submit it to there and it has the form on it. Them a bove it there are two parts that look simalar, the top one is if the user does not have an avatar and the botton one is if they do. The bottom one works fine.

Now this is the part I think I am having most of the troubles in:

if((!$avatar_link))
 	 {
    require ('config.php');
    $result = mysql_query("SELECT * FROM ". $table_prefix ."_categories ORDER BY ID ASC");
    while($row = mysql_fetch_array($result))
    {
   	 $menu = $_POST['menu'];
   	 $name = $_POST['tut_name'];
   	 $category = $_POST['select'];
   	 $tutorial_description = $_POST['tut_description'];
   	 $site_homepage = $_POST['site_homepage'];
   	 $tut_page = $_POST['tut_page'];
   	 $avatar_link = $row['avatar'];
    }
    require('config.php');
    mysql_query("INSERT INTO ". $table_prefix ."_tutorials (name, category, date, descrip, url2, url, previews, active)
    VALUES('$name', '$cateogry', now(), '$tutorial_discription', '$site_homepage', '$tut_page', '$avatar_link', '0')")or die (mysql_error());
    echo 'Thank you, your tutorial has been submited. If your tutorial is not on in 7 days it has been declined';
 	 }

It is like it just doesn't what to read the defualt avatar in this part of the script:

$avatar_link = $row['avatar'];

Then because it doesn't want to read it when they submit it it shows nothing there so the picture doesn't want to work.

Now in this part of the script I have two tables the _categories and the _tutorials and what it is suppose to do is take the default link from categories and posts it to the part that has $row['avatar']; there and then it should insert it into the _tutorials categories.

I hope that isn't confusing lol I was trying to tell you as best I could on how I think it should work and whats wrong with it.

dEcade

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 July 2005 - 01:54 PM

Well, i noticed that you require config.php twice. After one, you add the mysql_connect() etc... functions, after the other, theres nothing. Theoretically, that should give you an error after the first require, or just waste resources.

Other then that, check and make sure that "$row['avatar'];" exists, and contains the data you want. If it does, then make sure you select the right avatar for the category. I just noticed you don't have a where statement in the query, and that could help things. Try changing it to something like this:
mysql_query("SELECT avatar FROM ".$table_prefix."_categories WHERE category = '".$_POST['category']." LIMIT 1");
Naturally, you need to modify it to work with your _categories table and form correctly, but you should get the point.

If that doesn't work, change
while($row = mysql_fetch_array($result))
   {
    $menu = $_POST['menu'];
    $name = $_POST['tut_name'];
    $category = $_POST['select'];
    $tutorial_description = $_POST['tut_description'];
    $site_homepage = $_POST['site_homepage'];
    $tut_page = $_POST['tut_page'];
    $avatar_link = $row['avatar'];
   }
   require('config.php');
To
while($row = mysql_fetch_array($result))
   {
    highlight_string(print_r($row,1));
   }
   die();
Just so you can see what's being out putted from the database, and then you can adjust from there.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users