I am facing issue in my dynamic drop down function it not return values i am unable to find where i'm doing wrong.One more issue i am facing regarding this code is that it not open drop down according to menus i.e if i select USA as a country it not show related cities of USA it always show all cities of all countries please set my code i will be highly thankful to you.
function listcatagoery()
{
$query="select * from tblcountry";
$rs=mysqli_query($query);
$html ='<select name="listcatagoery" id="listcatagoery" onchange="submitme();">';
while($row = mysqli_fetch_array($rs))
{
if($cntid == $row['cnt_id'])
{
$html.='<option selected="selected"
value="'.$row['cnt_id'].'">'.$row['cnt_name'].'</option>';
}
else
{
$html.='<option
value="'.$row['cnt_id'].'">'.$row['cnt_name'].'</option>';
}
}
$html.='</select>';
return $html;
}
///////////////////// List sub-catagoery////////
function listsubcatagoery()
{
$query = "select * from tblcity";
$rs=mysqli_query($query);
$html='<select name="listsubcatagoery" id="listsubcatagoery">';
while($row = mysqli_fetch_array($rs))
{
$html.='<option value="'.$row['cit_id'].'">
'.$row['cit_name'].'</option>';
}
$html.='</select>';
return $html;
}
<div id="main">
<div id="right">
<h2>User Registration Here...</h2><br />
<form name="frmadd" id="frmadd" action="" method="post" enctype="multipart/form-data">
<table border="1" cellpadding="5" cellspacing="4" width="90%" align="center">
<tr>
<td>Full Name</td>
<td><input type=text name="textname" size="40" id="textname" required="required"></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="rdgender" value="male" size="10">Male
<input type="radio" name="rdgender" value="Female" size="10">Female</td>
</tr>
<tr>
<td>Email</td>
<td><input type=text name="textemail" size="40" id="textemail" required="required"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="textpass" size="40" id="textpass" required="required"><span class="first"></span></td>
</tr>
<tr>
<td>Country</td>
<td>
<?php echo $htmlcountry; ?>
</td>
</tr>
<tr>
<td>City</td>
<td>
<?php echo $htmlcity; ?>
</td>
</tr>
<tr>
<td>Telephone</td>
<td><input type="number" name="txttel" size="11" id="txttel" required="required"></td>
</tr>
<tr>
<td>Photo</td>
<td><input type="file" name="txtphoto" size="40" id="txtphoto"></td>
</tr>
<tr>
<td>Signin</td>
<td colspan="2" align="center"><input type="submit" name="btnadd" id="btnadd" value="SigIn Now" /></td>
</tr>
<tr>
<td align="center" colspan="2">
<?php echo $msg; ?>
</td>
</tr>
</table>
</form><br />
</div>
I am at the very basic level of coding and I need help regarding this. You can post other links if there are any, related to this thing.
I want to get values from database dynamically on selection of city drop down and set it in a text box.
Any help will be appreciated.!!
enter image description here
<tr>
<td>
<label>City</label>
</td>
<td>
<select id="state" name="city" class="form-control" >
<?php
$sql = "SELECT city FROM service_point GROUP BY city";
$sel = mysql_query($sql);
// output data of each row
while($row = mysql_fetch_array($sel)) {
$city=$row['city'];
?>
<option value="<?php echo $row['city'] ?>">
<?php echo $row['city']; ?></option>
<?php }?>
</select>
</td>
</select>
</tr>
<tr>
<td> </td>
</tr>
<?php
include('config.php');
$s_name="";
$address="";
$phone_no="";
$email="";
$cperson="";
$city="";
$id=$_POST['city'];
$sql = "SELECT * FROM service_point where city = $id'' ";
$query = mysql_query($sql);
echo $sql;
while($row = mysql_fetch_array($query)){
?>
<tr>
<td> Name Of Service Point</td>
<td><input type="text" name="name" value="<?php echo $row['s_name'];?>"/></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Address </td>
<td><textarea name="address" col="5" value="<?php echo $row['address'];?>"></textarea></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Phone No</td>
<td><input type="text" name="phoneno" value="<?php echo $row[' phone_no'];?>"/></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Email Id</td>
<td><input type="text" name="email" value="<?php echo $row['email'];?>"/></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Contact Person</td>
<td><input type="text" name="cperson" value="<?php echo $row['cperson'];?>"/></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td></td>
<td align="center"><input type="submit" name="submit" value="submit"/><td>
</tr>
</table>
<?php }?>
</form>
When I'm pasting dummy text from any website to my textarea it is not saving into MySQL server but sometimes it works correctly. I don't know why it is happening.
Here is my code:
<table align="center" border="10">
<form method="post" action="insert.php" enctype="multipart/form-data">
<tr>
<td>News Title</td>
<td><input type="text" name="title" /></td>
</tr>
<tr>
<td>Select Category</td>
<td>
<select name="cat">
<option>Select Your category</option>
<?php
include('db.php');
$query="select * from nav";
$run=mysql_query($query);
while($row=mysql_fetch_array($run)){
$m_id=$row[0];
$m_title=$row['m_title'];
echo "<option value='$m_id'>$m_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>News Image</td>
<td><input type="file" name="news_image" /></td>
</tr>
<tr>
<td>News Description</td>
<td><textarea cols="40" rows="10" name="desc"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="btn" value="Insert News"/> </td>
</tr>
</form>
</table>`
<?php
if(isset($_POST['btn'])){
$news_title=$_POST['title'];
$news_cat=$_POST['cat'];
$news_desc=$_POST['desc'];
$news_image=$_FILES['news_image']['name'];
$tmp_image=$_FILES['news_image']['tmp_name'];
if($news_title=='' || $news_cat=='' || $news_desc==''){
echo "<script>alert('Any of your field is Empty')</script>";
exit();
}
else{
move_uploaded_file($tmp_image,"../images/$news_image");
$insert_query="insert into pages(cat_id,page_title,news_image,page_desc) VALUES ('$news_cat','$news_title','$news_image','$news_desc')";
$insert_run=mysql_query($insert_query);
echo "<script>alert('News Inserted...!!!')</script>";
}
}
?>`
You need to escape the input data in case it contains quote characters.
$news_title=mysql_real_escape_string($_POST['title']);
$news_cat=mysql_real_escape_string($_POST['cat']);
$news_desc=mysql_real_escape_string($_POST['desc']);
$news_image=mysql_real_escape_string($_FILES['news_image']['name']);
It would be better if you switched form the deprecated mysql extension to PDO or mysqli, and used prepared statements.
i found the insert to database code on internet, use it for trying and its works. but, after i add on some more column, i got error on inserting data to database. which i'm using this code
error_reporting(E_ALL);
ini_set('display_errors','on');
to determine error location, but its show no error on coding. only goes to error result. could anyone help me looking for my mistake and my code error?
here is my insert2_db.php
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">function checkinput() {
var id_mesin = document.getElementById('id_mesin').value;
if(!id_mesin.match(/\S/)) {
alert ('Please enter Machine ID');
return false;
} else {
return true;
}
}
</script>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form_insert" method="post" action="insert_ac.php" onSubmit="return checkinput(this)">
<table width="100%" height="398" border="0" cellpadding="3" cellspacing="1">
<tr>
<td colspan="9"><strong>Insert Data Into EXA_mySQL Database </strong></td>
</tr>
<tr>
<td width="106">MACHINE ID</td>
<td width="6">:</td>
<td colspan="3"><input name="id_mesin" type="text" id="id_mesin"></td>
<td colspan="2">BRAND</td>
<td width="9">:</td>
<td width="164"><select name="jenama">
<option selected>Please select :</option>
<option value="SHARP">SHARP</option>
<option value="TOSHIBA">TOSHIBA</option>
<option value="CANON">CANON</option>
<option value="SAMSUNG">SAMSUNG</option>
<option value="MEXTEC">MEXTEC</option>
</select></td>
</tr>
<tr>
<td>MODEL</td>
<td>:</td>
<td colspan="3"><input name="model" type="text" id="model"></td>
<td colspan="2">METER START</td>
<td>:</td>
<td><input name="meter_awal" type="text" id="meter_awal" value="0"></td>
</tr>
<tr>
<td>SERIAL NO</td>
<td>:</td>
<td colspan="3">MACHINE</td>
<td colspan="2">FEEDER</td>
<td> </td>
<td>FINISHER</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><input name="siri_mesin" type="text" id="siri_mesin"></td>
<td colspan="3"><input name="siri_feeder" type="text" id="siri_feeder"></td>
<td><input name="siri_finisher" type="text" id="siri_finisher"></td>
</tr>
<tr>
<td>STOCK IN</td>
<td>:</td>
<td width="58">DATE</td>
<td width="8">:</td>
<td width="220"><input type="text" name="stok_in" id="stok_in"></td>
<td colspan="2">D.O NO </td>
<td>:</td>
<td><input type="text" name="in_do" id="in_do"></td>
</tr>
<tr>
<td>LOCATION</td>
<td>:</td>
<td colspan="3"><select name="lokasi">
<option selected>Please select :</option>
<option value="HQ WAREHOUSE">HQ WAREHOUSE</option>
<option value="CHENDERING WAREHOUSE">CHENDERING WAREHOUSE</option>
</select></td>
<td colspan="2">J.S.O</td>
<td>:</td>
<td><input type="text" name="js_order" id="js_order"></td>
</tr>
<tr>
<td>STOCK OUT</td>
<td>:</td>
<td>DATE</td>
<td>:</td>
<td><input type="text" name="stok_out" id="stok_out"></td>
<td colspan="2">D.O NO </td>
<td>:</td>
<td><input type="text" name="out_do" id="out_do"></td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td colspan="7"><input name="pelangan" type="text" id="pelangan" size="90"></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:</td>
<td colspan="7"><textarea name="pelangan_alamat" cols="69" id="pelangan_alamat"></textarea></td>
</tr>
<tr>
<td>CONTACT PERSON</td>
<td>:</td>
<td colspan="4"><input name="pelangan_person" type="text" id="pelangan_person" size="50"></td>
<td width="109">NO TEL/HP</td>
<td>:</td>
<td><input type="text" name="pelangan_no" id="pelangan_no"></td>
</tr>
<tr>
<td>TECHNICIAN INCHARGE</td>
<td>:</td>
<td colspan="4"><input name="tech" type="text" id="tech" size="50"></td>
<td>NO TEL/HP</td>
<td>:</td>
<td><input type="text" name="tech_no" id="tech_no"></td>
</tr>
<tr>
<td>STATUS</td>
<td>:</td>
<td colspan="3"><select name="status">
<option selected>Please select :</option>
<option value="ORDER PURCHASE">ORDER PURCHASE</option>
<option value="RENTAL">RENTAL</option>
<option value="HIRE PURCHASE">HIRE PURCHASE</option>
</select></td>
<td colspan="3"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
<td colspan="3"><input type="reset" value="Clean" /></td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
and my insert_ac.php
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<script type="text/javascript">
<!--
function CloseWindow() {
window.close();
window.opener.location.reload();
}
//-->
</script>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
$con=mysqli_connect("localhost","root","admin","exa");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id_mesin=$_POST['id_mesin'];
$jenama=$_POST['jenama'];
$model=$_POST['model'];
$siri_mesin=$_POST['siri_mesin'];
$siri_feeder=$_POST['siri_feeder'];
$siri_finisher=$_POST['siri_finisher'];
$meter_awal=$_POST['meter_awal'];
$lokasi=$_POST['lokasi'];
$status=$_POST['status'];
$pelangan=$_POST['pelangan'];
//$rekod=$_POST['rekod'];
$stok_in=$_POST['stok_in'];
$stok_out=$_POST['stok_out'];
$in_do=$_POST['in_do'];
$out_do=$_POST['out_do'];
$pelangan_alamat=$_POST['pelangan_alamat'];
$pelangan_no=$_POST['pelangan_no'];
$pelangan_person=$_POST['pelangan_person'];
$js_order=$_POST['js_order'];
$tech=$_POST['tech'];
$tech_no=$_POST['tech_no'];
//$sql2="SELECT * FROM aset where id_mesin = '".$id_mesin."'";
//$result2=mysqli_query($con, $sql2);
$sql="INSERT INTO aset(id_mesin, jenama, model, siri_mesin, siri_feeder, siri_finisher, meter_awal, lokasi, status, pelangan, stok_in, stok_out, in_do, out_do, pelangan_alamat, pelangan_no, pelangan_person, js_order, tech, tech_no) VALUES('$id_mesin', '$jenama', '$model', '$siri_mesin', $siri_feeder, $siri_finisher, '$meter_awal', '$lokasi', '$status', '$pelangan', '$stok_in', '$stok_out', '$in_do', $out_do, $pelangan_alamat, '$pelangan_no', '$pelangan_person', '$js_order', '$tech', '$tech_no')";
$result=mysqli_query($con, $sql);
if($result){//if ($result2 !== 1){
echo "Successful";
echo "<BR>";
echo "<th><form>";
echo "<input type='button' onClick='CloseWindow()' value='Back to Exa_mySQL'>";
echo "</form></th>}";
}//}
else {
echo "Data error, please check your submit.";
echo "<BR>";
echo "<a href='insert.php'>Back to insert form</a>";
}
mysqli_close($con);
?>
</body>
</html>
i'm also using some dropdown list as input on my form, which initial value = Please select: and it has null value. i cant insert data even i put all information on my insert form, all goes to this error result.
echo "Data error, please check your submit.";
I have managed to populate my three drop down lists in php and ajax. Here is the one part of my code that displays the three dropdown lists:
<?php
echo "<font id=\"categoria\"><select>\n";
echo "<option value='0'>Select the Firm</option> \n" ;
echo "</select></font>\n";
?>
<?php
echo "<font id=\"subcategoria\"><select>\n";
echo "<option value='0'>Select the Claims Hub</option> \n" ;
echo "</select></font>\n";
?>
<?php
echo "<font id=\"subcategoria2\"><select>\n";
echo "<option value='0'>Select the Area</option> \n" ;
echo "</select></font>\n";
?>
My question is: I also have a form on this pages and i want to make the three dropdown lists part of my form in order to post the values into another mysql table. Any suggestions how i can do this? Here is my form part:
<form method="post" align= "right">
<table >
<tr><td> </td>
<tr>
<td>Select the Matter Type: </td>
<td><?php echo $dropdown; ?></td>
</tr>
<tr><td> </td>
<tr>
<td style="text-align: left; ">Active </td>
<td align="left" >
<input type="checkbox" name="active" value="1" />
</td>
</tr>
<tr><td> </td>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Add" align= "right" /></td>
</tr>
</table>
Why not just insert them into the html?
<form method="post" align= "right">
<table >
<tr><td> </td>
<tr>
<td>Select the Matter Type: </td>
<td><?php echo $dropdown; ?></td>
</tr>
<tr>
<td>
<?php echo "<font id=\"categoria\"><select><option value='0'>Select the Firm</option></select></font>";?>
</td>
</tr>
<tr><td> </td>
<tr>
<td style="text-align: left; ">Active </td>
<td align="left" >
<input type="checkbox" name="active" value="1" />
</td>
</tr>
<tr><td> </td>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Add" align= "right" /></td>
</tr>