0
Well, I’m trying to create a menu, and my sql is returning the following error: These are the results you’re picking up, so I gave an echo to see if it was going properly. Who we are is the name that identifies the menu, 2 is the code of who is the superior of it and 0 is the publication it is linked to. For min the error is in 0, because there is no post so it is 0, but 0 is a valid value to be a menu id. What is the right way to correct.
Quem Somos20
Cannot add or update a child row: a foreign key constraint fails (`jrcomunicacoes`.`tbl_MENU`, CONSTRAINT `FK00` FOREIGN KEY (`COD_PUBLI_VINCU`) REFERENCES `tbl_PUBLICACOES` (`COD_IDENT_PUBLI`) ON DELETE NO ACTION ON UPDATE NO ACTION)
When I am sending to the bank I do a validation, where I take the field and equals zero, if it is true it returns null, if it is false I return its value, however it is not working.
<div class="form-group">
<?php
$query = mysql_query("SELECT COD_IDENT_MENUX, TXT_DESCR_MENUX FROM tbl_MENU");
?>
<label>Superior:</label>
<select class="form-control" id="COD_IDENT_SUPER" name="COD_IDENT_SUPER" >
<option value="0" selected="selected">Menu Pai</option>
<?php while($menu = mysql_fetch_array($query)) { ?>
<option value="<?php echo $menu['COD_IDENT_MENUX'] ?>"><?php echo $menu['TXT_DESCR_MENUX'] ?></option>
<?php } ?>
</select>
</div>
My query is this:
$query = "INSERT INTO tbl_MENU (TXT_DESCR_MENUX, COD_IDENT_SUPER, COD_PUBLI_VINCU) VALUES";
$query .= "('$titulo','$pai','$publica')";
//executando a query
$inserir = mysql_query($query)
What part of your code are you entering? By error message you are wanting to change a record that is foreign key in another table.
– gmsantos
I switched to go null, but also continues the same message @gmsantos
– Renan Rodrigues
Renan probably this field of your table does not support nulls. It has the structure of her create ai ?
– gmsantos
Have not can I get ? I am using Mysql Workbench
– Renan Rodrigues
Right click on the table
Copy to Clipboard
>Create Statment
– gmsantos