Toon posts:

[php] selectbox werkt niet

Pagina: 1
Acties:
  • 103 views sinds 30-01-2008
  • Reageer

Verwijderd

Topicstarter
Ik zit even helemaal vast. Ik heb een pagina gemaakt waarbij er wat data in wordt gevoerd in de database. Nu heb ik daarbij ook zo'n vervolgkeuze lijst gemaakt, dus dat je kan kiezen tussen hardware of software in dit geval.

dit is het invoer gedeelte
code:
1
2
3
4
5
6
7
8
9
<?
   if ($cato == "h") {
    $h_cato = "SELECTED";
   }
   elseif ($cato == "s") {
    $s_cato = "SELECTED";
   }
?>
<SELECT NAME="cato"><OPTION VALUE="h" <? echo "$h_cato";?>>Hardware</OPTION><OPTION VALUE="s" <? echo "$s_cato";?>>Software</OPTION></SELECT><BR>

Klopt daar iets niet aan?

dit is de sql entry
code:
1
$sql = "INSERT INTO articles (id,content,title,name,bron,date,info,cato) VALUES ('','$content', '$title','$username_news','$bron','$tijd','$info''$cato')";

  • Life-is-party
  • Registratie: Oktober 2000
  • Laatst online: 14-02-2023
Geeft hij een foutmelding? Of heb je het nog nooit getest?

Acer TM661LMi - Intel Centrino 1,4 Ghz - 512mb ram - DVD-RW


  • goalgetter
  • Registratie: Juni 1999
  • Laatst online: 25-08 15:24
En wat gaat er fout? Of waar zit je vast?

Verwijderd

Topicstarter
Error while adding article. BackColumn count doesn't match value count at row 1

dat krijg ik bij invoeren.

Verwijderd

Topicstarter
Zal ik anders me hele script ff posten? het is niet zo heel groot hoor

  • goalgetter
  • Registratie: Juni 1999
  • Laatst online: 25-08 15:24
Ik denk dat het idd ietsje makkelijker is als je even wat meer code post.

Verwijderd

Topicstarter
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
begin_page ("Add article"); # Call function to start layout, the argument is the title 

if ($content && $bron && $title && $info && $cato) { # If the content and title are entered 

    connect_with_db(); # Connect with mysql db 

    $tijd = time();
    
    $sql = "INSERT INTO articles (id,content,title,name,bron,date,info,cato) VALUES ('','$content', '$title','$username_news','$bron','$tijd','$info''$cato')"; 
    $add_article = mysql_query ($sql); # inserting article 
    
    if (!$add_article) {  # if something went wrong while adding article 
      echo ("Error while adding article. <a href='javascript:history.go(-1)'>Back</a>"); 
      echo mysql_error();
    } 
    
    else { 
      echo ("Het bericht is succesvol geplaatst. <a href=index.php class='main'>Ga naar de Index.</a>"); 
    } 


} # end 'if ($content != 0 && $title != 0 && $bron != 0 && $info != 0 && $cato != 0)' 


else { # if nothin' is entered yet, write form 

    ?> <?
   if ($cato == "h") {
    $h_cato = "SELECTED";
   }
   elseif ($cato == "s") {
    $s_cato = "SELECTED";
   }
?> 
      <tr> 
        <td class="main"><b>Voeg nieuws toe</b></td> 
      </tr> 
      <tr> 
        <td class="main"> 
            <form method=post><b>Titel:</b><BR> 
              <input style='background: #dddddd; border-color: 003366; font-family: Verdana; color: 000000; border-width: 1; font-size: 12px; border-height: 1; border-style: solid' type="text" name="title" size=50 maxlength=50 value=<?php echo($title); ?>><BR><BR>
<b>Catogorie:</b><BR>            
<SELECT NAME="cato"><OPTION VALUE="h" <? echo "$h_cato";?>>Hardware</OPTION><OPTION VALUE="s" <? echo "$s_cato";?>>Software</OPTION></SELECT><BR>
<b>Bron:</b><BR> 
              <input style='background: #dddddd; border-color: 003366; font-family: Verdana; color: 000000; border-width: 1; font-size: 12px; border-height: 1; border-style: solid' type="text" name="bron" size=50 maxlength=100 value=<?php echo($bron); ?>><BR><BR>
              <b>Thx to?:</b><BR> 
              <input style='background: #dddddd; border-color: 003366; font-family: Verdana; color: 000000; border-width: 1; font-size: 12px; border-height: 1; border-style: solid' type="text" name="info" size=50 maxlength=100 value=<?php echo($info); ?>><BR><BR>
<b>Bericht:</b> <i>(POST BERICHT IN HTML!!)</i><BR> 
              <textarea style='background: #dddddd; border-color: 003366; font-family: Verdana; color: 000000; border-width: 1; font-size: 12px; border-height: 1; border-style: solid' name="content" cols=80 rows=20><?php echo($content); ?></textarea> 
              <br><br><input style='background: #dddddd; border-color: 003366; font-family: Verdana; color: 000000; border-width: 1; font-size: 12px; border-height: 1; border-style: solid' accessKey="s" type=submit value="Plaats het bericht"> 
            </form>

Dit is wel genoeg denk ik, hier staat alles in. Als ik dus alles heb ingevuld en ik druk op submit, dan krijg ik dus die error, en vult hij het niet toe aan de db.

  • goalgetter
  • Registratie: Juni 1999
  • Laatst online: 25-08 15:24
Error found :)
code:
1
'$info''$cato'

Even een komma ertussen zetten.

Verwijderd

Topicstarter
een hele dikke kus voor goalgetter!!!! het werkt!!!
erg stom dat ik het zelf niet gezien hebt! bedankt man!!!!

  • D2k
  • Registratie: Januari 2001
  • Laatst online: 31-08 10:19

D2k

BackColumn count doesn't match value count at row 1

dit betekend dus dat je aantal variabelen en het aantal database velden dat je hebt opgegeven niet klopt

Doet iets met Cloud (MS/IBM)


Verwijderd

Topicstarter
In de database wordt nu of "h" of "s" ingevoerd. Nu wil ik het dus uitlezen, en nu kan ik dus gewoon $cato doen, dan wordt er een H of een S getoond. Maar wat mijn wens nou is is dat als er een H staat dat het plaatje h.gif wordt getoond en als het S is dat plaatje s.gif wordt getoond.

Hoe doe ik dat?

  • Jelle Niemantsverdriet
  • Registratie: Februari 2000
  • Laatst online: 19:03
[img]"$cato.gif"[/img]

  • goalgetter
  • Registratie: Juni 1999
  • Laatst online: 25-08 15:24
Meer iets in de richting van:
code:
1
[img]"<?[/img]".gif>

of
PHP:
1
2
3
<?
echo "[img]'"[/img]";
?>

  • Jelle Niemantsverdriet
  • Registratie: Februari 2000
  • Laatst online: 19:03
Dat bedoelde ik idd, maar had het even beknopt opgeschreven ;)
Pagina: 1