[php]Hulp gezocht[php]

Gestart doorPropje14 reacties57 weergaven

15 berichten · pagina 1 van 1

Propje

Lid · Topicstarter

Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo one2xerzzzz,

ik zoek hulp ik heb zeg maar dit

mysql_query("INSERT INTO spaarrekening (geld, gebruiker) VALUES (".mysql_real_escape_string($_POST[geld]) .", " . mysql_real_escape_string($_SESSION[gebruiker]) . ") ") or die(mysql_error());


om een rij te maken alleen ik wil zeg maar als de gebruiker een rij hebt gemaakt dat er dan update moet komen dan

alleen weet niet hoe
0
Berichten
212
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
mysql_query("UPDATE spaarrekening SET geld=".mysql_real_escape_string($_POST[geld]) ." WHERE gebruik=" . mysql_real_escape_string($_SESSION[gebruiker]) ."") or die (mysql_error());


Zoiets?

Haal volgende keer eens een boek over mysql.
0
Propje

Lid · Topicstarter

Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
@tsam

dat snap ik ook wel maar ik wil zeg maar eerst insert into om een rij toe tevoegen en dan wil ik zeg maar update er in hebben
0
Propje

Lid · Topicstarter

Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
kijk heb zeg maar dit

mysql_query("INSERT INTO spaarrekening (geld, gebruiker) VALUES (".mysql_real_escape_string($_POST[geld]) .", " . mysql_real_escape_string($_SESSION[gebruiker]) . ") ") or die(mysql_error());      
           mysql_query("UPDATE spaarrekening SET geld=".mysql_real_escape_string($_POST[geld]) ." WHERE gebruiker=" . mysql_real_escape_string($_SESSION[gebruiker]) ."") or die (mysql_error());


alleen dat gaat niet lukken want nu maakt die weer een nieuwe rij en hij update maar dat moet niet
ik wil dat die 1 keer een rij maakt.
0
Berichten
212
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
update is om een rij te bewerken, maar als je de rij die je er net hebt ingezet wil bewerken kan je iets gebruiken als mysql_insert_id() die functie geeft het laatste id terug die in een tabel is gezet.
0
Propje

Lid · Topicstarter

Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
ik doe het op een session van een gebruiker

alleen hoe moet het met de id dan?

gwn zo?
$_SESSION[id]

maar dat gaat volgens mij niet werken?
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je moet via een SELECT checken of die user al een row heeft (met mysql_num_rows()) zoja, dan gebruik je de UPDATE query, anders de INSERT query
0
Propje

Lid · Topicstarter

Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
zo?

$aFouten = array();
    if($_POST[geld] == mysql_num_rows()))
      {
        $aFouten[] = Je hebt geen euro waarde ingevuld;
      }


als dat fout is kan je me het dan uitleggen waar het wel moet
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dat is dus nogal fout ja emoJe moet een query maken die in de tabel spaarrekening kijkt of er al iets staat van de user. Zoja dan doe je

if(mysql_num_rows($spaarrekening_check_query))
{
//HIER DE UPDATE QUERY
}
else
{
//HIER DE INSERT QUERY
}
0
Propje

Lid · Topicstarter

Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
ik krijg deze error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/werewolf/domains/antiverbod.nl/public_html/leden/test.php on line 27

[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR] [COLOR= #007700]&& ![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700]))
  {[/COLOR]
    [COLOR= #0000BB]$aFouten[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]geld[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700])
      {[/COLOR]
        [COLOR= #0000BB]$aFouten[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Je hebt geen euro waarde ingevuld[/COLOR][COLOR= #007700];
      }[/COLOR]
      
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aFouten[/COLOR][COLOR= #007700]) !=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
          {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De volgende fouten zijn opgetreden: <br /><br />[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/for"]for[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$Fi[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$Fi[/COLOR] [COLOR= #007700]<[/COLOR] [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aFouten[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #0000BB]$Fi[/COLOR][COLOR= #007700]++)
              {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$aFouten[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$Fi[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];
              }[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />Klik <a href="javascript:history.go(-1);">hier</a> om terug te keren[/COLOR][COLOR= #007700];
          }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
          [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$spaarrekening_check_query[/COLOR][COLOR= #007700]))
          {[/COLOR]
           
           [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE spaarrekening SET geld="[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]geld[/COLOR][COLOR= #007700]]) .[/COLOR][COLOR= #DD0000]" WHERE gebruiker="[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruiker[/COLOR][COLOR= #007700]]) .[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());                     
          }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
          [COLOR= #007700]{[/COLOR]
          [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO spaarrekening (geld, gebruiker) VALUES ("[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]geld[/COLOR][COLOR= #007700]]) .[/COLOR][COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruiker[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]") "[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());      
          }[/COLOR]
          
          [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De gegevens zijn succesvol opgeslagen in de database[/COLOR][COLOR= #007700];
          }
      
  }[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
  [COLOR= #007700]{[/COLOR]
?>
<form action="" method="POST">
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Weet je zeker dat je een spaarrekening wil starten?[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</br><br />[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Geld lenen: <input type="text" name="geld" value="">[/COLOR][COLOR= #007700];[/COLOR]
?>
<input type="submit" name="verzenden" value="Verzenden">
</form>
[COLOR= #0000BB]<?php[/COLOR]
  [COLOR= #007700]}[/COLOR]
?>
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
*facepalm*
Je moet wel die query makenemo
0
Propje

Lid · Topicstarter

Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
wtf ik maak toch al een query aan
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik bedoel de query waar er gecheckt wordt of de user al iets in die tabel heeft staan
0
Propje

Lid · Topicstarter

Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
zo toch?

in dat checken ben ik niet goed in daar moet ik nog wat van leren yummie
$getgebruiker = mysql_query("SELECT * FROM spaarrekening WHERE gebruiker = ".$_SESSION[gebruiker]."");
    $$spaarrekening_check_query = mysql_fetch_assoc($getgebruiker);
    if($spaarrekening_check_query[gebruiker] < $geld)
      {
        $aFouten[] = fout opgetreden.;
      }
0
Berichten
212
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Volgende keer je vraag wat duidelijker stellen.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren