Autor | Zpráva | ||
---|---|---|---|
hrubos Profil |
#1 · Zasláno: 26. 11. 2006, 11:57:27
hi,
Plz, show me how to do if I want to insert id_reservation into database when user clik to radiobutton.In my dtabase id_resrevation is primary key and auto_increment I have written but not run //class interface <html> <body> <form method = "POST" action = "data.php"> <p> <input type="radio" name="id_reservation" />Rezervace</p> <p> <input type="submit" value="Submit" name="submit"> </p> </body> </html> //class to insert into database <html> <body> <?php $id_reservation = $_POST['id_reservation']; if(!get_magic_quotes_gpc()) { $id_reservation = addslashes($id_reservation); } @ $db = mysql_connect("localhost", "root","ha1985") or die("Error"); mysql_select_db("kolej",$db) or die("Can't choose database"); $query = "insert into reservation " . "(id_reservation) values" . "('$id_reservation')"; mysql_query($query); ?> </body> </html> |
||
esemeska Profil |
#2 · Zasláno: 26. 11. 2006, 12:27:28
<input type="radio" name="id_reservation" value="xxx" />
|
||
Aesir Profil |
#3 · Zasláno: 26. 11. 2006, 12:32:39
hrubos:
You trying to insert a string (type="radio" sends "on" if selected) to integer column (if id_reservation is auto_increment). |
||
hrubos Profil |
#4 · Zasláno: 26. 11. 2006, 13:36:59
I tried but in my database nothing was inserted(After cliking to radio button, in database there are id_reservation, detail is number , from 1 to....)
Plz help me change this code. Where do I have mistake??? |
||
peta Profil |
#5 · Zasláno: 26. 11. 2006, 18:57:34
hrubos
http://www.mysql.com/ http://www.volny.cz/peter.mlich/www.htm#msub13 # peter-mlich.wz.cz PHP minichat (5k 1 soubor) (POST,SESSION) # www.volny.cz/peter.mlich (zdroj: minichat.txt) # www.volny.cz/peter.mlich (zdroj: minichat.sql) I use: error_reporting(E_ALL); if ($r["id"]=="" && ($r["heading"]!="" || $r["content"]!="")) { $x = array(); $y = array(); $r["id"] = ""; foreach($r as $key => $value) {$x[]="`$key`"; $y[]="'$value'";} $data1 = implode(",",$x); $data2 = implode(",",$y); $dotaz = "INSERT INTO $tab ($data1) VALUES ($data2)"; mysql_query($dotaz) or die("<hr>Err add: $dotaz<hr>".mysql_error()); } Try echo $query; ? Try write SQL error? Try print_r($_POST) ? Try add webpage for test? Try use name="idreservation", not "_". Problem 1: Viz esemeska, where you have INPUT value=""? <input type="radio" name="id_reservation" value="xxx" /> "id_reservation is primary key and auto_increment" That is problem2 , maybe. You cannot INSERT data, if autoincrement exist. Viz Aesir From problem 1, you have $id_reservation = $_POST[...] = "checked"; , you try insert as autoincrement value. |
||
hrubos Profil |
#6 · Zasláno: 27. 11. 2006, 00:16:29
okei, but I have tried.Now I have problem.
In database there is table Resrevation,contains rows id_reservation, id_student. If I insert id_resrevation into databse by cliking radio button, I will have error " Field 'id_student' doesn't have a default value". If table contains only one row, it will be inserted well. So hepl me, plz.... this code here : //class interface <html> <body> <form method = "POST" action = "data.php"> <p> <?php $i; <input type="radio" value= "$i"name="id_reservation" />Rezervace</p> ?> <p> <input type="submit" value="Submit" name="submit"> </p> </body> </html> //class to insert into database <html> <body> <?php $id_reservation = $_POST['id_reservation']; if(!get_magic_quotes_gpc()) { $id_reservation = addslashes($id_reservation); } @ $db = mysql_connect("localhost", "root","ha1985") or die("Error"); mysql_select_db("kolej",$db) or die("Can't choose database"); $query = "insert into reservation " . "(id_reservation) values" . "('$id_reservation')"; mysql_query($query); ?> </body> </html> |
||
peta Profil |
#7 · Zasláno: 27. 11. 2006, 13:46:42 · Upravil/a: peta
... I will have error " Field 'id_student' doesn't have a default value" ...
SQL error, no PHP -> Problem is in SQL Please, if you doing SQL table, do file as this: -- DROP TABLE IF EXISTS minichat_banned; -- DROP TABLE IF EXISTS minichat_room; CREATE TABLE minichat_banned ( ip varchar(15) NOT NULL default '', PRIMARY KEY(ip) ) TYPE=MYISAM; -- ) TYPE=MyISAM COLLATE cp1250_general_ci; CREATE TABLE minichat_room ( id int(11) NOT NULL AUTO_INCREMENT, nick1 varchar(16) default NULL, nick2 varchar(16) default NULL, type int(11) default NULL, date datetime NOT NULL default '0000-00-00 00:00:00', text varchar(255) default NULL, ip varchar(15) NOT NULL default '', PRIMARY KEY(id), KEY (nick1), KEY (nick2), KEY (type) ) TYPE=MyISAM; -- ) TYPE=MyISAM COLLATE cp1250_general_ci; Your problem is: type int(11), I use: type int(11) default NULL, Try - run PHPMyAdmin - table "kolej" - edit table structure - field "id_student" - set default value as NULL or "" from my PHP admin other example: "ALTER TABLE `adresar_banned` CHANGE `ip` `ip` VARCHAR( 15 ) DEFAULT 'aaa' NOT NULL" ... have you PHP my admin? I have EasyPHP 1.8 (apache+PHP+MySQL+PHPMyAdmin) I must click right button on small icon in task-bar window - select Administration - select Manage (autologon) now is running PHPMyAdmin (free PHP program for MySQL administration) |
||
Časová prodleva: 17 let
|
Toto téma je uzamčeno. Odpověď nelze zaslat.
0