Jump to content
php.lv forumi

kā caur formu INSERT...


edi

Recommended Posts

kā var caur formu ierakstīt db?

echo 'Pievienot jaunu lietotaju<br>
<form name="" action="" method="post">
Vards:<input name="Name" type="text" value=""><br>
Uzvards:<input name="Secondname" type="text" value=""><br>
Lietotajvards:<input name="username" type="text" value=""><br>
Parole:<input name="password" type="text" value=""><br>
<input type="submit" value="Send">
</form>

 

mysql_query (INSERT INTO `db`.`users` (`id`, `username`, `password`, `name`, `lastname`, `level`) VALUES ('$id', '$usernamme', '$password', '$name', '$lastname', '$level'));

ceru ka sapratāt ko vajag..

EDIT: laikam nepareizajā vietā topiku atvēru :D

Edited by edi
Link to comment
Share on other sites

Formas fails form.php

<?php
echo 'Pievienot jaunu lietotaju<br>
<form name="" action="insert.php" method="post">
Vards:<input name="name" type="text" value=""><br>
Uzvards:<input name="lastname" type="text" value=""><br>
Lietotajvards:<input name="username" type="text" value=""><br>
Parole:<input name="password" type="text" value=""><br>
<input type="submit" value="Send">
</form>';
?>

 

Formas datu fails insert.php

<?php
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
if(isset($_POST['level'])) { $level = 'admin'; }
else { $level = 'user'; }

$insert = mysql_query (INSERT INTO `db`.`users` (`username`, `password`, `name`, `lastname`, `level`) VALUES ('$usernamme', '$password', '$name', '$lastname', '$level'));

if($insert)
{ echo 'Dati pievienoti'; }
else { echo 'Dati nav pievienoti, jo: '.mysql_error(); }
?>

 

Nu vienkāršajā variantā, tas apmēram tā varētu izskatīties, tik nevaig aizmirst veikt datu pārbaudi pirms tiek insertoti datu bāzē,

kā arī paroles kriptēšnu un visas pārējās izvirtības, kas nepiecišamas pirms inserta ;)

Bet gan jau lielie PHP guru ar ko ieteiks!

Link to comment
Share on other sites

Formas fails form.php

<?php
echo 'Pievienot jaunu lietotaju<br>
<form name="" action="insert.php" method="post">
Vards:<input name="name" type="text" value=""><br>
Uzvards:<input name="lastname" type="text" value=""><br>
Lietotajvards:<input name="username" type="text" value=""><br>
Parole:<input name="password" type="text" value=""><br>
<input type="submit" value="Send">
</form>';
?>

 

Formas datu fails insert.php

<?php
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
if(isset($_POST['level'])) { $level = 'admin'; }
else { $level = 'user'; }

$insert = mysql_query (INSERT INTO `db`.`users` (`username`, `password`, `name`, `lastname`, `level`) VALUES ('$usernamme', '$password', '$name', '$lastname', '$level'));

if($insert)
{ echo 'Dati pievienoti'; }
else { echo 'Dati nav pievienoti, jo: '.mysql_error(); }
?>

 

Nu vienkāršajā variantā, tas apmēram tā varētu izskatīties, tik nevaig aizmirst veikt datu pārbaudi pirms tiek insertoti datu bāzē,

kā arī paroles kriptēšnu un visas pārējās izvirtības, kas nepiecišamas pirms inserta ;)

Bet gan jau lielie PHP guru ar ko ieteiks!

 

 

pats tiku atrak gala neka postu sagaidiju :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...