homers Posted November 15, 2009 Report Share Posted November 15, 2009 (edited) Tatad piemēram es atrodas http://*.lv/?p=cup&id=1 spiežu Pievienoties turnirā viss notiek labi, bet kad atrodos http://*.lv/?p=cup&id=2 spiežu pievienoties un tabulā pievienojas visa informācija tikai turnira_id parādas 1 Kas ir janomaina lai tabulā pievienotos pareiza turnira id ? Kods <?php if($_GET['p'] == 'cup' and isset($_GET['id']) and $_GET['id'] == $_GET['id'] and isset($_GET['go']) and $_GET['go'] == 'join'){ $tmt = mysql_query("SELECT * FROM komanda WHERE playera_id=$id"); if(mysql_num_rows($tmt) > 0){ $resultsas = mysql_query("SELECT * FROM komanda WHERE playera_id = $id") or die(mysql_error()); $ras = mysql_fetch_array($resultsas); $usera_team = $ras['nosaukums']; $komanda = $usera_team; $turnirs = $s['nos']; $t_idd = isset($_GET['id']); $statuss = "2"; mysql_query("INSERT INTO komandas_turnira(komanda, turnirs, turnira_id, status) VALUES('$komanda', '$turnirs', '$t_idd', '$statuss')"); echo "<script>alert('Tagad gaidi kamēr tavu komandu apstiprinās!');</script>"; echo '<meta http-equiv="refresh" content="0;url=http://lapa.lv/?p=cup&id='.$_GET['id'].'">'; }else{ echo "Tev nav komandas!"; } }else{ echo ""; } ?> Edited November 15, 2009 by homers Quote Link to comment Share on other sites More sharing options...
yuppio Posted November 15, 2009 Report Share Posted November 15, 2009 Ak, jel. 1) kas ir domāts iekš IF "$_GET['id'] == $_GET['id']" ? Iekš IF lieto &&, nevis and! 2) tev mainīgais $t_idd, ka tiek izveidots ar $t_idd = isset($_GET['id']) var saturēt tikai true/false (attiecīgi, kad liec datubāzē, tad true tiek saprasts kā 1). isset funkcijas atgriež true/false, tu iegūsti tikai vai vispār tāds mainīgais eksistē, nevis viņa vērtību, tev vajag tur $t_idd = (int)$_GET['id'], lai iegūtu id vērtību, ko iegūsti no GET parametra. 3) Vajadzētu arī pārbaudīt vai tāds padotais turnīrs vispār eksistē, jo pēc esošā varianta var pievienoties jebkāda turnīra ID, tikai pamainot GET parametru Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted November 15, 2009 Report Share Posted November 15, 2009 Nedaudz palabojot yuppio - && var aizstāt ar and :) Quote Link to comment Share on other sites More sharing options...
homers Posted November 16, 2009 Author Report Share Posted November 16, 2009 Pamainīju uz $_POST['join'] <?php if(isset($_POST['join'])){ $tmt = mysql_query("SELECT * FROM komanda WHERE playera_id=$id"); if(mysql_num_rows($tmt) > 0){ $resultsas = mysql_query("SELECT * FROM komanda WHERE playera_id = $id") or die(mysql_error()); $ras = mysql_fetch_array($resultsas); $usera_team = $ras['nosaukums']; $komanda = $usera_team; $turnirs = $s['nos']; $t_idd = isset($_GET['id']); $statuss = "2"; mysql_query("INSERT INTO komandas_turnira(komanda, turnirs, turnira_id, status) VALUES('$komanda', '$turnirs', '$t_idd', '$statuss')"); echo "<script>alert('Tagad gaidi kamēr tavu komandu apstiprinās!');</script>"; echo '<meta http-equiv="refresh" content="0;url=http://localhost/?p=cup&id='.$_GET['id'].'">'; }else{ echo "Tev nav komandas!"; } }else{ echo ""; } ?> Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted November 16, 2009 Report Share Posted November 16, 2009 Runa ir par šo vietu: $t_idd = isset($_GET['id']); Quote Link to comment Share on other sites More sharing options...
homers Posted November 16, 2009 Author Report Share Posted November 16, 2009 Un kas tur būtu nepareizs? Quote Link to comment Share on other sites More sharing options...
briedis Posted November 16, 2009 Report Share Posted November 16, 2009 Un kas tur būtu nepareizs? RTFM ko atgriež isset() Quote Link to comment Share on other sites More sharing options...
yuppio Posted November 19, 2009 Report Share Posted November 19, 2009 Nedaudz palabojot yuppio - && var aizstāt ar and :) Lietot var, bet tā ir sava veida izvirtība līdzīgi kā lietot alternatīvās IF sintakses u.c. Lietot protams var, bet koda lasāmībai un iespējamai koplietošanai ar kādu vēlams pieturēties pie plašāk lietotā standarta. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.