need help with my php code.

Im trying to make a form where it appears a lists of events so the user can chosee.
this events are inside a table and its supposed to record wich user chose wich event.

The query seems to work, I seem to have a problem with the radiobutton.
Please help me, im driving my self crazy

here`s the code :

[php]

<head>
	<title>	Inscribirse a un nuevo evento </title>
</head>
<body>

	<h1> Seleccione el evento al que se quiere inscribir  </h1>
	
	<?php
		$link = mysql_connect("localhost", "root");
			if ($link) {
						mysql_select_db("intranet_cpsi", $link);
						}
		$idlogin_user = 3 ; 
				
		
		$query= "select * from evento";
		$resultado= mysql_query($query,$link);
		
		$aux_cod_event =9 ;		
		//echo $aux_cod_event;
		
		//mysql_query("INSERT INTO usuario_evento VALUES('3','3')     ");
		echo " <table border = '1' ><tr><td>Codigo de evento</td><td>Comienzo</td><td>Fin</td><td>Costo</td><td>Nombre del evento</td><td>Seleccion de evento</td></tr>";
		echo " <form method = 'POST'> " ; 

		
	
		while($dato=mysql_fetch_array($resultado))
		{
			echo "<tr>";
			echo "<td>".$dato["cod_event"]."</td>" ;
			echo "<td>".$dato["comienzo"]."</td>"  ;
			echo "<td>".$dato["fin"]."</td>"  ;
			echo "<td>".$dato["coste"]."</td>"  ;
			echo "<td>".$dato["nombre_event"]."</td>" ;	?>
			
			
			<input type='radio' name='aux_cod_event'<?php if (isset($aux_cod_event) && $aux_cod_event == $dato["cod_event"] ) echo "checked"; ?> value = '$dato["cod_event"]'>  </td>" ;
			
			
			
			
		
		



			<?php
			echo "</tr>";
	
		}			
	 	echo "</table>";	
		
		echo $aux_cod_event."<br>";
	
		echo "<input type='submit' name='submit' value='Registrarme'/> " ;
		echo "</form>";
		
		
		if (isset($_POST['submit'])) 
		{
		    $aux_cod_event = $_POST['$aux_cod_event'];
			echo $aux_cod_event."<br>";

			mysql_query("INSERT INTO usuario_evento VALUES('$idlogin_user','$aux_cod_event')");
			mysql_close($link);
			echo 'Se ha registrado exitosamente ';
		
		}
		 
	?>
</body>
[/php]

Change:

[php] <input type=‘radio’ name=‘aux_cod_event’<?php if (isset($aux_cod_event) && $aux_cod_event == $dato["cod_event"] ) echo "checked"; ?> value = ‘$dato[“cod_event”]’> " [/php]

To:

[php] <?php if (isset($aux_cod_event) && $aux_cod_event == $dato[“cod_event”] ) {
echo “”
} else {
echo “”
};
[/php]

Im getting this error and I cant solve it. Im sorry for being such a newbiee with this,

Parse error: syntax error, unexpected ‘}’, expecting ‘,’ or ‘;’

Sorry about that, I forgot a few semi-colons; I program in .net where I don’t need to use semi-colons, so I always leave them off.

[php] <?php if (isset($aux_cod_event) && $aux_cod_event == $dato[“cod_event”] ) {
echo “”;
} else {
echo “”;
};
[/php]

Its still dosnt work. It does`nt record the entrys on the tables in the database.

Well at least it is not givingme the syntax error

I found the problem ! Its seems that I have the foreings keys as unique. But foreings keys does not necessary have to be unique ?.
I can only put the foreing keys as unique ! ! ! And that what`s fucking wrong with this

It’s hard to understand what you need, at first you said you had issues with the radio buttons working, so we recoded that section. It seems that maybe I missed understand, I thought perhaps you had issues with the radio button showing the values to the user to select from.

Now it sounds like, it always shown the values, and that it never saves the data to the database, because you have unique constraints.

If you can dump out the DLL to the tables in questions, we can most likely alter the table and fix that.

I realice that the radio button wasn´t working (still isn´t). So i´ve try to see if i could insert data in de table of the database. That`s when I realice that not only the radio button doesn´t work but the table where im supossed to record the data only takes the same entrys as one. I mean, it seems that I can´t set foreing keys if they are not unique and I don´t know how to solve that.
This is my database :

CREATE TABLE IF NOT EXISTS evento
(comienzo date NOT NULL,
fin date NOT NULL,
coste int(11) NOT NULL,
cod_event int(11) NOT NULL AUTO_INCREMENT,
nombre_event text NOT NULL,
PRIMARY KEY (cod_event),
UNIQUE KEY cod_event (cod_event)
) ENGINE=InnoDB

CREATE TABLE IF NOT EXISTS tramite
(fecha_emi date NOT NULL,
fecha_ven date NOT NULL,
pago int(11) NOT NULL,
costo int(11) NOT NULL,
idlogin_user int(11) NOT NULL,
cod_tramite int(11) NOT NULL,
PRIMARY KEY (cod_tramite),
UNIQUE KEY idlogin_user (idlogin_user)
) ENGINE=InnoDB

CREATE TABLE IF NOT EXISTS usuario
( idlogin_user int(11) NOT NULL AUTO_INCREMENT,
clave text NOT NULL,
tipo_user text NOT NULL,
nombre text NOT NULL,
apellido text NOT NULL,
mail int(11) NOT NULL,
PRIMARY KEY (idlogin_user)
) ENGINE=InnoDB

CREATE TABLE IF NOT EXISTS usuario_evento
(
idlogin_user int(11) NOT NULL,
cod_event int(11) NOT NULL
) ENGINE=InnoDB

ALTER TABLE tramite
ADD CONSTRAINT
tramite_ibfk_1 FOREIGN KEY (idlogin_user)
REFERENCES usuario (idlogin_user)
ON DELETE CASCADE ON UPDATE CASCADE;

idlogin_user and cod_event on table USUARIO and evento are supposed to be primary key making foreings keys in usuario_evento where in usuario_evento is supposed to take the data of wich user is subscribe to wich event.

And my php code is suppose to take a user, and list him all the events that he can subscribe to.

I am making any sense?
im not so good in english as im not good in php, haha.
Thanks a lot for helping me.

I think we are having a little language barrier…

Their seems to be nothing stopping you from inserting data into the table usuario_evento. It has no keys on the table.

Are you trying to add a foreign key to that table to enforce integrity and is that where you are having the issue?

Thank youuu soooo much ! Ill try modifing my database and now thw code works perfect ! ! Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service