problem with PHP

problem with PHP

am 16.04.2008 12:58:32 von ghalyonline

i have problem with PHP language and it's :
------------------- the first page -----------------


function add_form (){
?>

>


cellspacing="0" bordercolor="#FFFFFF" bgcolor="#F2F2F2">































































Worker Id:
Worker Name:
Passport Number:
Age:
Languages:
Country:
Photo: value="2000">

Maximum
File is 200 KB
More Info:   KeyWords_ar
Description_en   Description_ar
Text_en :   Text_ar :
Photo Gallery : Yes if($images==yes){echo'checked=checked';} ?> value="yes"> NO type="radio" name="images" > value="no">      
name="edit" value=" Edit ">






}




function edit (){
$subid=$_GET[subid];

if ($_POST[subname_en]<>""){

$sql0="update sub set
`subname_en`='$_POST[subname_en]',`subname_ar`='$_POST[subna me_ar]',
`order`='$_POST[order]',

`title_en`='$_POST[title_en]',`title_ar`='$_POST[title_ar]', `banner`='$_POST[banner]',

`meta_key_en`='$_POST[key_en]',`meta_key_ar`='$_POST[key_ar] ',`meta_desc_en`='$_POST[desc_en]',`meta_desc_ar`='$_POST[de sc_ar]',
`side_right`='$_POST[side_right]',
`side_left`='$_POST[side_left]'
,`body`='$_POST[body]' ,`images`='$_POST[images]',`text_en`='$_POST[text_en]',`text _ar`='$_POST[text_ar]'
where subid='$_GET[subid]'";
mysql_query($sql0);
}
echo"
Edit Successfully
Back
";
}


function delete ()
{
$sql0="select sub_2id from sub_2 where sub_2id='$_GET[subid]'";
$rs0=mysql_query($sql0);
$num0=mysql_num_rows($rs0);

$sql7="select * from img where page='sub' and id='$_GET[subid]' ";
$rs7=mysql_query($sql7);
$num7=mysql_num_rows($rs7);


if($num0==0 and $num7==0 ){

$sql="delete from sub where subid='$_GET[subid]'";
mysql_query($sql);
}

else{
echo"
There Are Sub Pages or
Images


center>"; return; }
echo"
Delete Successfully
Back
";
}



$op=$_GET[op];

switch ($op)
{
case 'add_form' :
add_form();
break;

case 'add' :
add();
break;

case 'browse' :
browse();
break;

case 'edit_form' :
edit_form();
break;

case 'edit' :
edit();
break;

case 'delete' :
delete();
break;

}
?>

-----------------------
-------------- the second page ---------------

$sql="INSERT INTO `workers` ( `id` , `worker_id` , `name` ,
`passport_number` , `age` , `languages` , `country` , `photo` ,
`available` , `date_enter_syria` , `start_work` , `requested_name` ,
`more_info` )
VALUES (
'' , `$_POST[worker_id]` , `$_POST[worker_name]` , `
$_POST[passport_nu]` , `$_POST[age]` , `$_POST[lang]` , `
$_POST[country]` , `photo` , `$_POST[ava]` , `$_POST[enter_syria]` ,
`1` , `1` , `$_POST[info]` ) ";

mysql_query($sql);
if($sql){
echo"
The worker has been added successfully. href=index.php?page=new_worker&op=browse>
Back

";
}
?>
------------------
the problem that i can't insert the record to db
plz help me
im on fire

Re: problem with PHP

am 16.04.2008 13:04:45 von Captain Paralytic

On 16 Apr, 10:58, ghalyonl...@gmail.com wrote:
> i have problem with PHP language and it's :
> ------------------- the first page -----------------
> the problem that i can't insert the record to db
> plz help me
> im on fire
You have posted loads of code and a totally useless problem statement.

How about telling us what does happen.

Re: problem with PHP

am 16.04.2008 13:56:54 von alvaroNOSPAMTHANKS

ghalyonline@gmail.com escribió:
> $sql="INSERT INTO `workers` ( `id` , `worker_id` , `name` ,
> `passport_number` , `age` , `languages` , `country` , `photo` ,
> `available` , `date_enter_syria` , `start_work` , `requested_name` ,
> `more_info` )
> VALUES (
> '' , `$_POST[worker_id]` , `$_POST[worker_name]` , `
> $_POST[passport_nu]` , `$_POST[age]` , `$_POST[lang]` , `
> $_POST[country]` , `photo` , `$_POST[ava]` , `$_POST[enter_syria]` ,
> `1` , `1` , `$_POST[info]` ) ";

Since you don't give much info I've picked a random snippet from your
code and I've written down the remarks I could think of:

1. You can't randomly pick ` or ' at your will. They have different
meanings:

http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html
http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

2. What happens when Patrick O'Brian joins the staff?

http://en.wikipedia.org/wiki/Sql_injection
http://www.php.net/mysql_real_escape_string

3. In PHP, foo is not the same as 'foo'. Your code will eventually work
as expected but just by chance.

http://www.php.net/string
http://www.php.net/manual/en/language.constants.php

4. You can't develop properly if you don't enable error reporting. Open
you php.ini file and set the error_reporting and display_errors
directives to something useful.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--

Re: problem with PHP

am 16.04.2008 14:55:59 von hellsop

On Wed, 16 Apr 2008 03:58:32 -0700 (PDT), ghalyonline@gmail.com wrote:
> mysql_query($sql);

After everything like this? Put something like


or die('Query failed: ' . mysql_error());

If you make the quited part of the error unique for ever single one,
you'll ewven know precisely WHICH query failed.


> ------------------
> the problem that i can't insert the record to db
> plz help me
> im on fire

What does the error message say?

--
Any research done on how to efficiently use computers has been long lost
in the mad rush to upgrade systems to do things that aren't needed by
people who don't understand what they are really supposed to do with them.
-- Graham Reed