if exist

Gestart doorSmiegles1 reacties44 weergaven

2 berichten · pagina 1 van 1

Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
He,
ik ben bezig met een kladblok script
hoe zorg ik ervoor dat als er al een gebruiker met die naam is dat hij word geupdate en als hij nog niet bestaat dat hij een nieuwe aanmaakt?

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzend[/COLOR][COLOR= #007700]])
{[/COLOR]
[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * from users WHERE id="[/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]uid[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR] 
 [COLOR= #0000BB]$bericht[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]];[/COLOR]
 [COLOR= #0000BB]$ip[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]];[/COLOR]
  [COLOR= #0000BB]$naam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];[/COLOR]
 [COLOR= #0000BB]$save[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO kladblok(bericht, naam, ip) VALUES("[/COLOR][COLOR= #007700].[/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$bericht[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]", $naam, $ip)"[/COLOR][COLOR= #007700]);[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"in de database gezet"[/COLOR][COLOR= #007700];
                                 }[/COLOR]
?>

<form method="post">
<table>
  <tr>
    <td>
    <TEXTAREA type="text" cols="85" rows="12" value="bericht" name="bericht" id="bericht" /></TEXTAREA>
    </td>
    <td><br />
    <input type="submit" name="verzend" value="opslaan" />
    </td>
</table>
</form>
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Eerst een select:

SELECT 1 FROM tabel WHERE name = naam

En dan kijken of de num rows 1 is

Dan spreekt het voor zich....
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