Jump to content
php.lv forumi

echo "WTF"


FT3

Recommended Posts

Labdien te tada lieta kur man jaieliek kodu

echo "Neizdevas"

Lai vinu raditu kad nau aizpilditi input lauki ?

rekur kods !

<?function add(){ ?>

<form action="" method="POST" >
<table width="100%" cellspacing="3" cellpadding="0">
<tr><td><b>
title 1:
</b></td><td>
<input type="text" name="title1"></td></tr>
<tr><td><b>
title 2:
</b></td><td>
<input type="text" name="title2"></td></tr>
<tr><td><input type="submit" name="submit" value="Pievienot"></td><td>
</table>
</form>

<? } if ($_POST['submit']) { $title1 = $_POST['title1']; $title2 = $_POST['title2']; if (($title1 != "") && ($title2 != "")) { ?>

<b>Done!</b><? echo "<meta http-equiv='refresh' content='2;url=java script: history.go(-1)'>";

mysql_query("INSERT INTO titles (title1, title2) VALUES('$title1', '$title2') ") or die(mysql_error());

}}else{add();}

?>

 

Visska esmu meginajis bet neka nesanak ;/

Iepriekš paldies ! :)

Link to comment
Share on other sites

Kautkāds murgains tev tas kods...

 

bet te pavediens...

if($_POST['zaraza'] != '') {
  turpinam...
}
else {
  daram to kas jādara ja `zaraza` ir tukša...
}

Link to comment
Share on other sites

my eyes!!!!!!!

 

Saac ar koda struktureeshanu...un tavs echo 'Neizdevas' tur butu mazaka problema...shobriid vinju vari baazt visur un taapat shaubos, ka kaut kas straadaas kaa paredzeets...

 

Ak jaa - un es to visu dzeest un saaktu no 0...ieprieksh pamaacoties.

Edited by rATRIJS
Link to comment
Share on other sites

es kādreiz (tikai samērā neilgu brīdi) katru funkciju rakstīju vienā rindiņā. bet pēc tam pārdomāju un sapratu, ka tas ir mazliet par traku, un sāku rakstīt nedaudz plašāk pa vairākām rindiņām :))

 

iemesls par labu plašākai/izvērstākai koda raktībai bija lasāmība un loģisko bloku uztvere

vnk dažādi līkloči ir izieti ideālā koda meklējumos... ;)

Edited by 2easy
Link to comment
Share on other sites

Es pacentos (padariiju saprotamaaku arii):

 


<?php
/**
* Probleemas:
* - nosaukums neatbilst tam ko f-ja dara.
* - es neatbalstu f-jas, kas tikai izvada kaut ko HTML'iigu - tam ir templates.
*/
function add() {
?>
<form action="" method="POST" >
<table width="100%" cellspacing="3" cellpadding="0">
<tr><td><b>
title 1:
</b></td><td>
<input type="text" name="title1"></td></tr>
<tr><td><b>
title 2:
</b></td><td>
<input type="text" name="title2"></td></tr>
<tr><td><input type="submit" name="submit" value="Pievienot"></td><td>
</table>
</form>
<?php } ?>

<?php
if($_POST['submit']) {
/**
    * Probleemas ar sho rindinju:
    * - potenciaali biistama, jo netiek eskeipots strings, lai vinjsh nebuutu SQL injekciju ievainojams
    * - kapeec nosaukumaa ir 1?
    * - dabuusi E_NOTICE liimenja warning'u ja kaads nepados sho lauku
    */
$title1 = $_POST['title1'];
/**
    * Probleemas ar sho rindinju:
    * - tas pats ar SQL injekcijaam
    * - kapeec nosaukumaa ir 2? Neko neizsakoshi...
    * - tas pats par E_NOTICE
    */
$title2 = $_POST['title2'];

if(empty($title1) or empty($title2)) {
	echo 'Neizdevaas (no shit)!';
	add();
}
else {
	/**
     * Probleemas:
     * - SQL ievainojamiibas FTW
     */
	mysql_query("INSERT INTO titles (title1, title2) VALUES('$title1', '$title2') ") or die(mysql_error());
	/**
     * Kaada jeega izvadiit shaadu mazu tekstinju uz 2s? Vismaz uzstilot...
     */
	echo 'Done! (neticu)';
	/**
     * Probleemas:
     * - javascript raksta kopaa
     * - shis buutu jaaliek ieksh <head>. Neizskataas, ka tas buus ieveerots.
     */
	echo "<meta http-equiv='refresh' content='2;url=java script: history.go(-1)'>";
}
}
else {
add();
}
?>

Edited by rATRIJS
Link to comment
Share on other sites

2easy - vai tava 'perfektaja koda' ietilpst short tags?

ja ne tad es nedraudzesos ar tevi =D

 

es nez kapec, bet jau vairak ka pusgadu nevaru normali rakstit kodu, ja ir <?php .. ?>

man tas 'php' vislaik lec acis un trauce, tapec viss kods sastav no <?..?>

Teiksim iedomajamies shadu formu

 

<form method="<?php=$method?>"> action="<?php=$action?>">
Login:<br/>
<input type="text" name="<?php=$lname?>" value="<?php=$pname?>"/><br/>
Pass:<br/>
<input type="text" name="<?php=$lpass?>" value="<?php=$ppass?>"/><br/>
<input type="submit" name="<?php=$lsub?>" value="Okej"/>
</form>

 

kad ta vieta tu vari visu kautnedaudz samazinat un novakt to visu uzkritoshos <?php

 

<form method="<?=$method?>"> action="<?=$action?>">
Login:<br/>
<input type="text" name="<?=$lname?>" value="<?=$pname?>"/><br/>
Pass:<br/>
<input type="text" name="<?=$lpass?>" value="<?=$ppass?>"/><br/>
<input type="submit" name="<?=$lsub?>" value="Okej"/>
</form>

 

 

Jūsu domas par šo?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...