Hi!
I'm developing a form with a external database. The primary key is id ,but we have another field, dni (identity card) and is unique.
I need check if that person inserted in my database was already inserted or not.
How I can check it? I'm beginner in Joomla.
Thank you!
Bye!!
I'm developing a form with a external database. The primary key is id ,but we have another field, dni (identity card) and is unique.
I need check if that person inserted in my database was already inserted or not.
How I can check it? I'm beginner in Joomla.
Thank you!
Bye!!
Hi BN,
Should I have a custom code before or after DB SAVE?
Don't I need reading my database?
And, do you have a code example?
Thank you for your answer!!
Should I have a custom code before or after DB SAVE?
Don't I need reading my database?
And, do you have a code example?
Thank you for your answer!!
Hi hv,
I would switch the db save for a custom action, so I'll do it with some like:
(p.s. I'm assuming that your user is logged)
I dind't test the code, so please, test it and debug if needed.
BN
I would switch the db save for a custom action, so I'll do it with some like:
(p.s. I'm assuming that your user is logged)
<?php
$user = JFactory::getUser();
$con=mysqli_connect("server, "username",
"password", "databasename");
// Check connection
if (mysqli_connect_errno())
{
echo "Error: " . mysqli_connect_error();
}
$userExists= mysqli_query($con,"SELECT * FROM
"tablename" WHERE dni=".$user->get("id")."");
if (!$userExists) {
$query= mysqli_query($con,"INSET INTO "tablename" ('dni', 'field1', 'field2', 'field3', 'field4', 'fieldN') VALUES ('".$user->get("id")."',"".$form->data["field1"]."","".$form->data["field2"]."","".$form->data["field3"]."","".$form->data["field4"]."","".$form->data["fieldN"]."")");
}
?>
I dind't test the code, so please, test it and debug if needed.
BN
BNDragon
Good idea, but you can use "Event Switcher", custom Code for check if already exist the user with the Joomla API for less code.
In success option, you load the action "DB Save" and de Fail Option you load the action "Event Loop"
See the image http://prntscr.com/5esdgc
Try, good day
Good idea, but you can use "Event Switcher", custom Code for check if already exist the user with the Joomla API for less code.
$db = JFactory::getDbo();
$user = JFactory::getUser();
$query = $db->getQuery(true);
$query= 'SELECT * FROM #__tablename WHERE id='. $user->get("id");
$db->setQuery($query);
$db->query();
$num_rows = $db->getNumRows();
if ($num_rows==0){
return "success";
}else{
return "fail";
}
In success option, you load the action "DB Save" and de Fail Option you load the action "Event Loop"
See the image http://prntscr.com/5esdgc
Try, good day
This topic is locked and no more replies can be posted.