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>
I' edit this question with my full coding
Let me post my full code here.
Page1.php
<div id="container">
<div class="box">
<form name="form" method="post" action="userbooking2.php">
<table width="" style="border: 0px solid black" align="center">
<tr>
<td><h2>Book a Room Step 1 - Booking Information</h2></td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="150px" class="titlestyle">Booked by</td>
<td width="400px"><span style="text-transform: uppercase;"><?php echo $_SESSION['SESS_FNAME']; ?></span></td>
</tr>
<tr>
<td class="titlestyle">Title</td>
<td><span class="hint--right" data-hint="Hint : Organization meeting"><input type="text" name="booking_title" id="booking_title" maxlength="50" size="50" /></span></td>
</tr>
<tr>
<td class="titlestyle">Date</td>
<td>From <input type="text" name="booking_start_date" id="booking_start_date"/> to <input type="text" name="booking_end_date" id="booking_end_date"/></td>
</tr>
<tr>
<td class="titlestyle">Time</td>
<td>From <input name="booking_start_time" id="booking_start_time" value="8:00 AM" /> to <input name="booking_end_time" id="booking_end_time" value="8:30 AM"/></td>
</tr>
<tr>
<td class="titlestyle">Room</td>
<td><select name="room_type" id="room_type">
<option value="none">--Select--</option>
<option value="Meeting Room">Meeting Room</option>
<option value="Lecture Room">Lecture Room</option>
<option value="Computer Lab">Computer Lab</option>
</select>
</td>
</tr>
<tr>
<td class="titlestyle">Participant</td>
<td><span class="hint--right" data-hint="Hint : Insert number of participants"><input type="text" name="room_participant" id="room_participant" maxlength="50" size="3" /></span> Persons</td>
</tr>
<tr>
<td class="titlestyle">Equipment</td>
<td><table>
<tr>
<td><input type="checkbox" name="room_facility[]" value="Audio System" />Audio System</td>
<td><input type="checkbox" name="room_facility[]" value="Projector" />Projector</td>
<td><input type="checkbox" name="room_facility[]" value="Video Conferencing" />Video Conferencing</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="titlestyle">Food & Baverages</td>
<td><table>
<tr>
<td><input type="checkbox" name="room_food[]" value="Breakfast" />Breakfast</td>
<td><input type="checkbox" name="room_food[]" value="Tea Break" />Tea Break</td>
<td><input type="checkbox" name="room_food[]" value="Lunch" />Lunch</td>
</tr>
<tr>
<td><input type="checkbox" name="room_food[]" value="High Tea" />High Tea</td>
<td><input type="checkbox" name="room_food[]" value="Dinner" />Dinner</td>
<td><input type="checkbox" name="room_food[]" value="No" />No, thanks</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="titlestyle">Additional Info</td>
<td><span class="hint--right" data-hint="Hint : ."><textarea name="booking_desc" id="booking_desc" style="max-width:400px;" rows="4" cols="50"></textarea></span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="Submit" value="Next" /></td>
</tr>
</table>
</form>
</div>
Page2.php
<?php
//now, let's register our session variables
session_register('fname');
session_register('booking_title');
session_register('booking_start_date');
session_register('booking_end_date');
session_register('booking_start_time');
session_register('booking_end_time');
session_register('room_participant');
session_register('room_type');
session_register('booking_facility');
session_register('booking_food');
session_register('booking_desc');
//finally, let's store our posted values in the session variables
$_SESSION['fname'] = $_SESSION['SESS_FNAME'];
$_SESSION['booking_title'] = $_POST['booking_title'];
$_SESSION['booking_start_date'] = $_POST['booking_start_date'];
$_SESSION['booking_end_date'] = $_POST['booking_end_date'];
$_SESSION['booking_start_time'] = $_POST['booking_start_time'];
$_SESSION['booking_end_time'] = $_POST['booking_end_time'];
$_SESSION['room_participant'] = $_POST['room_participant'];
$_SESSION['room_type'] = $_POST['room_type'];
$_SESSION['room_facility'] = /* WHAT TO SEND HERE? */
$_SESSION['room_food'] = $_POST['room_food'];
$_SESSION['booking_desc'] = $_POST['booking_desc'];?>
// Other form process here
Page3.php
<div id="container">
<div class="box">
<form name="form" method="post" action="">
<table width="" style="border: 0px solid black" align="center">
<tr>
<td><h2>Book a Room Step 3 - Final</h2></td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="150px" class="titlestyle">Booked by</td>
<td width="400px" ><span style="text-transform: uppercase;"><?php echo $_SESSION['SESS_FNAME']; ?></span></td>
</tr>
<tr>
<td class="titlestyle">Title</td>
<td><?php echo $_SESSION['booking_title']; ?></td>
</tr>
<tr>
<td class="titlestyle">Date</td>
<td>From <?php echo $_SESSION['booking_start_date']; ?> to <?php echo $_SESSION['booking_end_date']; ?></td>
</tr>
<tr>
<td class="titlestyle">Time</td>
<td>From <?php echo $_SESSION['booking_start_time']; ?> to <?php echo $_SESSION['booking_end_time']; ?></td>
</tr>
<tr>
<td class="titlestyle">Room</td>
<td><?php echo $_SESSION['room_name']; ?></td>
</tr>
<tr>
<td class="titlestyle">Participant</td>
<td><?php echo $_SESSION['room_participant']; ?> Persons</td>
</tr>
<tr>
<td class="titlestyle">Equipment</td>
<td><?php echo $_SESSION['room_facility']; ?></td>
</tr>
<tr>
<td class="titlestyle">Food & Baverages</td>
<td><?php echo $_SESSION['room_food']; ?></td>
</tr>
<tr>
<td class="titlestyle">Additional Info</td>
<td><?php echo $_SESSION['booking_desc']; ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
In page3.php, i want to view this kind of string "I book Value1, Value2" before store it into the database
Use:
$string = implode(', ', isset($_REQUEST['room_facility']) ? $_REQUEST['room_facility'] : array());
echo 'I need ' . $string;
Then just insert into the database as normal
Im a newbie ih php.Im trying to show drop down list values from database using this but the data not shown up.There is no error as well. Need some experts advice.
Code
<?php
include('connectdb.php');
$sql="SELECT id,name FROM companydetailstbl";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
//echo $id;
$thing=$row["name"];
$options.="<OPTION VALUE=\"$id\">".$thing;
}
?>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%">Company Name </td>
<td width="3%">:</td>
<td width="75%"><SELECT NAME="thing">
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT></td>
</tr>
<tr>
<td>Installation Date </td>
<td>:</td>
<td><input type="text" name="ins_dt" />
(ddmmyyyy)</td>
</tr>
<tr>
<td>Expiry Date </td>
<td>:</td>
<td><input type="text" name="ex_dt" />
(ddmmyyyy)</td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Update" />
<input type="submit" name="Submit2" value="Reset" /></td>
</tr>
</table>
Please help. Thanks
I don't know what DTD you are currently using, but according to the HTML 4.0 Specification, you need to close your option tag.
$options .= '<option value="' . $id . '">' . $thing . '</option>';
Also there,
<select name="thing">
<option value="0">Choose</option>
<?php echo $options; ?>
</select>
please try to close the tag
$options.="<OPTION VALUE=\"$id\">".$thing."</OPTION>";
also edit
<SELECT NAME="thing">
<OPTION VALUE=0>Choose</OPTION>
<?=$options?>
</SELECT>
<?php
include('connectdb.php');
$sql="SELECT id,name FROM companydetailstbl";
$result=mysql_query($sql);
?>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%">Company Name </td>
<td width="3%">:</td>
<td width="75%">
<select name="thing">
<?php
while($row = mysql_fetch_object($result)){
?>
<option value="<?=$row["id"]; ?>"><?=$row["name"]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Installation Date </td>
<td>:</td>
<td><input type="text" name="ins_dt" />(ddmmyyyy)</td>
</tr>
<tr>
<td>Expiry Date </td>
<td>:</td>
<td><input type="text" name="ex_dt" />(ddmmyyyy)</td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="Submit" value="Update" />
<input type="submit" name="Submit2" value="Reset" />
</td>
</tr>
</table>
Hope it helps
Hey guys, im trying to insert some checkboxes into a database and im pretty sure my code is correct however i keep getting the error ERROR INSERTING: Column count doesn't match value count at row 1
Basically i am adding each checkbox to a different column in my database
Here is my code
$idextra=$_POST['extras'];
$arr_num=count($idextra);
$i=0;
while ($i < $arr_num)
{
$qu="INSERT INTO bs_reservations (deodoriser,carpet,carpetrepair,furniture,tabs,urine) VALUES ('$idextra[$i]')";
$res=mysql_query($qu) or die('ERROR INSERTING: '.mysql_error());
$i++;
}
Hey guys here is the HTML for my check boxes and contact form.
`
<tr>
<td height="30" align="right" class="align_right">Your Name*: </td>
<td>
<input type="text" name="name" id="name" value="<?php echo $name?>" onchange="checkFieldBack(this)"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Phone*: </td>
<td><input type="text" name="phone" id="phone" value="<?php echo $phone?>" onchange="checkFieldBack(this)" onkeyup="noAlpha(this)"/></td>
</tr>
<tr>
<td height="30" align="right" class="align_right">E-mail*: </td>
<td><input type="text" name="email" id="email" value="<?php echo $email?>" onchange="checkFieldBack(this);"/></td>
</tr>
<tr>
<td align="right" valign="top" class="align_right">Address*: </td>
<td><textarea name="comments" id="comments" cols="15" rows="5" onchange="checkFieldBack(this)"><?php echo $comments?></textarea></td>
</tr>
<tr>
<td width="236" height="25" align="left">Drop off at:</td>
<td width="548" height="23"><select name="dropoff">
<option value="05:00" <?php echo $dropoff=="05:00"?"selected":""?>>05:00</option>
<option value="06:00" <?php echo $dropoff=="06:00"?"selected":""?>>06:00</option>
<option value="07:00" <?php echo $dropoff=="07:00"?"selected":""?>>07:00</option>
<option value="08:00" <?php echo $dropoff=="08:00"?"selected":""?>>08:00</option>
<option value="09:00" <?php echo $dropoff=="09:00"?"selected":""?>>09:00</option>
<option value="10:00" <?php echo $dropoff=="10:00"?"selected":""?>>10:00</option>
<option value="11:00" <?php echo $dropoff=="11:00"?"selected":""?>>11:00</option>
<option value="12:00" <?php echo $dropoff=="12:00"?"selected":""?>>12:00</option>
<option value="13:00" <?php echo $dropoff=="13:00"?"selected":""?>>13:00</option>
<option value="14:00" <?php echo $dropoff=="14:00"?"selected":""?>>14:00</option>
<option value="15:00" <?php echo $dropoff=="15:00"?"selected":""?>>15:00</option>
<option value="16:00" <?php echo $dropoff=="16:00"?"selected":""?>>16:00</option>
<option value="17:00" <?php echo $dropoff=="17:00"?"selected":""?>>17:00</option>
<option value="18:00" <?php echo $dropoff=="18:00"?"selected":""?>>18:00</option>
<option value="19:00" <?php echo $dropoff=="19:00"?"selected":""?>>19:00</option>
</select>
</td>
<tr>
<td height="10" align="right" class="align_right">Deodoriser: </td>
<td>
<input type="checkbox" name="extras[]" id="deodoriser" value="Deodoriser>"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Carpet Protector (5 litre): </td>
<td>
<input type="checkbox" name="extras[]" id="carpet" value="Carpet Protector (5 litre)"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Carpet Repair Tools: </td>
<td>
<input type="checkbox" name="extras[]" id="carpetrepair" value="Carpet Repair Tools"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Furniture Moving Equipment: </td>
<td>
<input type="checkbox" name="extras[]" id="furniture" value="Furniture Moving Equipment"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Furniture Tabs: </td>
<td>
<input type="checkbox" name="extras[]" id="tabs" value="Furniture Tabs"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Urine Decontamination Treatment: </td>
<td>
<input type="checkbox" name="extras[]" id="urine" value="Urine Decontamination Treatment"/>
</td>
</tr>
`
and here is my complete php code for inserting into the data base
`$idextra=$_POST['extras'];
$arr_num=count($idextra);
$i=0;
while ($i < $arr_num)
{
$qu="INSERT INTO bs_reservations (deodoriser,carpet,carpetrepair,furniture,tabs,urine) VALUES ('{$idextra[1]}','{$idextra[2]}','{$idextra[3]}','{$idextra[4]}','{$idextra[5]}','{$idextra[6]}')";
$res=mysql_query($qu) or die('ERROR INSERTING: '.mysql_error());
$i++;
}
$q="INSERT INTO bs_reservations (dateCreated, name, email, phone, comments,status,eventID, qty,dropoff) VALUES (NOW(),'".$name."','".$email."','".$phone."','".$comments."','2','".$eventID."','".$qty."','".$dropoff."')";
$res=mysql_query($q) or die("error!");
$orderID=mysql_insert_id();`
I basically want to take all the inputs that the user selects and insert them into a data base.
You have these columns:
(deodoriser,carpet,carpetrepair,furniture,tabs,urine)
And you are inserting this:
'$idextra[$i]'
That's 6 columns and 1 value. As the error says, that's not the same.
You might have meant something like this:
('{$idextra[1]}','{$idextra[2]}','{$idextra[3]}','{$idextra[4]}','{$idextra[5]}','{$idextra[6]}')
If you want to make a string out of your array beforehand, use something like this using implode
$yourString = implode("','",$idextra);
$qu="INSERT INTO bs_reservations (deodoriser,carpet,carpetrepair,furniture,tabs,urine)
VALUES ('{$yourString}')";
echo the query to be sure it's sane :)
Instead of using array for your checkboxes, give them distinct names, e.g.
<input type="checkbox" name="carpetrepair" id="carpetrepair" value="Carpet Repair Tools"/>
And then check if any of them were checked:
$options = explode(",","deodoriser,carpet,carpetrepair,furniture,tabs,urine");
$sql = "INSERT INTO bs_reservations SET ";
foreach($options as $opt){
if (isset($_POST[$opt])) {
$sql.= "`$opt`=1,";
}
}
$sql = rtrim($sql,",");