not working code, please help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

not working code, please help!

Post by elenait »

What I have here is a code that doesn't have a result after 'submit', there is a blank page. I want to have an error message or to redirect me to the next page. So the "ifs" are not readed, may be, I don;t know why. Please help me, as I am new in php and MySql. Thank you in advance!

***********************************************************************************************************************************

Code: Select all

<? ob_start(); //Its turning on the output buffer. So any output is kept in the buffer. And ob_flush() is to flush the buffer ?><?php
session_start();

$user = $_SESSION['user'];
include "config.php";
echo "Вие сте логнат като ".$user."!<br>";
 
 date_default_timezone_set('Europe/Helsinki');
 echo "Днес е ".date("Y m d");
 
 $art_tell=$_POST['art_tell'];
		$art_site=$_POST['art_site'];
			$id_oblast=$_POST['id_oblast'];
			$head=$_POST['head'];
			$art_description=$_POST['art_description'];
			$id_genre=$_POST['id_genre'];
			$time=$_POST['time'];
			$quantity=$_POST['quantity'];
			$prise=$_POST['prise'];
			$button=$_POST['submit'];
			$date=$_POST['date("Y m d")'];
		//	$user = $_POST['user'];
		
			
			

$form="<table align='center'>";
$form.="<form action='ad_reg1.php' method='post'>";
$form.="<tr><td>";
$form.="<select  name='id_genre'  >";

$form.="<option selected='selected'>Изберете жанр *</option>";

$form.="<option value='1'>фолклор</option>";
$form.="<option value='2'>танци</option>";
$form.="<option value='3'>вокал</option>";
$form.="<option value='4'>оркестър, бенд</option>";
$form.="<option value='5'>водещи</option>";
$form.="<option value='6'>циркови, екзотични</option>";
$form.="      </select>";
$form.="<br /><br />";
$form.="</td></tr><tr><td>";
$form.="<select  name='id_oblast' style='width:160px'  >";
$form.="<option selected='selected'>Изберете област *</option>";
$form.=" <option value='26'>Благоевград</option>";
$form.="<option value='18'>Бургас</option>";
$form.="<option value='1'>Варна</option>";
$form.="<option value='5'>Велико Търново</option>";
$form.="<option value='10'>Видин</option>";
$form.="<option value='11'>Враца</option>";
$form.="<option value='6'>Габрово</option>";
$form.="<option value='2'>Добрич</option>";
$form.="<option value='23'>Кърджали</option>";
$form.="<option value='25'>Кюстендил</option>";
$form.="<option value='14'>Ловеч</option>";
$form.="<option value='12'>Монтана</option>";
$form.="<option value='19'>Пазарджик</option>";
$form.="<option value='27'>Перник</option>";
$form.="<option value='13'>Плевен</option>";
$form.="<option value='20'>Пловдив</option>";
$form.="<option value='8'>Разград</option>";
$form.="<option value='7'>Русе</option>";
$form.="<option value='9'>Силистра</option>";
$form.="<option value='16'>Сливен</option>";
$form.="<option value='21'>Смолян</option>";
$form.="<option value='24'>София</option>";
$form.="<option value='15'>Стара Загора</option>";
$form.="<option value='3'>Търговище</option>";
$form.="<option value='22'>Хасково</option>";
$form.="<option value='4'>Шумен</option>";
$form.="<option value='17'>Ямболн</option>";

 $form.="     </select><br /><br />";
$form.="тел.*<br /><input type='text' name='art_tell'  size='20'/><br />";
$form.="</td></tr><tr><td>";
$form.="сайт ('http://')<br /><input type='text' name='art_site'  size='20'/><br />";
$form.="</td></tr><tr><td>";
$form.="Име на ръководител/главен артист*<br /><input type='text'name='head'size='20'/><br/><";$form.="br />";
$form.="</td></tr><tr><td>";
$form.="Кратко описание на изявата*<br /><textarea   name='art_description'  rows='6' cols='40'>";$form.="</textarea><br /><br />";
$form.="Продължителност на програмата<br /><input type='text' name='time'  size='15'/><br />";
$form.="</td></tr><tr><td>";
$form.="брой участници*<br /><input type='text' name='quantity' size='5'/><br />";
$form.="</td></tr><tr><td>";
$form.="цена (лв.)<br /><input type='text' name='prise'   size='15'/><br /><br />";
$form.="</td></tr><tr><td>";
$form.="</td></tr>";
$form.="<tr><td><br /><br />";
$form.="   <p align='center'><input type='submit'  name='submit' value='запиши и продължи' />";$form.="</p>   </td></tr>";
$form.="</form></table> <a href='register.php'>назад</a>";
if (!isset($button)){
echo $form;  }
	   
   
			
			
           if (((isset ($button)) && (($id_oblast)!==null) &&
    (($id_genre)!==null) && (($art_description)!==null) &&
    (($art_tell)!==null) && (($head)!==null) && ($quantity)!==null)&&
    (eregi("^[0-9]+$", $art_tell)) &&
    (eregi("^[a-z0-9]+$", $art_site)) &&       //eregi- case insensitive
    (eregi("^[a-zа-я0-9]+$", $art_description)))
{
			 $result2 =mysql_query( "INSERT INTO  art_contact
                            (id_user, art_tell, art_site,id_reg  id_oblast,type_id) 
                         VALUES 
                            ('','$art_tell', '$art_site','', '$id_oblast','') ");
  
			 $result3 = mysql_query("INSERT INTO art_more
                           ( id_user, head, art_description,  id_genre, time, quantity, prise ) 
                        VALUES 
                           ('','$head', '$art_description', '$id_genre','$time', '$quantity',                '$prise') "); 
							
   if (($result2) && ($result3)) //&& (mysql_num_rows($result2)!==0))
   {
				
			header("Location: http://localhost/artisti/exp.php"); exit;	
}}

if (((isset ($button)) && ((($id_oblast)==null) ||
 ($id_genre==null) || ($art_description)==null) ||
 ($art_tell==null) || ($head==null) || ($quantity==null)||
(!eregi("^[0-9]+$", $art_tell)) ||
   (!eregi("^[a-z0-9]+$", $art_site)) ||      //eregi- case insensitive
(!eregi("^[a-zа-я0-9]+$", $art_description)) ))
{ 
	exit(); echo"<center><font  color=\"#FF0000\">Моля, върнете се и попълнете полетата, отбелязани със ' * ' с валидни данни!</font></center>"; 
}

		
?><? ob_flush(); ?>
****************************************************************************************************************
Last edited by Benjamin on Fri Dec 10, 2010 2:10 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: not working code, please help!

Post by social_experiment »

Code: Select all

<?php
if (((isset ($button)) && (($id_oblast)!==null) &&
(($id_genre)!==null) && (($art_description)!==null) &&
(($art_tell)!==null) && (($head)!==null) && ($quantity)!==null)&&
(eregi("^[0-9]+$", $art_tell)) &&
(eregi("^[a-z0-9]+$", $art_site)) && //eregi- case insensitive
(eregi("^[a-zа-я0-9]+$", $art_description)))
{
$result2 =mysql_query( "INSERT INTO art_contact
(id_user, art_tell, art_site,id_reg id_oblast,type_id) 
VALUES 
('','$art_tell', '$art_site','', '$id_oblast','') ");

$result3 = mysql_query("INSERT INTO art_more
( id_user, head, art_description, id_genre, time, quantity, prise ) 
VALUES 
('','$head', '$art_description', '$id_genre','$time', '$quantity', '$prise') "); 

if (($result2) && ($result3)) //&& (mysql_num_rows($result2)!==0))
{

header("Location: http://localhost/artisti/exp.php"); exit; 
}}

if (((isset ($button)) && ((($id_oblast)==null) ||
($id_genre==null) || ($art_description)==null) ||
($art_tell==null) || ($head==null) || ($quantity==null)||
(!eregi("^[0-9]+$", $art_tell)) ||
(!eregi("^[a-z0-9]+$", $art_site)) || //eregi- case insensitive
(!eregi("^[a-zа-я0-9]+$", $art_description)) ))
{ 
exit(); echo"<center><font color=\"#FF0000\">Моля, върнете се и попълнете полетата, отбелязани със ' * ' с валидни данни!</font></center>"; 
}

?>
It's possible that you are not meeting ALL of the conditions you set for the form like if (($result2) && ($result3)) . You should simplify the code IMO.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

Re: not working code, please help!

Post by elenait »

Hello, again social_experiment!
I tried to separate the if statement in many if(s), but the result is the same: blank page.
When I put all required data into the form, or I don't put anything - no error message or redirecting to next page?
:( Any other suggestion?
Thanks in advance to everyone who can help!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: not working code, please help!

Post by social_experiment »

This might be irrelevant but why do you declare your variables ($art_tell=$_POST['art_tell'];) before you actually process the code? Make a copy of your code and try the following

Code: Select all

<?php
 // this is when you submit the form
 if (isset($_POST['submit'])) {
   echo 'Button has been clicked';
 }
 else {
  echo 'Button not clicked';
 }
?>
Edit: Ignore the question about the variables, it is irrelevant.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

Re: not working code, please help!

Post by elenait »

:? Dear social_experiment,
I putt your code and it shows if the button is clicked or not. I change the place where I declare the variables , and now when I click the button , the form is still there, no redirect, no error message, the only difference is the message that the button has been clicked.

Code: Select all

<? ob_start(); //Its turning on the output buffer. So any output is kept in the buffer. And ob_flush() is to flush the buffer ?><?php
session_start();

$user = $_SESSION['user'];
include "config.php";
echo "Вие сте логнат като ".$user."!<br>";
 
 date_default_timezone_set('Europe/Helsinki');
 echo "Днес е ".date("Y m d");
 

		//	$user = $_POST['user'];
		
			
			

$form="<table align='center'>";
$form.="<form action='ad_reg1.php' method='post'>";
$form.="<tr><td>";
$form.="<select  name='id_genre'  >";

$form.="<option selected='selected'>Изберете жанр *</option>";

$form.="<option value='1'>фолклор</option>";
$form.="<option value='2'>танци</option>";
$form.="<option value='3'>вокал</option>";
$form.="<option value='4'>оркестър, бенд</option>";
$form.="<option value='5'>водещи</option>";
$form.="<option value='6'>циркови, екзотични</option>";
$form.="      </select>";
$form.="<br /><br />";
$form.="</td></tr><tr><td>";
$form.="<select  name='id_oblast' style='width:160px'  >";
$form.="<option selected='selected'>Изберете област *</option>";
$form.=" <option value='26'>Благоевград</option>";
$form.="<option value='18'>Бургас</option>";
$form.="<option value='1'>Варна</option>";
$form.="<option value='5'>Велико Търново</option>";
$form.="<option value='10'>Видин</option>";
$form.="<option value='11'>Враца</option>";
$form.="<option value='6'>Габрово</option>";
$form.="<option value='2'>Добрич</option>";
$form.="<option value='23'>Кърджали</option>";
$form.="<option value='25'>Кюстендил</option>";
$form.="<option value='14'>Ловеч</option>";
$form.="<option value='12'>Монтана</option>";
$form.="<option value='19'>Пазарджик</option>";
$form.="<option value='27'>Перник</option>";
$form.="<option value='13'>Плевен</option>";
$form.="<option value='20'>Пловдив</option>";
$form.="<option value='8'>Разград</option>";
$form.="<option value='7'>Русе</option>";
$form.="<option value='9'>Силистра</option>";
$form.="<option value='16'>Сливен</option>";
$form.="<option value='21'>Смолян</option>";
$form.="<option value='24'>София</option>";
$form.="<option value='15'>Стара Загора</option>";
$form.="<option value='3'>Търговище</option>";
$form.="<option value='22'>Хасково</option>";
$form.="<option value='4'>Шумен</option>";
$form.="<option value='17'>Ямболн</option>";

 $form.="     </select><br /><br />";
$form.="тел.*<br /><input type='text' name='art_tell'  size='20'/><br />";
$form.="</td></tr><tr><td>";
$form.="сайт ('http://')<br /><input type='text' name='art_site'  size='20'/><br />";
$form.="</td></tr><tr><td>";
$form.="Име на ръководител/главен артист*<br /><input type='text'name='head'size='20'/><br/><";$form.="br />";
$form.="</td></tr><tr><td>";
$form.="Кратко описание на изявата*<br /><textarea   name='art_description'  rows='6' cols='40'>";$form.="</textarea><br /><br />";
$form.="Продължителност на програмата<br /><input type='text' name='time'  size='15'/><br />";
$form.="</td></tr><tr><td>";
$form.="брой участници*<br /><input type='text' name='quantity' size='5'/><br />";
$form.="</td></tr><tr><td>";
$form.="цена (лв.)<br /><input type='text' name='prise'   size='15'/><br /><br />";
$form.="</td></tr><tr><td>";
$form.="</td></tr>";
$form.="<tr><td><br /><br />";
$form.="   <p align='center'><input type='submit'  name='submit' value='запиши и продължи' />";$form.="</p>   </td></tr>";
$form.="</form></table> <a href='register.php'>назад</a>";
if (!isset($button)){
echo $form;  }
	   
   
 // this is when you submit the form
 if (isset($_POST['submit'])) {
   echo 'Button has been clicked';
 }
 else {
  echo 'Button not clicked';
 }
 $art_tell=$_POST['art_tell'];
		$art_site=$_POST['art_site'];
			$id_oblast=$_POST['id_oblast'];
			$head=$_POST['head'];
			$art_description=$_POST['art_description'];
			$id_genre=$_POST['id_genre'];
			$time=$_POST['time'];
			$quantity=$_POST['quantity'];
			$prise=$_POST['prise'];
			$button=$_POST['submit'];
			$date=$_POST['date("Y m d")'];
			
			
           if ((isset ($_POST['submit'])) &&($id_oblast!==null) 
		                             &&    ($id_genre!==null) 
									  &&($art_description!==null) 
										   &&  ($art_tell!==null) 
										     && ($head!==null) 
										    && ($quantity!==null) 
											   && (eregi("^[0-9]+$", $art_tell)) 
											  && (eregi("^[a-z0-9]+$", $art_site)) 
											 &&        //eregi- case insensitive
    (eregi("^[a-zа-я0-9]+$", $art_description)))
{
			 $result2 =mysql_query( "INSERT INTO  art_contact
                            (id_user, art_tell, art_site,id_reg  id_oblast,type_id) 
                         VALUES 
                            ('','$art_tell', '$art_site','', '$id_oblast','') ");
  
			 $result3 = mysql_query("INSERT INTO art_more
                           ( id_user, head, art_description,  id_genre, time, quantity, prise ) 
                        VALUES 
                           ('','$head', '$art_description', '$id_genre','$time', '$quantity',                '$prise') "); 
							
   if (($result2) &&  ($result3)) //&& (mysql_num_rows($result2)!==0))
   {
				
			header("Location: http://localhost/artisti/exp.php"); exit;	
}}

if ((isset ($_POST['submit'])) && (($id_oblast==null) |
 ($id_genre==null) | ($art_description==null) |
 ($art_tell==null) | ($head==null) | ($quantity==null)|
(!eregi("^[0-9]+$", $art_tell)) |
   (!eregi("^[a-z0-9]+$", $art_site)) |      //eregi- case insensitive
(!eregi("^[a-zа-я0-9]+$", $art_description))))
{ 
	exit(); echo"<center><font  color=\"#FF0000\">Моля, върнете се и попълнете полетата, отбелязани със ' * ' с валидни данни!</font></center>"; 
}

		
?><? ob_flush(); ?>
Last edited by Benjamin on Tue Dec 28, 2010 3:51 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: not working code, please help!

Post by social_experiment »

:) The code i supplied was simply a demonstration to show you that you should have an 'else' to the if (!isset) option. Here is what i mean (using your code).

Code: Select all

<?php
if (!isset($button)){
 echo $form;
 }
else {
 //---- your code should in the else statement.
 $art_tell=$_POST['art_tell'];
 $art_site=$_POST['art_site'];
 $id_oblast=$_POST['id_oblast'];
 $head=$_POST['head'];
 $art_description=$_POST['art_description'];
 $id_genre=$_POST['id_genre'];
 $time=$_POST['time'];
 $quantity=$_POST['quantity'];
 $prise=$_POST['prise'];
 $button=$_POST['submit'];
 $date=$_POST['date("Y m d")'];


if ((isset ($_POST['submit'])) &&($id_oblast!==null) 
&& ($id_genre!==null) 
&&($art_description!==null) 
&& ($art_tell!==null) 
&& ($head!==null) 
&& ($quantity!==null) 
&& (eregi("^[0-9]+$", $art_tell)) 
&& (eregi("^[a-z0-9]+$", $art_site)) 
&& //eregi- case insensitive
(eregi("^[a-zа-я0-9]+$", $art_description)))
{
$result2 =mysql_query( "INSERT INTO art_contact
(id_user, art_tell, art_site,id_reg id_oblast,type_id) 
VALUES 
('','$art_tell', '$art_site','', '$id_oblast','') ");

$result3 = mysql_query("INSERT INTO art_more
( id_user, head, art_description, id_genre, time, quantity, prise ) 
VALUES 
('','$head', '$art_description', '$id_genre','$time', '$quantity', '$prise') "); 

if (($result2) && ($result3)) //&& (mysql_num_rows($result2)!==0))
{

header("Location: http://localhost/artisti/exp.php"); exit; 
}}

if ((isset ($_POST['submit'])) && (($id_oblast==null) |
($id_genre==null) | ($art_description==null) |
($art_tell==null) | ($head==null) | ($quantity==null)|
(!eregi("^[0-9]+$", $art_tell)) |
(!eregi("^[a-z0-9]+$", $art_site)) | //eregi- case insensitive
(!eregi("^[a-zа-я0-9]+$", $art_description))))
{ 
exit(); echo"<center><font color=\"#FF0000\">Моля, върнете се и попълнете полетата, отбелязани със ' * ' с валидни данни!</font></center>"; 
}
// ----
}
?>
The syntax below will also have to be changed.

Code: Select all

<?php
if ((isset ($_POST['submit'])) &&($id_oblast!==null) 
&& ($id_genre!==null) 
&&($art_description!==null) 
&& ($art_tell!==null) 
&& ($head!==null) 
&& ($quantity!==null) 
&& (eregi("^[0-9]+$", $art_tell)) 
&& (eregi("^[a-z0-9]+$", $art_site)) 
&& //eregi- case insensitive
(eregi("^[a-zа-я0-9]+$", $art_description)))
?>
You should first check if the button is set. Once you have concluded that is has, then you start checking the validity of the fields (do they have data, are the types valid to each field, etc). I think there are too many conditions that have to be met and that's causing the problem. Your idea is correct to want to check all these things but you are going about it in the wrong way. Here is some pseudo-code that might be helpful
Pseudo-code
if : (!isset(button)) show error message / redirect user
else : at this point the button is clicked so you start checking for other things
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

Re: not working code, please help!

Post by elenait »

I know the conditions are a lot,but how to do like them working in general? here is what i did, but the result is the same- it stays on the same page, but nothing on it:

....

Code: Select all

$button=$_POST['submit'];
if (!isset($button)){
echo $form;  }
	   
   else {

 $art_tell=$_POST['art_tell'];
		$art_site=$_POST['art_site'];
			$id_oblast=$_POST['id_oblast'];
			$head=$_POST['head'];
			$art_description=$_POST['art_description'];
			$id_genre=$_POST['id_genre'];
			$time=$_POST['time'];
			$quantity=$_POST['quantity'];
			$prise=$_POST['prise'];
			
			$date=$_POST['date("Y m d")'];
			
			if (isset($id_genre)) {			
                  if (isset($id_oblast)) {
                      if ($art_tell!==null) {
                         if($head!==null) {
                            if  ($art_description!==null) {
                                if ($quantity!==null){
                                    if (eregi("^[0-9]+$", $art_tell)){
                                      if (eregi("^[a-z0-9]+$", $art_site))  {
                                         if (eregi("^[a-zа-я0-9]+$", $art_description))    {

			 $result2 =mysql_query( "INSERT INTO  art_contact
                            (id_user, art_tell, art_site,id_reg  id_oblast,type_id) 
                         VALUES 
                            (' ','$art_tell', '$art_site',' ', '$id_oblast',' ') ");
  
			 $result3 = mysql_query("INSERT INTO art_more
                           ( id_user, head, art_description,  id_genre, time, quantity, prise ) 
                        VALUES 
                           (' ','$head', '$art_description', '$id_genre','$time', '$quantity',   '$prise') "); }
							
   if (($result2) |  ($result3)) 
      {
				
			header("Location: http://localhost/artisti/exp.php"); exit;	
       }
									  }else{exit; echo"Моля, попълнете description validno!";}
									}else{exit; echo"Моля, попълнете walide sajt";}
								}else{exit; echo"Моля, попълнете валиден телефон";}
							}else {exit; echo"Моля, попълнете quantity";}
						 }else {exit; echo"Моля, напишете кратко описание";}
					  }else{exit; echo"Моля, попълнете glawen artist";}
				  }else{exit; echo"Моля, попълнете телефон";}
			}else {exit('Моля, изберете област');}
    exit( 'Моля изберете жанр');

   }
Last edited by Benjamin on Tue Dec 28, 2010 3:51 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: not working code, please help!

Post by social_experiment »

This page you are refering to, what's its name? In your script you are calling a page called 'ad_reg1.php', what code is on that page. If nothing, that could be the reason you are not seeing anything happening. If you want to call the page on itself, change the action of the form to $_SERVER['PHP_SELF'], then your code should be called. Here is the latest bit of code, I can't test it properly but it does call on itself so you can test it and see if it work. Hth :) (Pardon all the question marks, that's my editor that did that :| )

Code: Select all

<? ob_start(); //Its turning on the output buffer. So any output is kept in the buffer. And ob_flush() is to flush the buffer ?><?php
session_start();

$user = $_SESSION['user'];
include "config.php";
echo "??? ??? ?????? ???? ".$user."!<br>";
 
 date_default_timezone_set('Europe/Helsinki');
 echo "???? ? ".date("Y m d");
 
 $art_tell=$_POST['art_tell'];
		$art_site=$_POST['art_site'];
			$id_oblast=$_POST['id_oblast'];
			$head=$_POST['head'];
			$art_description=$_POST['art_description'];
			$id_genre=$_POST['id_genre'];
			$time=$_POST['time'];
			$quantity=$_POST['quantity'];
			$prise=$_POST['prise'];
			$button=$_POST['submit'];
			$date=$_POST['date("Y m d")'];
		//	$user = $_POST['user'];
		
			
			

$form="<table align='center'>";
$form.="<form action='". $_SERVER['PHP_SELF'] ."' method='post'>";
$form.="<tr><td>";
$form.="<select  name='id_genre'  >";

$form.="<option selected='selected'>???????? ???? *</option>";

$form.="<option value='1'>???????</option>";
$form.="<option value='2'>?????</option>";
$form.="<option value='3'>?????</option>";
$form.="<option value='4'>????????, ????</option>";
$form.="<option value='5'>??????</option>";
$form.="<option value='6'>???????, ?????????</option>";
$form.="      </select>";
$form.="<br /><br />";
$form.="</td></tr><tr><td>";
$form.="<select  name='id_oblast' style='width:160px'  >";
$form.="<option selected='selected'>???????? ?????? *</option>";
$form.=" <option value='26'>???????????</option>";
$form.="<option value='18'>??????</option>";
$form.="<option value='1'>?????</option>";
$form.="<option value='5'>?????? ???????</option>";
$form.="<option value='10'>?????</option>";
$form.="<option value='11'>?????</option>";
$form.="<option value='6'>???????</option>";
$form.="<option value='2'>??????</option>";
$form.="<option value='23'>????????</option>";
$form.="<option value='25'>?????????</option>";
$form.="<option value='14'>?????</option>";
$form.="<option value='12'>???????</option>";
$form.="<option value='19'>?????????</option>";
$form.="<option value='27'>??????</option>";
$form.="<option value='13'>??????</option>";
$form.="<option value='20'>???????</option>";
$form.="<option value='8'>???????</option>";
$form.="<option value='7'>????</option>";
$form.="<option value='9'>????????</option>";
$form.="<option value='16'>??????</option>";
$form.="<option value='21'>??????</option>";
$form.="<option value='24'>?????</option>";
$form.="<option value='15'>????? ??????</option>";
$form.="<option value='3'>?????????</option>";
$form.="<option value='22'>???????</option>";
$form.="<option value='4'>?????</option>";
$form.="<option value='17'>??????</option>";

 $form.="     </select><br /><br />";
$form.="???.*<br /><input type='text' name='art_tell'  size='20'/><br />";
$form.="</td></tr><tr><td>";
$form.="???? ('http://')<br /><input type='text' name='art_site'  size='20'/><br />";
$form.="</td></tr><tr><td>";
$form.="??? ?? ???????????/?????? ??????*<br /><input type='text'name='head'size='20'/><br/><";$form.="br />";
$form.="</td></tr><tr><td>";
$form.="?????? ???????? ?? ???????*<br /><textarea   name='art_description'  rows='6' cols='40'>";$form.="</textarea><br /><br />";
$form.="??????????????? ?? ??????????<br /><input type='text' name='time'  size='15'/><br />";
$form.="</td></tr><tr><td>";
$form.="???? ?????????*<br /><input type='text' name='quantity' size='5'/><br />";
$form.="</td></tr><tr><td>";
$form.="???? (??.)<br /><input type='text' name='prise'   size='15'/><br /><br />";
$form.="</td></tr><tr><td>";
$form.="</td></tr>";
$form.="<tr><td><br /><br />";
$form.="   <p align='center'><input type='submit'  name='submit' value='?????? ? ????????' />";$form.="</p>   </td></tr>";
$form.="</form></table> <a href='register.php'>?????</a>";
if (!isset($button)){
echo $form;  }
else {	   
   
			
			
           if (((isset ($button)) && (($id_oblast)!==null) &&
    (($id_genre)!==null) && (($art_description)!==null) &&
    (($art_tell)!==null) && (($head)!==null) && ($quantity)!==null)&&
    (eregi("^[0-9]+$", $art_tell)) &&
    (eregi("^[a-z0-9]+$", $art_site)) &&       //eregi- case insensitive
    (eregi("^[a-z?-?0-9]+$", $art_description)))
{
			 $result2 =mysql_query( "INSERT INTO  art_contact
                            (id_user, art_tell, art_site,id_reg  id_oblast,type_id) 
                         VALUES 
                            ('','$art_tell', '$art_site','', '$id_oblast','') ");
  
			 $result3 = mysql_query("INSERT INTO art_more
                           ( id_user, head, art_description,  id_genre, time, quantity, prise ) 
                        VALUES 
                           ('','$head', '$art_description', '$id_genre','$time', '$quantity',                '$prise') "); 
							
   if (($result2) && ($result3)) //&& (mysql_num_rows($result2)!==0))
   {			
			header("Location: <!-- m --><a class=\"postlink\" href=\"http://localhost/artisti/exp.php\">
			http://localhost/artisti/exp.php</a><!-- m -->");
			exit;	
   }  
}
}

		
?><? ob_flush(); ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

Re: not working code, please help!

Post by elenait »

I put $_SERVER['PHP_SELF'] , and the code what you entered, but it still not working :cry: :cry:
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: not working code, please help!

Post by social_experiment »

Code: Select all

<?php
if (!isset($button)){
echo $form;  }
else {
	
	   
   
			
			
           if ( ((isset ($button)) && (($id_oblast)!==null) &&
    (($id_genre)!==null) && (($art_description)!==null) &&
    (($art_tell)!==null) && (($head)!==null) && ($quantity !==null)&&
    (eregi("^[0-9]+$", $art_tell)) &&
    (eregi("^[a-z0-9]+$", $art_site)) &&       //eregi- case insensitive
    (eregi("^[a-z?-?0-9]+$", $art_description)) ) )
{
	
			 $result2 =mysql_query( "INSERT INTO  art_contact
                            (id_user, art_tell, art_site,id_reg  id_oblast,type_id) 
                         VALUES 
                            ('','$art_tell', '$art_site','', '$id_oblast','') ");							
  
			 $result3 = mysql_query("INSERT INTO art_more
                           ( id_user, head, art_description,  id_genre, time, quantity, prise ) 
                        VALUES 
                           ('','$head', '$art_description', '$id_genre','$time', '$quantity', '$prise') "); 
						 
							
   if (($result2) && ($result3)) //&& (mysql_num_rows($result2) != 0))
   {
				
			header("Location: <!-- m --><a class=\"postlink\" 
			href=\"http://localhost/artisti/exp.php\">http://localhost/artisti/exp.php</a><!-- m -->");
			exit;	
}}
    // ----------------------------------------
    else {
		// Add additional code here
                                echo 'Query failed';
	}
   // -----------------------------------------

	}
?>
Ok, so there reason that nothing is showing (i think) is because you had no code to check what would happen if your results ($result 2 and $result 3) failed. Add the code that is between the two lines in the above example and see what happens.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

Re: not working code, please help!

Post by elenait »

It says this : 'Query failed isset but'; So the file know that the button isset, but doesn't do the rest... :?:
And if I put the echo where you suggested- again nothing
..................................................

Code: Select all

if (!isset($button)){
echo $form;  }
	   
   // ----------------------------------------
    else {
                // Add additional code here
                                echo 'Query failed isset but';
        
   // -----------------------------------------


  if (((isset ($button)) && (($id_oblast)!==null) &&
    (($id_genre)!==null) && (($art_description)!==null) &&
    (($art_tell)!==null) && (($head)!==null) && ($quantity)!==null)&&
    (eregi("^[0-9]+$", $art_tell)) &&
    (eregi("^[a-z0-9]+$", $art_site)) &&       //eregi- case insensitive
    (eregi("^[a-z?-?0-9]+$", $art_description)))
{
                         $result2 =mysql_query( "INSERT INTO  art_contact
                            (id_user, art_tell, art_site,id_reg  id_oblast,type_id)
                         VALUES
                            ('','$art_tell', '$art_site','', '$id_oblast','') ");
 
                         $result3 = mysql_query("INSERT INTO art_more
                           ( id_user, head, art_description,  id_genre, time, quantity, prise )
                        VALUES
                           ('','$head', '$art_description', '$id_genre','$time', '$quantity',                '$prise') ");
                                                       
   if (($result2) && ($result3)) //&& (mysql_num_rows($result2)!==0))
   {                   
                        header("Location:
                        <!-- m --><a class='postlink' href='http://localhost/artisti/exp.php'>http://localhost/artisti/exp.php</a><!-- m -->");
                        exit;  
   }  // ----------------------------------------
    else {
                // Add additional code here
                                echo 'Query failed $result';
        }
   // -----------------------------------------

}
	}
Last edited by Benjamin on Tue Dec 28, 2010 3:52 am, edited 2 times in total.
Reason: Added [syntax=php] tags.
elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

Re: not working code, please help!

Post by elenait »

That is the code with else(s) , that says 'Query failed isset but :banghead:

Code: Select all

$button=$_POST['submit'];
if (!isset($button)){
echo $form;  }
	   
   else {        echo 'Query failed isset but';

 $art_tell=$_POST['art_tell'];
		$art_site=$_POST['art_site'];
			$id_oblast=$_POST['id_oblast'];
			$head=$_POST['head'];
			$art_description=$_POST['art_description'];
			$id_genre=$_POST['id_genre'];
			$time=$_POST['time'];
			$quantity=$_POST['quantity'];
			$prise=$_POST['prise'];
			
			$date=$_POST['date("Y m d")'];
			
			if (isset($id_genre)) {			
                  if (isset($id_oblast)) {
                      if ($art_tell!==null) {
                         if($head!==null) {
                            if  ($art_description!==null) {
                                if ($quantity!==null){
                                    if (eregi("^[0-9]+$", $art_tell)){
                                      if (eregi("^[a-z0-9]+$", $art_site))  {
                                         if (eregi("^[a-zа-я0-9]+$", $art_description))    {

			 $result2 =mysql_query( "INSERT INTO  art_contact
                            (id_user, art_tell, art_site,id_reg  id_oblast,type_id) 
                         VALUES 
                            ('','$art_tell', '$art_site','', '$id_oblast','') ");
  
			 $result3 = mysql_query("INSERT INTO art_more
                           ( id_user, head, art_description,  id_genre, time, quantity, prise ) 
                        VALUES 
                           ('','$head', '$art_description', '$id_genre','$time', '$quantity',                '$prise') "); }
							
   if (($result2) |  ($result3)) //&& (mysql_num_rows($result2)!==0))
      {
				
			header("Location: http://localhost/artisti/exp.php"); exit;	
       } 
									  }else{exit; echo"Моля, попълнете description validno!";}
									}else{exit; echo"Моля, попълнете walide sajt";}
								}else{exit; echo"Моля, попълнете валиден телефон";}
							}else {exit; echo"Моля, попълнете quantity";}
						 }else {exit; echo"Моля, напишете кратко описание";}
					  }else{exit; echo"Моля, попълнете glawen artist";}
				  }else{exit(); echo"Моля, попълнете телефон";}
			}else {exit('Моля, изберете област');}
    exit( 'Моля изберете жанр');

   }
Last edited by Benjamin on Tue Dec 28, 2010 3:52 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

Re: not working code, please help!

Post by elenait »

Any way, THANK YOU VERY MUCH for the simple advise to put echo "..";
The most simple the most greater (sorry if my english is incorrect).
I put echo in every condition and made it working!
I found the mistakes!
Have a nice evening social_experiment! :D :wink:
elenait
Forum Newbie
Posts: 21
Joined: Thu Dec 09, 2010 8:23 am

$row = mysql_fetch_array($sql) problem

Post by elenait »

Hello, everybody!
I have this code here:
The problem is that $row doesn't work, so no result here : ( First Name: <?php echo $row['date']; ?><br> ) and in the rest $row's queries!
Please help!
------------------------------------------------------update_account.php------------------------------------------------------

Code: Select all

<?php
include "auth_user.inc.php";
include "config.php";
?>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title></title>
</head>
<body>
<h1></h1>
<p>hello <?php echo $_SESSION['username'];?>
  Here you can update your account information for viewing in your
  profile.<br><br>
<?php

if (isset($_POST['submit']) && $_POST['submit'] == "Update") {
  $query_update = "UPDATE users SET 
                  mail = '" . $_POST['mail'] . "'
                   WHERE username = '" . $_SESSION['username'] . 
                  "' AND password = (PASSWORD('" . 
                  $_SESSION['password'] . "'))";
  $result_update = mysql_query($query_update) 
   or die(mysql_error($result_update)); //if ($query_update) {echo "update_q";}
 
// if($result_update) {echo"res_up";}
 
  $query = "SELECT * FROM users " .
           "WHERE username = '" . $_SESSION['username'] . "' " .
           "AND password = (PASSWORD('" . 
           $_SESSION['password'] . "'))";  //if($query) {echo"query";}
  $result = mysql_query($query) 
    or die(mysql_error());// if($result) {echo"result";}

 $row = mysql_fetch_array($result); if($row) {echo"row";}
  
?>
  <b>Your account information has been updated.</b><br>
  <a href="user_personal.php">Click here</a> to return to your account.
 
</p>
<?php
} else {
  $query = "SELECT * FROM users 
           WHERE username = '" . $_SESSION['username']. "' 
           AND password = (PASSWORD('" . 
           $_SESSION['password'] . "'));";
  $result = mysql_query($query) 
    or die(mysql_error());

 $row = mysql_fetch_array($result);
  ?>
<p>
  <form action='<?=$_SERVER['PHP_SELF']; ?>' method="post">
    Email: <input type="text" name='mail' 
             value='<?php while($row = mysql_fetch_array($result)){
echo $row['mail'];
}
 ?>'><br>
    
    <br><br>
    <input type="submit" name="submit" value="Update"> &nbsp; 
    <input type="button" value="Cancel" onClick="history.go(-1);">
  </form>
</p>
<?php
}
?>
</body>
</html>
-------------------------------------------------------------------------------user_personal.php---------------------------------------

Code: Select all

<?php
include "auth_user.inc.php";
include "config.php";
?>
<html>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />

<head>
<title>Beginning PHP5, Apache and MySQL</title>
</head>
<body>
<h1>Welcome to your personal information area</h1>
<p>
hello , <?php echo $_SESSION['username'];?>
  Here you can update your personal information, 
  or delete your account.<br>
  Your information as you currently have it is shown below:<br>
  <a href="index.php">Click here</a> to return to the home page<br><br>
<?php
$sql =mysql_query( "SELECT * FROM users 
         WHERE username = '" . $_SESSION['username'] . "'  
         AND password = (PASSWORD('" . 
         $_SESSION['password'] . "'))")

  or die(mysql_error());

$row = mysql_fetch_array($sql) ;


?>
  First Name: <?php echo $row['date']; ?><br>
  Last Name: <?php echo $row['type_id']; ?><br>
 
  Email: <?php echo $row['mail']; ?><br>
 <br><br>
  <a href="update_account.php">Update Account</a> | 
  <a href="delete_account.php">Delete Account</a>
</p>
</body>
</html>
Last edited by Benjamin on Tue Dec 28, 2010 3:52 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: not working code, please help!

Post by social_experiment »

Code: Select all

<?php $row = mysql_fetch_array($sql) ; ?>
The best option is to use this in a while loop. If you want to use the values 'outside' of the while loop, declare them inside the while loop.

Code: Select all

<?php
 while ($row = mysql_fetch_array($sql)) {
  $date = $row['date'];
  // etc
} >?
Now you can use '$date' as a variable outside the loop
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply