How to populate html texbox with mysql query? - php

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>';

Related

RedBeanPHP: Only first two store functions work

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.

How to insert two variable value into single field in php?

code:
<?php
if(isset($_POST['add_new']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$field = $_POST['field'];
$message = $_POST['message'];
$comment1 =array($_POST['comment1'],$s_date);
$comment2 = $_POST['comment2'];
$status = $_POST['status'];
$s_date = date('Y-m-d');
$interested_in = $_POST['interested_in'];
$academic_details = $_POST['academic_details'];
$city = $_POST['city'];
$sql = "insert into enquires2(name,email,phone,field,message,comment1,comment2,status,s_date,interested_in,academic_details,city,admin_idd)values('$name','$email','$phone','$field','$message','$comment1','$comment2','$status','$s_date','$interested_in','$academic_details','$city','$admin_id')";
$result = mysqli_query($link,$sql);
if($result == true)
{
$msg .= "<p style='color:green;'>You are successfully add new enquiry</p>";
}
else
{
$msg .= "<p style='color:red;'>Error!</p>";
}
}
?>
In this code I want to pass two value in single variable i.e.
$comment1 = array($_POST['comment1'],$s_date);
which show (array) when I print query ($sql). How can I pass two value into single variable ? please help me.
Another option if you don't want to concatenate , use serialize function make an associative array and serialize it and store to db
for example :
$comment1 =serialize(array("comment"=>$_POST['comment1'],"date"=>$s_date));
and when you get form db ,just use
$data = unserialize($yourDataFromDb);
and you get your values like
$data["comment"] // Your comment
$data["date"] // your date
Simply use concatenation
$comment1 = $_POST['comment1'] . $s_date;
But if you want to parse later and keep sepration between comment and date you can use any format like
$comment1 = $_POST['comment1'] . "--date--" . $s_date;
Later you can simply use print_r (explode("--date--",$str));
Something like multivalue field.
You already record the value of $s_date in a separate "date" field, so there's no need to record it again within the comment field.
If you want to combine them for display or reporting purposes later on, then you can easily do that in the object or UI layer using simple string concatenation. I would advise you not to do this when storing the data as you're attempting - otherwise you're just duplicating the same value twice in the row for no obvious reason, as well as making it more difficult to separate what the user actually wrote from the date you inserted into it.

I'm trying to make update process page for my eprofile web

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

Why do I get "Null" in MySQL database? Flash pro cs6

I'm trying to update a flash movie quiz that records names and question answers - I did not write the original application. The quiz works, except that it replaces the name with null when recording data. All the other records work fine. I have deleted out the res2 - res12 just to shorten it up, they all work well.
Im using Flash Pro CS6
The code is in AS3
Thanks in advance for any light you can shed on this.
From Name input page of the quiz. participname is the text field input:
stop();
btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {
var Name:String=participname.text.toString();
gotoAndPlay(3);
});
From the last page of the quiz
sendData();
function sendData(){
var messages:URLRequest = new URLRequest("./insertresult.php")
messages.method = URLRequestMethod.POST
var posts:URLVariables = new URLVariables()
posts.Name = Name
posts.DateCurrent = dtFormatted
posts.Res01 = res01
messages.data = posts
trace(posts);
var loader:URLLoader = new URLLoader()
loader.dataFormat = URLLoaderDataFormat.TEXT
// loader.addEventListener(Event.COMPLETE, dataOnLoad)
loader.load(messages)
trace(messages);
From the insertresult.php:
<?php
//Capture data from $_POST array
$name = $_POST['Name'];
$date = $_POST['DateCurrent'];
$res1 = $_POST['Res01'];
/* if(!$name ) {
echo "no input using default values <br>";
$name = 'deleteme';
}*/
$connect = mysql_connect("mydatabase");
mysql_select_db ("PAlogindatabase", $connect);
$result = mysql_query("INSERT into rhymeoddity1 (name,date,res1) values ('$name','$date','$res1')");
if($result) echo "writing=Ok&";
else echo "writing=Error";
?>
Can you check that the actionscript is actually reading and setting the Name properly before posting the data?
I sorted out the problem, i believe that this bit of the code was hiding away the var myname
stop();
btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {
var myname:String=participname.text.toString();
gotoAndPlay(3);
}
);
i have replaced this with this and it is working fine now.
stop();
var myname:String = "";
btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {
myname = participname.text;
gotoAndPlay(3);
}
);
If someone can explain what the difference is so i can understand

get data from sql and show on specific location

I m using the following query to get data from sql :
$query = mysql_query($sql);
while($row = mysql_fetch_array($q))
{
$url = ''.$row['a'].' '.$row['b'].' '.$row['c'].' '.$row['d'].'<br>';
}
now i want to do replace {URL} (that is writen in html file ) with data from sql
$mtheme = str_replace("{URL}",$url,$mtheme);
echo $mtheme;
the problem i that it shows only last row
$url .= ''.$row['a'].' '.$row['b'].' '.$row['c'].' '.$row['d'].'<br>';

Categories