Retriving a row from database for suggestions - php

I have a form which will input data from database and print it. Now at the customer name, i want an autosuggestion from the list of customer which are already in database. Eg when i start typing it should start suggesting the list of customer names which are stored in database. This is my current code for that text box.
<td valign="top"><div align="right">Enter Customer Name :</div></td>
<td valign="top"><div align="left">
<input name="customername" class="gentxt" id="customername" maxlength="50" type="text" value="<?php echo $customername; ?>" >
</div></td>

http://www.coderiddles.com/codeigniter-fetch-data-from-database/
Go through this link you will get idea how to retrieve the data form database
Happy Coding :)

Related

How to get a MySQL field's content with PHP?

I've been working on my website's database and I had this problem recently:
I want the user to read a field of a row, when another field of the same row is submitted.
I.e:
user_id=1 user_name=Fran user_pass=Potato referedby_id=0 referedby_name=empty
When going inside www.website.com/form.php?referedby_id=1
I want the user to see "So, Fran refered you?"
I've been learning php and I decided to try this:
$referedbyid = mysqli_real_escape_string($con,$_POST["referedby_id"]); //In this case it's 1 because of the url
$sel_referedbyname = "select user_name from users where user_id='$referedbyid'"; //Then this should be the select of the user_name "Fran"
$run_referedbyname = mysqli_query($con, $sel_referedbyname); //Then a query for that select
$check_referedbyname = mysqli_fetch_field($run_referedbyname); //And this one the content of the query's result
$refername = $check_refername->user_name; //As the query result is an object I want to convert it to text
if(isset($_POST["register"]) && $check_user == 0 && $check_email == 0 && $pass == $pass2){ //If everything is right and the user/email does not already exist
mysqli_query($con,"INSERT INTO users (user_name, user_email, user_pass, refer_id, refer_name) VALUES ('$user', '$email', '$pass', '$referid', '$refername')"); //It's submitted to the database with the other values.
mysqli_close($con); //And we finish the connection with the db.
The problem is that when I try this and check the database, the referedby_name field is empty. Is it a syntax error? Or is this because it didn't convert to text properly?
In case $referedbyname is not text, how can I convert it properly? Is this because I'm using the fetch_field function wrong?
Additional info: $referedbyid is being called properly (I think) in a POST form with this html
<form action="register.php" method="post" onsubmit="validate();">
<table width="500" align="center" bgcolor="skyblue">
<tr align="center">
<td colspan="3"><h2>Registrarse</h2></td>
</tr>
<tr>
<td align="right"><b>Nombre de usuario:</b></td>
<td><input type="text" name="user" required="required"/></td>
</tr>
<tr>
<td align="right"><b>Email:</b></td>
<td><input type="email" name="email" required="required"/></td>
</tr>
<tr>
<tr>
<td align="right"><b>Contraseña:</b></td>
<td><input type="password" id="pass" name="pass" required="required"/></td>
</tr>
<tr>
<td align="right"><b>Verificar contraseña:</b></td>
<td><input type="password" id="pass2" name="pass2" required="required"/></td>
</tr>
<tr align="center">
<td colspan="3">
<input type="hidden" name="referedby_id" value="<?php echo $_GET["referedby_id"]; ?>"/>
<input type="submit" name="register" value="Registrarse"/></td>
</tr>
</table>
</form>
I don't know why the downvotes, I tried to be as clear and specific as I could...
Anyways, if someone else has any trouble finding the value of a specific field just use mysqli_fetch_assoc(mysqli_query($conect, $select))['name of the sql field']
mysqli_fetch_field($result) will only show you information about the field, like the type of input, name of the table, name of the column, etc.
Hope that's useful for someone with the same issue. Bye.

Wordpress: additional meta data for user

I would like to add user data when registering, like middle name and many others.
I have found that I can add it to wp-includes/user.php in function _get_additional_user_keys and add them to $keys, but when user edit his profile, and submit changes, that data is not saved in database, and that meta is empty.
Does anyone know what else should I do?
Thank you
edit:
in \wp-admin\user-edit.php, i have added:
<tr>
<th><label for="last_name2"><?php _e('Middle name') ?></label></th>
<td><input type="text" name="last_name2" id="last_name2" value="<?php echo esc_attr($profileuser->last_name2) ?>" class="regular-text" /></td>
</tr>
and now in my db I got meta_key without value in table wp_usermeta
Dorijan

how to validate the text fields related to each other in a form

I have a form that has many text fields. Among them I have an issue with textfields (seating area and price). They can me added more and more according to the user clicks.
Here are my conditions:
1 - if (either of them) seating area textfield is empty or the price textfield is
empty the form should not be submitted.
2 - I have already used jquery plugin to validate some text fields but not all.
3 - As the field(seating area and price are related to each other in my condition
I have used their name as array to post all the value in array like:
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
4 - and whenever the user clicks add more the table row is inserted with fields
5 - I have not validate these fields(fldSeatingarea[] and fldPrice[])
6 - User must put value to both field of same row or to none of same tbl row.
SO my question is: how am I gonna find either of the two fields (fldSeatingarea[] and fldPrice[]) of the same table row are not empty when the form is submitted?
If either of the fields of same table row is empty the form should not be submitted.
I am doing this small experiment using html, php, and a little bit of javascript.
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea_1">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice_2">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea_2">
</td>
<td>
<input type="text" name="fldPrice" id="fldPrice_2">
</td>
</tr>
Use Id's Like this to reference the fields for validation.. otherwise it will not work.
I don't particularly agree with how you have used IDs on your form. I would keep a JS array variable to indicate the selected seating areas, while you populate the form.
Then you can change the ID of the element to be fldSeatingarea_3 or fldSeatingarea_5 and target both area and price elements by looping through the array for (var n in selection) { //check the 'fldSeatingarea_'+n field }
if you wana concept than you can do it with parent and child concept through jquery
what you have to do find all tr in table and than for each tr find their fldSeatingarea[] and fldPrice[]
after it validate it if you find both are empty return false for submit event
here are some link which may help you more for it
http://api.jquery.com/child-selector/
http://api.jquery.com/parent/
Just my opinion
After submiting the form all the field(fldSeatingarea[] and fldPrice[])
is passed in an array.both of them..
You can used count to compare the how many value are inserted and how many fields are added and if they ddon`t have the same value the form will triger and not submit unless they have the same value.

How to handle a dynamic table with dojo.query()

This is going to be a meaty question because I am not sure the best way to handle this.
I have a page that contains a number of dojo inline editors, to allow users to change values, when one entry had been changes a save button will appear to prompt the user to save the information.
The page has a number of rows, contained within DIV tags, which relate to a row in a database table.
<?php if($this->userjobdetails != null) : ?>
<?php foreach($this->userjobdetails as $employment) :?>
<div id="employ_<?php echo $this->escape($employment['historyid']);?>">
<table class="employment-table">
<tr>
<td><Strong>
<span dojoType="dijit.InlineEditBox" editor="dijit.form.TextBox" onchange="markEmploymentForUpdate();" id="cmpy_<?php echo $this->escape($employment['historyid']);?>"><?php echo $this->escape($employment['employername']);?></span>
</Strong>
</td>
<td align="left"><input dojoType="dijit.form.FilteringSelect" store="rolestore" searchAttr="name" name="role" id="roleInput_<?php echo $this->escape($employment['historyid']); ?>" value="<?php echo $this->escape($employment['jobrole']);?>"></td>
<td align="left">
<span dojoType="dijit.InlineEditBox" editor="dijit.form.TextBox" onchange="markEmploymentForUpdate();" id="jtitle_<?php echo $this->escape($employment['historyid']);?>"><?php echo $this->escape($employment['jobtitle']);?></span>
</td>
<td width="15px;">
<input type="hidden" value="<?php echo $this->escape($employment['historyid']);?>" name="employid" id="employid_<?php echo $this->escape($employment['historyid']);?>"/>
<img src="<?php echo $this->baseUrl();?>/images/site/msg/small/msg-remove-small.png" border="0" onmouseover="this.style.cursor='pointer';" onclick="removeEmployer('emply_<?php echo $this->escape($employment['historyid']);?>')"/>
</td>
</tr>
</table>
</div>
<?php endforeach;?>
When the user 'saves' the page I want to then using dojo.xhrPost post the data for the elements on the page, so that the database rows are updated.
How would I go about this, having multiple 'rows'??
Thanks
Take a look at dijit.form.Form — the second example shows how to validate a form and do whatever actions you like when user submits it. AFAIK, dijit.form.Form doesn't care how many fields it has, and collects them dynamically.

connection textfield and html table with database

dear all..i have a textfield
<tr>
<td>
<td><input type="text" id="model_name"></td>
</td>
</tr>
and a cell
<tr>
<td><div id="value">//i want data show here after fill textfield</div>
</td>
</tr>
beside that, i've a table "settingdata" in database it consist of 2 field:itemdata and remark..
itemdata's value are "UD" and remark's value are "FM=87.5-108.0MHZ"...
what must i do if i want after type model name "car01UD" at textfield inside
<div id="value"></div>
can show "FM=87.5-108.0mhz"...
if you want "0103" + value of itemdata then do following
<input type="text" id="mod" value="0103<?PHP echo $itemdata ?>">
Looks like you are trying to do basic Ajax functionality. Consider reading some Ajax tutorials to get an idea how to do this.

Categories