problem with PHP

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


function add_form (){
?>
<form action="action.php" method="POST" enctype="multipart/form-data"
>
<center>Back</center><br/>
<table width="530" border="1" align="center" cellpadding="5"
cellspacing="0" bordercolor="#FFFFFF" bgcolor="#F2F2F2">
<tr>
<td width="160">Worker Id:</td>
<td width="344"><input name="worker_id" type="text" /></td>
</tr>
<tr>
<td width="160">Worker Name:</td>
<td width="344"><input name="worker_name" type="text" /></td>
</tr>
<tr>
<td width="160">Passport Number:</td>
<td width="344"><input name="passport_nu" type="text" /></td>
</tr>
<tr>
<td width="160">Age:</td>

<td width="344"><input name="age" type="text" /></td>
</tr>
<tr>
<td width="160">Languages:</td>
<td width="344"><input name="lang" type="text" /></td>
</tr>
<tr>
<td width="160">Country:</td>
<td width="344"><select name="country">
<option value="syria">Syria</option>
<option value="uae">UAE</option>
<option value="eygpt">Eygpt</option>
<option value="saudi">Saudi</option>
<option value="turky">Turky</option>
</select>
</td>
</tr>
<tr>
<td width="160">Photo:</td>
<td width="344"><input type="hidden" name="max_file_size"
value="2000">
<input name="photo" type="file" size="25"/><br>Maximum
File is 200 KB</td>
</tr>
<tr>
<td width="160">More Info:</td>
<td width="344"><textarea name="info" cols="30" rows="5"></
textarea></td>
</tr>
<tr>
<td width="160">Available:</td>
<td width="344">Yes<input name="ava" type="radio" value="yes"
checked="checked" />
No<input name="ava" type="radio" value="no" /></td>
</tr>
<tr>
<td width="160">Date of Enter To Syria:</td>
<td width="344"><input name="enter_syria" type="text" /> dd/mm/
yyyy</td>
</tr>
<tr>
<td width="160" align="center"></td>
<td width="344" align="center"><input type="submit" name="add"
value="Add Worker"/>
</td>
</tr>
</table>
</form>


<?php
}


function add ()
{

$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]` ,
`` , `` , `$_POST[info]` ) ";

mysql_query($sql);
echo"<center>The worker has been added successfully.<a
href=index.php?page=main&op=browse>Back</a></center>
";
}



function browse (){
?>
<center>


<p><a href="index.php?page=new_worker&op=add_form">Add New Worker</
a></p>
</center>

<?php
}


function edit_form (){
if(!$_GET[subid]) return;
$sql="select * from`sub` where `subid`=$_GET[subid]";
$rs=mysql_query($sql);
$subid=mysql_result($rs,0,'subid');
$subname_en=mysql_result($rs,0,'subname_en');
$subname_ar=mysql_result($rs,0,'subname_ar');
$banner=mysql_result($rs,0,'banner');
$title_ar=mysql_result($rs,0,'title_ar');
$title_en=mysql_result($rs,0,'title_en');
$side_right=mysql_result($rs,0,'side_right');
$side_left=mysql_result($rs,0,'side_left');
$body=mysql_result($rs,0,'body');
$order=mysql_result($rs,0,'order');
$key_en=mysql_result($rs,0,'meta_key_en');
$key_ar=mysql_result($rs,0,'meta_key_ar');
$desc_en=mysql_result($rs,0,'meta_desc_en');
$desc_ar=mysql_result($rs,0,'meta_desc_ar');
$images=mysql_result($rs,0,'images');
$text_en=mysql_result($rs,0,'text_en');
$text_ar=mysql_result($rs,0,'text_ar');


?>
<center>
<form action="index.php?page=sub&op=edit&subid=<?=$subid?>"
method="POST" enctype="multipart/form-data" >
<center>Back</center>


<table border="1" align="center" cellpadding="5" cellspacing="0"
bordercolor="#FFFFFF" bgcolor="#F2F2F2">
<tr>
<td width="150">Name_en :</td>
<td width="200"><input name="subname_en" value="<?=$subname_en?
>" /></td>
<td width="5"> </td>
<td width="150">Name_ar :</td>
<td width="200"><input name="subname_ar" value="<?=$subname_ar?
>" dir="rtl" /></td>
</tr>

<tr>
<td width="150" height="35">Title_en: </td>
<td width="200"><input name="title_en" id="title_en" value="<?=
$title_en?>"></td>
<td width="5"> </td>
<td width="150">Title_ar: </td>
<td width="200"> <input name="title_ar" id="title_ar" value="<?
=$title_ar?>" ></td>
</tr>
<tr>
<td width="150">order </td>
<td width="200"> <input name="order" value="<?=$order?>"></td>
<td width="5"> </td>
<td width="150">Banner:</td>
<td width="200"><input name="banner" id="banner" value="<?=
$banner?>" /></td>
</tr>

<tr>
<td width="150">HTML Right : </td>
<td width="200"><input name="side_right" value="<?=
$side_right?>" /> </td>
<td width="5"> </td>
<td width="150">HTML Left : </td>
<td width="200"> <input name="side_left" value="<?=
$side_left?>" /></td>
</tr>

<tr>
<td width="150">KeyWords_en </td>
<td width="200"> <textarea name="key_en" cols=60 rows="5"
><?=$key_en?></textarea></td>
<td width="5"> </td>
<td width="150">KeyWords_ar </td>
<td width="200"><textarea name="key_ar" cols=60 rows="5"
><?=$key_ar?></textarea> </td>
</tr>

<tr>
<td width="150">Description_en </td>
<td width="200"> <textarea name="desc_en" cols=60
rows="5" ><?=$desc_en?></textarea></td>
<td width="5"> </td>
<td width="150">Description_ar </td>
<td width="200"><textarea name="desc_ar" cols=60 rows="5"
><?=$desc_ar?></textarea> </td>
</tr>

<tr>
<td width="150">Text_en :</td>
<td width="200"> <textarea name="text_en" cols=60
rows="5" ><? echo"$text_en"; ?></textarea></td>
<td width="5"> </td>
<td width="150">Text_ar : </td>
<td width="200"><textarea name="text_ar" cols=60
rows="5" ><? echo"$text_ar"; ?></textarea> </td>
</tr>

<tr>
<td width="150">Photo Gallery : </td>
<td width="200">Yes <input type="radio" name="images" <?
if($images==yes){echo'checked=checked';} ?> value="yes"> NO <input
type="radio" name="images" <? if($images==no){echo'checked=checked';} ?
> value="no"></td>
<td width="5"> </td>
<td width="150"> </td>
<td width="200"> </td>
</tr>
<tr>
<td colspan="5" align="center"> <input type="submit"
name="edit" value=" Edit "> </td>
</tr>
</table>



</p>
</form>
<?php
}




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"<center>Edit Successfully <a href=index.php?page=sub&op=browse>
Back </a></center>";
}


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"<center><font color=#FF0000 size=+3> There Are Sub Pages or
Images</font><br><br> <a href=javascript:history.go(-1)>Back</a></
center>"; return; }
echo"<center>Delete Successfully <a href=index.php?page=sub&op=browse>
Back </a></center>";
}



$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 ---------------
<?php

$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"<center>The worker has been added successfully.<a
href=index.php?page=new_worker&op=browse><br>Back</a></center>
";
}
?>
------------------
the problem that i can't insert the record to db
plz help me
im on fire
ghalyonline [ Mi, 16 April 2008 12:58 ] [ ID #1943870 ]

Re: problem with PHP

On 16 Apr, 10:58, ghalyonl... [at] 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.
Captain Paralytic [ Mi, 16 April 2008 13:04 ] [ ID #1943871 ]

Re: problem with PHP

ghalyonline [at] 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
--
alvaroNOSPAMTHANKS [ Mi, 16 April 2008 13:56 ] [ ID #1943873 ]

Re: problem with PHP

On Wed, 16 Apr 2008 03:58:32 -0700 (PDT), ghalyonline [at] 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
hellsop [ Mi, 16 April 2008 14:55 ] [ ID #1943875 ]
PHP » comp.lang.php » problem with PHP

Vorheriges Thema: Need a Good PHP developer
Nächstes Thema: problem with com and php