update db met input radio

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Ruben Vanhoeyveld

Ruben Vanhoeyveld

24/10/2008 18:02:00
Quote Anchor link
Hallo, ik zou een kolom in mijn database willen updaten adhv welke radio is aangeduid. Hoe moet ik dit hier uithalen?


Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
<td width="146" align="left" class="submit"><INPUT TYPE="radio" name="style" title="Layout 1" value="style1" checked>Layout 1</td>
          <td width="146" align="left" class="submit"><INPUT TYPE="radio" name="style" title="Layout 2" value="style2">Layout 2</td>
          <td width="200" rowspan="2" align="center" class="submit"><strong>Binnenkort beschikbaar </strong></td>
        </tr>
        <tr>
          <td width="146" align="left" class="submit"><INPUT TYPE="radio" name="style" title="Layout 3" value="style3" disabled>Layout 3</td>
          <td width="146" align="left" class="submit"><INPUT TYPE="radio" name="style" title="Layout 4" value="style4" disabled>Layout 4</td>



Het zou iets in de aard van het volgende moeten zijn:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
$result
= mysql_query("UPDATE login SET style='/*!!!HIER ÉÉN VAN DE 4 STYLES!!!*/' WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'")
or die(mysql_error());?>
Gewijzigd op 01/01/1970 01:00:00 door Ruben Vanhoeyveld
 
PHP hulp

PHP hulp

25/04/2024 16:29:24
 
Auriorx

Auriorx

24/10/2008 18:05:00
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
$result
= mysql_query("UPDATE login SET style='".$_POST['style']."' WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'")
or die(mysql_error());?>



Je moet dan wel een formulier (<form>) toevoegen hè, maar misschien heb je die al?
 
Ruben Vanhoeyveld

Ruben Vanhoeyveld

24/10/2008 18:07:00
Quote Anchor link
Bedankt, ik probeer het eens uit...
 
Noppes

Noppes

24/10/2008 18:07:00
Quote Anchor link
En nu de relevante code! dus de formafhandeling welke normaliter begint met
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
<?php
if ($_SERVER['REQUEST_METHOD\]=='POST'
    isset($_POST['
....']) &&  trim($_POST['....']) != '') {

}

?>
 
Ruben Vanhoeyveld

Ruben Vanhoeyveld

24/10/2008 18:09:00
Quote Anchor link
Ik heb nu:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
if(isset($_POST['layout'])){
$sql = "SELECT name FROM login WHERE layout='".mysql_real_escape_string($_POST['style'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$buddy_name = htmlspecialchars($row->name);
$style = htmlspecialchars($row->layout);

echo "Je hebt je layout aangepast";
$result = mysql_query("UPDATE login SET layout='".mysql_real_escape_string($_POST['style'])."' WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'")
or die(mysql_error());

$style = $_POST['style'];}
?>


Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
      <table width="500" border="0" align="center" cellpadding="0" cellspacing="2" class="table">
        <tr>
          <td colspan="3" align="left" class="head"><div align="center">Layout aanpassen </div></td>
        </tr>
        <tr>
          <td colspan="3" align="center" class="cell"><?php
          echo "Je hebt nu ".$style.".";?>
</td>
        </tr>
        <tr>
          <td width="146" align="left" class="submit"><INPUT TYPE="radio" name="style" title="Layout 1" value="style1" checked>Layout 1</td>
          <td width="146" align="left" class="submit"><INPUT TYPE="radio" name="style" title="Layout 2" value="style2">Layout 2</td>
          <td width="200" rowspan="2" align="center" class="submit"><input name="layout" type="submit" class="button" id="style" value="Verander" onFocus="if(this.blur)this.blur()" /></td>
        </tr>
        <tr>
          <td width="146" align="left" class="submit"><INPUT TYPE="radio" name="style" title="Layout 3" value="style3" disabled>Layout 3</td>
          <td width="146" align="left" class="submit"><INPUT TYPE="radio" name="style" title="Layout 4" value="style4" disabled>Layout 4</td>
          </tr>
      </table></td>


In de database staat een kolom layout waar een cijfer van 1 tot 4 in komt. Het is de bedoeling dat die daar in komt, door de layout te veranderen bij die radiobolletjes. Het lukt niet echt... Kan iemand zeggen waar het verkeerd gaat?

Is er nog iemand die kan helpen?
Gewijzigd op 01/01/1970 01:00:00 door Ruben Vanhoeyveld
 
Ruben Vanhoeyveld

Ruben Vanhoeyveld

24/10/2008 19:50:00
Quote Anchor link
Is er écht niemand?
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.