I am currently working on some php code using redbeanphp that should store data into database tables using four different R::store functions, but only the first two work, and I don't know why the other two aren't working because I made no spelling mistakes and if I try to do it with R::storeAll it also only works for the first two objects.
My code:
require "rb.php";
R::setup('mysql:host=localhost;dbname=building_framework', 'root', '');
// Books table
$books1 = R::dispense('books');
$books1->title = "Wonders of the world";
$books1->author_id = "1";
$books1->publisher_id = "1";
$books2 = R::dispense('books');
$books2->title = "Math for dummy's";
$books2->author_id = "1";
$books2->publisher_id = "1";
// Author table
$author = R::dispense('author');
$author->id = "1";
$author->author = "Francesco Boccia";
// Publisher table
$publisher = R::dispense('publisher');
$publisher->id = "1";
$publisher->publisher = "Metro Books";
$store1 = R::store($books1);
$store2 = R::store($books2);
$store3 = R::store($author);
$store4 = R::store($publisher);
echo $store1;
echo $store2;
echo $store3;
echo $store4;
When I execute it, all the tables are getting made, but only in the books table, data is stored and not in the other two. Can someone please help me fixing this?
I know my mistake. I added an id for author and for publisher but the id gets added by redbean itself, so there was no need for that.
Related
JoomlaTune - developers of the JComments extension - offers the following code to display comments anywhere:
<?php
$comments = JPATH_SITE . '/components/com_jcomments/jcomments.php';
if (file_exists($comments)) {
require_once($comments);
$options = array();
$options['object_id'] = $this->item->id;
$options['object_group'] = 'com_content';
$options['published'] = 1;
$count = JCommentsModel::getCommentsCount($options);
echo ('<span>'. $count .'</span>');
}
?>
by substituting the id of the article into $this->item->id you can get the number of materials for this article.
Is it possible to somehow adapt this code to display the number of comments left by specific users by his id. Or maybe this variable already exists somewhere in the component code?
Thanks a lot in advance!
all you need to do is add the following code:
use Joomla\CMS\Factory;
$user = Factory::getUser();
$options['userid'] = $user->id;
just before:
$count = JCommentsModel::getCommentsCount($options);
Im trying to populate the textboxes of a CRUD with the information obtained from a query. I use a stored procedure which already works.
I mainly want to give an ID, click search and populate the rest of the texboxes with the clients rest of information. The rest of the buttons already work so I think my problem is located in this section of code:
if(isset($_POST['btnBuscar']))
{
$opc = "buscar";
$idcliente = ($_POST['txtIdCliente']);
$nombre = ($_POST['txtNombre']);
$apaterno = ($_POST['txtApPat']);
$amaterno = ($_POST['txtApMat']);
$tel = ($_POST['txtTel']);
$email = ($_POST['txtEmail']);
$fecalta = ($_POST['txtFechaAlta']);
$query = "CALL sp_clientes('$opc',$idcliente,'$nombre','$apaterno','$amaterno',$tel,'$email','$fecalta')";
if(mysqli_query($con,$query)){
header("location:Clientes.php?searched=1");
this next part where I have doubts
($_POST['txtIdCliente']) = $reg['IdCliente'];
($_POST['txtNombre'])= $reg['Nombre'];
($_POST['txtApPat']) = $reg['APaterno'];
($_POST['txtApMat']) = $reg['ApMaterno'];
($_POST['txtTel']) = $reg['Telefono'];
($_POST['txtEmail']) = $reg['Email'];
($_POST['txtFechaAlta']) = $reg['FecAlta'];
}
Here is the example. you can achieve more by appending HTML in PHP
echo '<input type="text" style="background-color:blue" id="'.$_POST['txtNombre'].'" name="content'.$_POST['txtNombre'].'" value="'.$_POST['txtNombre'].'"></input>';
I have this php script.
$cwZ = count($wiegen_zutat);
$cwM = count($wiegen_menge);
$cwS = count($wiegen_schritt);
if($cwM == $cwS and $cwM == $cwZ and $cwZ == $cwS){
for($x = 0; $x < $cwZ; $x++){
$aktZuat = $wiegenZutat[$x];
$qr = "SELECT ID_Zutat FROM Zutaten WHERE Name='$aktZutat' LIMIT 1";
$id_get = mysqli_query($verbindung,$qr );
$id = mysqli_fetch_array($id_get);
$zuatenID = $id['ID_Zutat'];
echo $id['ID_Zutat'];
echo $zutatenID;
$sql3 = "INSERT INTO Wiegen (ID_Zutat, Menge) VALUES ('$zutatenID', '$wiegenMenge[$x]')";
$wiegenEintragen = mysqli_query($verbindung, $sql3);
}
}
$wiegen_zutat, _menge, _schritt are all three arrays which contain the information from my form.
I go through the first array, and check the variable against a table which contains the ingredients for my website. I want to get the id of a ingredient which was added some steps before and add it into another table.
The problem is that neither the echos or the query are working.
What am I missing?
Please don't get confused by the name of the variables, I'm german :)
Best regards
This is what im trying to do.. i got eprofile with a database. the database consist of 2 table which is personal_data and and nationality. 1st user can view thier old personal information then i gonna make update/edit page for them. Nationality is in other table because the nationality in dropdown menu. then the user can change thier personal and information, after they insert new information they clicking the submit button and go to process.php where update process for database occur. my problem is, i dont know how to define/or how to connect two table which is personal_data and nationality in the update query.
code for nationality
<?php
$query = "SELECT nationality_type FROM nationality";
$result = mysql_query ($query); ?>
<select name="personal_nationality" >
<?php while($row = mysql_fetch_array($result)){ ?>
<option value="<?php echo $row['nationality_type']?>" <?php if ( $personal_nationality == $row['nationality_type']){ ?> selected <?php } ?>>
<?php echo $row['nationality_type']?></option>
<?php }?>
</select>
process.php code
<?php
$host="localhost"; // test local
$username="lasadmin"; // Mysql username
$password="lasadmin"; // Mysql password
$db_name="eprofile"; // Database name
$db = mysql_connect($host, $username, $password);
$link = mysql_select_db($db_name,$db);
$personal_designation = $_POST['personal_designation'];
$personal_department = $_POST['personal_department'];
$personal_job_grade = $_POST['personal_job_grade'];
$personal_emp_group = $_POST['personal_emp_group'];
$personal_current_company = $_POST['personal_current_company'];
$personal_work_location = $_POST['personal_work_location'];
mysql_query("UPDATE personal_data SET personal_designation = '".mysql_real_escape_string($_POST["personal_designation"])."', personal_department = '".mysql_real_escape_string($_POST["personal_department"])."', personal_job_grade = '".mysql_real_escape_string($_POST["personal_job_grade"])."', personal_emp_group = '".mysql_real_escape_string($_POST["personal_emp_group"])."', personal_current_company = '".mysql_real_escape_string($_POST["personal_current_company"])."', personal_work_location = '".mysql_real_escape_string($_POST["personal_work_location"])."' WHERE LAS_login_id = '".mysql_real_escape_string($_POST["LAS_login_id"])."'");
$personal_full_name = $_POST['personal_full_name'];
$personal_title = $_POST['personal_title'];
$personal_date_birth = $_POST['personal_date_birth'];
$personal_marital_status = $_POST['personal_marital_status'];
$personal_nationality = $_POST['nationality_type'];
mysql_query("UPDATE personal_data SET personal_full_name = '".mysql_real_escape_string($_POST["personal_full_name"])."', personal_title = '".mysql_real_escape_string($_POST["personal_title"])."', personal_date_birth = '".mysql_real_escape_string($_POST["personal_date_birth"])."', personal_marital_status = '".mysql_real_escape_string($_POST["personal_marital_status"])."', nationality_type = '".mysql_real_escape_string($_POST["personal_nationality"])."' WHERE LAS_login_id = '".mysql_real_escape_string($_POST["LAS_login_id"])."'");
?>
when i trying to change the information(testing), this error is show
-Notice: Undefined index: nationality_type in C:\wamp\www\eprofile\process.php on line 26
this is code for line 26
$personal_nationality = $_POST['nationality_type'];
can u tell me what is the problem, and what is the solution for this problem? what should i do on defined index??
At first I would recommend to escape the content that you receive by the $_POST variables.
You don't need to copy it into extra variables. (Unless us use it for something different)
Second problem is that $LAS_login_id is not initialized, has no value, so your UPDATE statement won't update anything.
//simple update
mysql_query("UPDATE mytable SET
myvalue = '".mysql_real_escape_string($_POST["my_value"])."'
WHERE mycriteria = '".mysql_real_escape_string($_POST["my_criteria"])."'");
And there should be an array with nationality_type as index which is undefined too.
You have two problems...
THe first one is in your UPDATE sql query.
WHERE LAS_login_id= '$LAS_login_id'
Where did you find the $LAS_login_id ? You are not defining it anywhere that i can see...
The second problem is with your index nationality_type which you have not included in the code above...
Hope this helps
I am testing out the Redbean ORM. I like how it works, less work for me :) I am using the redbean books example, from their website. I have been able to create new books with authors and titles, and display them to the page with no problem. I added another dimension to learn how to link pages to my books.
I am able to add an entry into the book table, as well as add an entry into the page table using the following code:
----------- dbmgmt.php ---------------------------------
function AddNewBook($FORMINFO){
$newBook = R::dispense('book');
$newBook->title = $FORMINFO['title'];
$newBook->author = $FORMINFO['author'];
$newBook->create_date = R::isoDateTime();
$newPage = R::dispense('page');
$newPage->pagetext = $FORMINFO['pagetext'];
$newBook->ownPage = $newPage;
$id = R::store($newBook);
return R::load('book', $id);
}
Both tables show the proper entries (new ids and populated fields). However, I am having a hard time accessing the pagetext field from the page table. This is the code I have been using for that:
----------- dbmgmt.php ---------------------------------
function GetBooks($id){
if($id == ""){
return R::find('book');
}
else{
return R::find('book','id = ?', array($id));
}
}
----------- GetBooks.php ---------------------------------
$id = "";
if(isset($_GET['id'])){
$id = $_GET['id'];
}
$books = GetBooks($id);
$booklist = "";
foreach($books as $book){
$pagetext = "";
foreach($book->ownPage as $page){
$pagetext .= $page->pagetext; //Errors with "Notice: Trying to get property of non-object"
}
$booklist .= "<tr id='$book->id'><td><a class='linkEdit' href='edit.php?id=$book->id'><img src='http://cdn1.iconfinder.com/data/icons/ledicons/page_white_edit.png' /></a> <span class='book-title'>$book->title</span></td><td><span class='book-author'>$book->author</span></td><td><span class='page-text'>$pagetext</span></td></tr>";
}
echo $booklist;
------------------------------------------------------------
When I print_r($book->ownPage), I don't even see the page entry that I can clearly see in the page table via phpmyadmin. I have tried many different ways of accessing the pagetext field via my script above, but can't get anywhere with it.
Any insight would be most welcome. Otherwise I will have to try a different, albeit bigger and more cumbersome, ORM.
Thanks in advance.
I am not 100% sure as I haven't encountered this problem yet myself, but I am almost positive, $book->ownPage needs to be an array:
$newPage = R::dispense('page');
$newPage->pagetext = $FORMINFO['pagetext'];
$newBook->ownPage[] = $newPage;
$id = R::store($newBook);