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,",");
Related
I am rewriting my php code form mysqli to PDO, now I get a few error messages when I want to post my data.
I hope someone can help me im a starter with learning pdo :)
Over here a screenshot with the error messages
screenshot: https://gyazo.com/f4c6f6686014facb59d0fd40f1ebe522
<body>
<font color="black">
<form method="post" enctype='multipart/form-data'>
<table class="table-fill">
<thead>
<tr>
<th class="text-left">Film:</th>
<th class="text-left">
<input style="text" name="txtFilm">
</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td class="text-left">Genre:</td>
<td class="text-left">
<select name="Genre">
<option value="Actie">Actie</option>
<option value="Fantasie">Fantasie</option>
<option value="Horror">Horror</option>
<option value="Avontuur">Avontuur</option>
<option value="Komedie">Komedie</option>
<option value="Romantiek">Romantiek</option>
<option value="Historisch">Historisch</option>
</select>
</td>
</tr>
<tr>
<td class="text-left">Film omschrijving:</td>
<td class="text-left">
<textarea style="width:100%;resize:none;height:200px;" type="text" name="txtFilmomschrijving"></textarea>
</td>
</tr>
<tr>
<td class="text-left">Datum van uitkomst:</td>
<td class="text-left">
<input type="date" name="uitkomstdate">
</td>
</tr>
<tr>
<td class="text-left">Datum uit bioscoop:</td>
<td class="text-left">
<input type="date" name="Biosdate">
</td>
</tr>
<tr>
<td class="text-left">Film draai dagen:</td>
<td class="text-left">
<input type="checkbox" value="Maandag" name="draaidag[]">Maandag
<input type="checkbox" value="Dinsdag" name="draaidag[]">Dinsdag
<input type="checkbox" value="Woensdag" name="draaidag[]">Woensdag
<input type="checkbox" value="Donderdag" name="draaidag[]">Donderdag
<input type="checkbox" value="Vrijdag" name="draaidag[]">Vrijdag
<input type="checkbox" value="Zaterdag" name="draaidag[]">Zaterdag
<input type="checkbox" value="Zondag" name="draaidag[]">Zondag
</td>
</tr>
<tr>
<td class="text-left">Film tijd dagen:</td>
<td class="text-left">
<input type="checkbox" value="12uur" name="tijddagen[]">12:00
<input type="checkbox" value="14uur" name="tijddagen[]">14:00
<input type="checkbox" value="16uur" name="tijddagen[]">16:00
<input type="checkbox" value="18uur" name="tijddagen[]">18:00
<input type="checkbox" value="20uur" name="tijddagen[]">20:00
<input type="checkbox" value="22uur" name="tijddagen[]">22:00
<input type="checkbox" value="24uur" name="tijddagen[]">24:00
</td>
</tr>
<tr>
<td class="text-left">Zaal:</td>
<td class="text-left">
<select name="zaal">
<option value="normaal">Normaal</option>
<option value="groot">Groot</option>
</select>
</td>
</tr>
<tr>
<td class="text-left">Film afbeelding:</td>
<td class="text-left">
<input type="file" name="filmafbeelding" id="filmafbeelding">
</td>
</tr>
<tr>
<td class="text-left"></td>
<td class="text-left">
<center><input type="submit" value="Film toevoegen" name="btnHuur"></center>
</td>
</tr>
</tbody>
</table>
<br>
</form>
<br>
<?php
include ("loginDB.php");
if (isset($_POST['btnHuur'])) {
$filmimage =$_FILES["filmafbeelding"]["name"];
$filmimagemap = "images/";
$filmimagedoel = $filmimagemap.$filmimage;
$draaidagen = $_POST['draaidag'];
$draaidag="";
foreach($draaidagen as $draaidagcheck)
{
$draaidag.= $draaidagcheck.",";
}
$tijddagen = $_POST['tijddagen'];
$tijddag="";
foreach($tijddagen as $tijddagcheck)
{
$tijddag.= $tijddagcheck.",";
}
//film moet in de map /bioscoop/banner/ of /bioscoop/images/ staan//
$uploadfilm = "INSERT INTO films (film, movieimage, genre, Filmomschrijving, Datumvanuitkomst, Datumuitbioscoop, Filmdraaidagen, Filmtijddragen, Zaal) VALUES ('".$_POST["txtFilm"]."','$filmimagedoel','".$_POST["Genre"]."','".$_POST["txtFilmomschrijving"]."','".$_POST["uitkomstdate"]."','".$_POST["BiosDate"]."','$draaidag','$tijddag','".$_POST["zaal"]."')";
$result = mysqli_query($db,$uploadfilm);
echo "Film toegevoegt!";
}
?>
NOTE THIS IS MY OLD MYSQLI PHP CODE SCRIPT:
<center>
<div class="gallery1">
<h3>Film toevoegen</h3>
</div>
<br>
<br>
<form method="post" enctype='multipart/form-data'>
<table class="table-fill">
<thead>
<tr>
<th class="text-left">Film:</th>
<th class="text-left"><input style="text" name="txtFilm"></th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td class="text-left">Genre:</td>
<td class="text-left"> <select name="Genre">
<option value="Actie">Actie</option>
<option value="Fantasie">Fantasie</option>
<option value="Horror">Horror</option>
<option value="Avontuur">Avontuur</option>
<option value="Komedie">Komedie</option>
<option value="Romantiek">Romantiek</option>
<option value="Historisch">Historisch</option>
</select></td>
</tr>
<tr>
<td class="text-left">Film omschrijving:</td>
<td class="text-left"><textarea style="width:100%;resize:none;height:200px;" type="text" name="txtFilmomschrijving"></textarea></td>
</tr>
<tr>
<td class="text-left">Datum van uitkomst:</td>
<td class="text-left"><input type="date" name="uitkomstdate"></td>
</tr>
<tr>
<td class="text-left">Datum uit bioscoop:</td>
<td class="text-left"><input type="date" name="Biosdate"></td>
</tr>
<tr>
<td class="text-left">Film draai dagen:</td>
<td class="text-left"><input type="checkbox" value="Maandag" name="draaidag[]">Maandag
<input type="checkbox" value="Dinsdag" name="draaidag[]">Dinsdag
<input type="checkbox" value="Woensdag" name="draaidag[]">Woensdag
<input type="checkbox" value="Donderdag" name="draaidag[]">Donderdag
<input type="checkbox" value="Vrijdag" name="draaidag[]">Vrijdag
<input type="checkbox" value="Zaterdag" name="draaidag[]">Zaterdag
<input type="checkbox" value="Zondag" name="draaidag[]">Zondag</td>
</tr>
<tr>
<td class="text-left">Film tijd dagen:</td>
<td class="text-left">
<input type="checkbox" value="12uur" name="tijddagen[]">12:00
<input type="checkbox" value="14uur" name="tijddagen[]">14:00
<input type="checkbox" value="16uur" name="tijddagen[]">16:00
<input type="checkbox" value="18uur" name="tijddagen[]">18:00
<input type="checkbox" value="20uur" name="tijddagen[]">20:00
<input type="checkbox" value="22uur" name="tijddagen[]">22:00
<input type="checkbox" value="24uur" name="tijddagen[]">24:00
</td>
</tr>
<tr>
<td class="text-left">Zaal:</td>
<td class="text-left"><select name="zaal">
<option value="normaal">Normaal</option>
<option value="groot">Groot</option></td>
</tr>
<tr>
<td class="text-left">Film afbeelding:</td>
<td class="text-left"><input type="file" name="filmafbeelding" id="filmafbeelding"></td>
</tr>
<tr>
<td class="text-left"></td>
<td class="text-left">
<center><input type="submit" value="Film toevoegen" name="submit"></center>
</td>
</tr>
</tbody>
</table>
</form>
</center>
<?php
if(isset($_POST["submit"])){
$hostname='localhost';
$username='root';
$password='';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=fastmovierenessefrank",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "INSERT INTO films (film, movieimage, genre, Filmomschrijving, Datumvanuitkomst, Datumuitbioscoop, Filmdraaidagen, Filmtijddragen, Zaal)
VALUES ('".$_POST["txtFilm"]."','$filmimagedoel','".$_POST["Genre"]."','".$_POST["txtFilmomschrijving"]."','".$_POST["uitkomstdate"]."','".$_POST["BiosDate"]."','$draaidag','$tijddag','".$_POST["zaal"]."')";
if ($dbh->query($sql)) {
echo "Film toegevoegt!";
}
else{
echo "Er is iets misgegaan...";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
Here are the issues:
$_POST["BiosDate"] != name="Biosdate"
No $draaidag =
No $filmimagedoel =, this item also isn't present in the PDO HTML form.
No $tijddag =.
You aren't assigning in the PDO code like you did in the mysqli code. In additional the real benefit to using these drivers is there ability to use prepared statements and parameterized queries. I think this would be closer to what you want. You'll need to figure out what the $filmimagedoel is suppose to be:
if(isset($_POST["submit"])){
$hostname='localhost';
$username='root';
$password='';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=fastmovierenessefrank",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "INSERT INTO films (film, movieimage, genre, Filmomschrijving, Datumvanuitkomst, Datumuitbioscoop, Filmdraaidagen, Filmtijddragen, Zaal)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$params = array($_POST["txtFilm"], $filmimagedoel, $_POST["Genre"], $_POST["txtFilmomschrijving"], $_POST["uitkomstdate"], $_POST["Biosdate"], implode(',', $_POST['draaidag']), implode(',', $_POST['tijddag']), $_POST["zaal"]);
$sth = $dbh->prepare($sql);
if ($sth->execute($params)) {
echo "Film toegevoegt!";
} else{
echo "Er is iets misgegaan...";
}
$dbh = null;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
Additionally, storing delimited data in a DB is bad practice. You should only have one data value in a column.
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>
This is the entire php code insert query working fine but rest is only working since product_is is missing. However if I put a value of product_id from the database, it's working perfectly.
if(isset($_POST["submit"]))
{
$pname=$_POST["pname"];
$pprice=$_POST["pprice"];
$quant=$_POST["quant"];
$imei_no=$_POST["imei_no"];
$total=$_POST["total"];
$transaction_no=$_POST["transaction_no"];
$sl_sql="insert into sales (pname,pprice,quant,imei_no,total,transaction_no,selling_date) values ('$pname','$pprice','$quant','$imei_no','$total','$transaction_no',NOW())";
$sl_res=mysql_query($sl_sql);
$product_id= $_GET["product_id"];
echo $sc_sql="select * from productlist where product_id='$product_id' ";
$sc_res=mysql_query($sc_sql);die();
while($sc_row=mysql_fetch_object($sc_res))
{
$pid=$sc_row->product_id;
$psold=$sc_row->psold;
$quantity=$sc_row->quantity;
}
$ab=$psold+$quant;
$bc=$quantity-$quant;
$up_sql="update productlist set psold ='$ab', quantity='$bc' where product_id='$pid'";
$up_res=mysql_query($up_sql);
if($up_res)
{
header("location:billing.php");
exit();
}
}
My dropdown list is working fine.
This is my HTML from
<form action="" method="post" onsubmit="return validation();" style="float: inherit;">
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<?php
$p_sql="select * from productlist where published=1";
$p_res=mysql_query($p_sql);
?>
<td width="140" height="32"><div align="right"><b>PRODUCT NAME :</b> </div></td>
<td><select name="pname" id="pname" onchange="showprice(this.value);" style=" border-style:groove">
<option value="">Select Your Product</option>
<?php
if($p_res)
{
while($p_row=mysql_fetch_object($p_res))
{
?>
<option value="<?=$p_row->product_id?>"><?=$p_row->pname?></option>
<?php
}
}
?>
</select>
</td>
<td><input type="hidden" name="product_id" id="product_id" value="" /></td>
<td> </td>
<td><div align="right"><b>PRODUCT PRICE :</b></div></td>
<td><div id="price"><input name="pro_price" type="text" readonly="readonly" style=" border-style:groove"/></div></td>
</tr>
<tr>
<td height="32"><div align="right"><b>SELLING PRICE :</b></div></td>
<td><input name="pprice" id="pprice" type="text" value="" style=" border-style:groove"/></td>
</tr>
<tr>
<td width="119" height="32"><div align="right"><b>QUANTITY:</b> </div></td>
<td width="184"><input name="quant" id="quant" type="text" onkeyup="multi()" onkeypress="return checkIt(event)" style=" border-style:groove"/></td>
</tr>
<tr>
<td height="32"><div align="right"><b>TRANSCATION NO. :</b></div></td>
<td><input name="transaction_no" id="transaction_no" type="text" readonly value="<?php echo $_SESSION["transaction"]; ?>" style=" border-style:groove"/>
</td>
</tr>
<tr>
<td><div align="right"><b>IMEI NUMBER :</b> </div></td>
<td><input name="imei_no" type="text" id="imei_no" maxlength="14" onkeydown="is_num();" style=" border-style:groove"/></td>
</tr>
<tr>
<td><div align="right"><b>Sub Total :</b> </div></td>
<td><input name="total" id="total" type="text" readonly="readonly" style=" border-style:groove"/></td>
<td> </td>
<td> </td>
<td> </td>
<td style="float:right;"><input name="submit" type="submit" value="" style="height: 90px; width: 110px; cursor:pointer; background-image:url(images/cart.png); border:none;"id="xx" /></td>
</tr>
</table>
</form>
By the looks of your dropdown list code, i think, you should not be able to see the items in the dropdown list as well.
Please change the option tag inside your while loop to the one below:
<option value="<?php echo $p_row->product_id; ?>"><?php echo $p_row->pname; ?></option>
If you are not able to see the product_id even after this change, paste the complete code for your form and the code corresponding to the GET method you are calling on form-submit.
-- seekers01
Please ensure that echo $product_id is returning value in the file, where you are framing the query using:
$sc_sql="select * from productlist where product_id='$product_id'";
I am assuming this file is a .php file. If so, try this instead:
$sc_sql="select * from productlist where product_id=\'" . $product_id . "\'";
Hope my assumptions are correct.
Let me know, if that does the trick for you.
-- seekers01
The second column, in the Procedures, it says there are no records. It shouldnt be like that. The results in there is from the data from another database. I already have the code for it and if I use include with a different php file with another mysql_connect configuration (from another database), the patient information isnt retrieved like the one seen here:
I know how to do multiple connections by storing different variables of the two connections.. But its much confusing to me cause its in different include files.
That page in the screenshot is editclient.php and i included editclient_include_inv.php where the code for the "procedures" section.
editclient.php
<?
include('header.php');
if ($id) {
echo "<h1>Edit Medical Records # : $id</h1>";
}
else
{
echo " <h1>Medical Records</h1>";
}
if($submit)
{
//-------------------check user name-----------------------------------------------------
$name = $_POST['name'];
$select = "select first_name from patient where last_name = '".$last_name."';";
$query = mysql_query($select) or die ("Mysql error! It was: ".mysql_error());
$rows = mysql_num_rows($query);
if ($rows != 0)
{
echo ("<script language=javascript>alert ('Sorry! $first_name is already taken!')</script>");
echo ("<script language=javascript>document.location.href = 'editclient.php'</script>");
exit;
}
if($name == "admin"){
echo ("<script language=javascript>alert ('Sorry! $first_name is not a good thing to do!')</script>");
echo ("<script language=javascript>document.location.href = 'editclient.php'</script>");
exit;
}
//-----------------------------------end check-------------------------------------------
$sql = "INSERT INTO patient (`first_name`, `last_name`,`country`, `address`, `gender`, `telno`, `occ`, `spo`, `occ2`,`cp`, `tel2`, `reff`, `all`, `ill`, `mat`, `frat`, `datetime`, `vs`,`ppe`, `ffup`)
VALUES ('$first_name','$last_name','$country','$address','$gender','$telno','$occ','$spo','$occ2', '$cp','$tel2','$reff','$all','$ill','$mat','$frat','$datetime','$vs','$ppe','$ffup')";
$result = mysql_query($sql);
//echo ("<script language=javascript>document.location.href = 'editclient.php?id=$id&message=Patient $id has been Created!'</script>");
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Succesfully Updated')
window.location.href='sample4.php';
</SCRIPT>");
}
else if($update)
{
$sql = "UPDATE patient set first_name='$first_name',last_name='$last_name',
country='$country',address='$address',gender='$gender',telno='$telno',
occ='$occ',spo='$spo',occ2='$occ2', cp='$cp', tel2='$tel2',reff='$reff', ill='$ill', mat='$mat', frat='$frat', datetime='$datetime', vs='$vs', ppe='$ppe' ,ffup='$ffup'
WHERE clientid=$id";
$result = mysql_query($sql);
//echo ("<script language=javascript>document.location.href = 'editclient.php?id=$id&message=Client $id has been Updated!'</script>");
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Succesfully Updated')
window.location.href='sample4.php';
</SCRIPT>");
}
else if($id)
{
$result = mysql_query("SELECT * FROM patient WHERE clientid=$id",$db);
$row = mysql_fetch_array($result);
?>
</p>
<br><font color=red size=4><?php if (isset($_GET['message'])) { echo ' - '.$_GET['message']; } ?></font><BR>
<?
//-------------NEXT PREVIOUS----------------------------------------------------------------------
$sql ="SELECT * FROM patient WHERE clientid < '$id' ORDER by clientid DESC LIMIT 1";
$resultp = mysql_query($sql);
$previousrows = mysql_num_rows($resultp);
while ($prerow = mysql_fetch_array($resultp)) {
$prev=$prerow['clientid'];
}
//echo $prev;
$sql2 ="SELECT clientid FROM patient WHERE clientid > '$id' ORDER by clientid ASC LIMIT 1";
$resultn = mysql_query($sql2);
$nextrows = mysql_num_rows($resultn);
while ($nextrow = mysql_fetch_array($resultn)) {
$next=$nextrow['clientid'];
}
//echo $next;
if ($previousrows == "") {
echo "";
}else{
echo "<B><a href=$PHP_SELF?id=$prev>$prev <- Prev</a> | ";
}
echo "<font size=6><B>$id</B></font>";
if ($nextrows == "") {
echo "";
}else{
echo "<b> | <a href=$PHP_SELF?id=$next > Next -> $next</a></b>";
}
//-----------------end next prev-----------------------------------------------------
?><br><br>
<?php include("inc/nav.inc");?>
<form name="form2a" method="post" action="<?php echo $PHP_SELF?>">
<table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class=topHeadrow1 valign="middle" width="50%" colspan="2">
Edit Patient Information:</td>
<td class=topHeadrow1 valign="middle" width="10" rowspan="20">
</td>
<td class=topHeadrow1 valign="middle" width="50%">
Procedures:</td>
</tr>
<tr>
<td valign="top" align="right">
<input type="hidden" name="id" value="<?php echo $row["clientid"]?>">
First name:<br>
</td>
<td valign="top" align="left">
<input type="text" size="20" name="first_name" value="<?php echo $row["first_name"]?>" ></td>
<td valign="top" width="10%" rowspan="13">
<?
include('editclient_include_inv.php');
?>
</td>
</tr>
<tr>
<td valign="top" align="right">
Last Name:
</td>
<td valign="top" align="left">
<input type="text" name="last_name" size="20" value="<?php echo $row["last_name"]?>"></td>
</tr>
<tr>
<td valign="top" align="right"> Gender:</td>
<td valign="top" align="left"><select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option> </select>
</td>
</tr>
<tr>
<td valign="top" align="right"> Country:</td>
<td valign="top" align="left">
<select name="country" >
<option value="Afghanistan">Afghanistan</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Bhutan">Bhutan</option>
<option value="Brunei">Brunei</option>
<option value="Cambodia">Cambodia</option>
<option value="China">China</option>
<option value="Malaysia">Malaysia</option>
<option value="Maldives">Maldives</option>
<option value="Mongolia">Mongolia</option>
<option value="Myanmar">Myanmar (Burma)</option>
<option value="Pakistan">Pakistan</option>
<option value="Philippines">Philippines</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Singapore">Singapore</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Syria">Syria</option>
<option value="UAE">United Arab Emirates</option>
<option value="Uzbekistan">Uzbekistan</option>
</select>
</tr>
<tr>
<td valign="top" align="right">
Tel. no.:</td>
<td valign="top" align="left">
<input
type="text" size="20" name="telno" placeholder="###-####" value="<?php echo $row["telno"]?>"></td></tr>
<tr>
<td valign="top" align="right">
Occupation:</td>
<td valign="top" align="left">
<input
type="text" size="20" name="occ" value="<?php echo $row["occ"]?>"></td></tr>
<tr>
<td align="right">
Spouse:</td>
<td >
<input
type="text" size="20" name="spo" value="<?php echo $row["spo"]?>"></td></tr><tr>
<td align="right">
Occupation:</td>
<td >
<input
type="text" size="20" name="occ2" value="<?php echo $row["occ2"]?>"></td></tr>
<tr>
<td align="right" width="20">
Contact Person(in case of emergency):</td>
<td >
<input
type="text" size="20" name="cp" value="<?php echo $row["cp"]?>"></td></tr><tr>
<td align="right">
Tel. no:</td>
<td >
<input
type="text" size="20" name="tel2" value="<?php echo $row["tel2"]?>"></td></tr>
<tr>
<td valign="top" align="right" nowrap>
Address:</td>
<td valign="top" align="left">
<input type="text" name="address" value="<?php echo $row["address"]?>" size="31"></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Reffered By:</td>
<td valign="top" align="left">
<input type="text" name="reff" value="<?php echo $row["reff"]?>" size="31" ></td>
</tr>
<tr>
<td class=topHeadrow1 valign="middle" width="50%" colspan="2">
Past Medical History:</td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Allergy:</td>
<td valign="top" align="left">
<input type="text" name="all" value="<?php echo $row["all"]?>" size="31"></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Previous illness:</td>
<td valign="top" align="left">
<input type="text" name="ill" value="<?php echo $row["ill"]?>" size="31"></td>
</tr>
<tr>
<td class=topHeadrow1 valign="middle" width="50%" colspan="2">
<b><font size="4">
Heredo-Familial Diseases:</font></b></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Maternal:
</td>
<td valign="top" align="left">
<input type="text" name="mat" value="<?php echo $row["mat"]?>" size="20"></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Fraternal:
</td>
<td valign="top" align="left">
<input type="text" name="frat" value="<?php echo $row["frat"]?>" size="20"></td>
</tr>
<tr>
<td class=topHeadrow1 valign="middle" width="50%" colspan="2">
<b><font size="4">
Examination:</font></b></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Date / Time:</td>
<td valign="top" align="left">
<input type="text" name="datetime" value="<?php echo $row["datetime"]?>" size="31"></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Vital Signs:</td>
<td valign="top" align="left">
<input type="text" name="vs" value="<?php echo $row["vs"]?>" size="31"></td>
</tr>
<tr>
<td align="center" nowrap>
Complain PPE Findings:</td>
<td valign="top" align="left">
<input type="text" name="ppe" value="<?php echo $row["ppe"]?>" size="31"></td>
</tr>
<tr>
<td align="center" nowrap>
Plan / Management / FF-UP</td>
<td valign="top" align="left">
<input type="text" name="ffup" value="<?php echo $row["ffup"]?>" size="31"></td>
</tr>
<tr>
<td class=topHeadrow1 valign="middle" width="100%" colspan="4">
<p align="center"><input class="form-button" type="Submit" name="update" value="Update Information"></td>
</tr>
<tr>
<td valign="top" width="100%" colspan="4">
<br>
</td>
</tr>
</table>
</form>
<?
}
else
{
//----------------------------begin add client--------------------------------------------------------
?>
<br><font color=red size=4><?php if (isset($_GET['message'])) { echo ' - '.$_GET['message']; } ?></font><BR>
<form name="form2b" method="post" action="editclient.php" onSubmit="return checkPw(this)">
<table>
<tr>
<td class="topHeadrow5" valign="top" width="100%" colspan="5">
<b><font size="4">Patient Information:</font></b></td>
</tr>
<tr>
<td valign="top" align="right">
First Name:</td>
<td valign="top" align="left">
<input
type="text" size="20" name="first_name" ></td></tr>
<tr>
<td valign="top" align="right">
Last Name:</td>
<td valign="top" align="left">
<input type="text" name="last_name" size="20"></td></tr>
<tr>
<td valign="top" align="right"> Gender:</td>
<td valign="top" align="left"><select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option> </select>
</td>
</tr>
<tr>
<td valign="top" align="right">Country:</td>
<td valign="top" align="left">
<select name="country" >
<option value="Afghanistan">Afghanistan</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Bhutan">Bhutan</option>
<option value="Brunei">Brunei</option>
<option value="Cambodia">Cambodia</option>
<option value="China">China</option>
<option value="Malaysia">Malaysia</option>
<option value="Maldives">Maldives</option>
<option value="Mongolia">Mongolia</option>
<option value="Myanmar">Myanmar (Burma)</option>
<option value="Pakistan">Pakistan</option>
<option value="Philippines">Philippines</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Singapore">Singapore</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Syria">Syria</option>
<option value="UAE">United Arab Emirates</option>
<option value="Uzbekistan">Uzbekistan</option>
</select>
</tr>
<tr>
<td valign="top" align="right">
Tel. no.:</td>
<td valign="top" align="left">
<input
type="text" size="20" name="telno" placeholder="###-####"></td></tr>
<tr>
<td valign="top" align="right">
Occupation:</td>
<td valign="top" align="left">
<input
type="text" size="20" name="occ" ></td></tr>
<tr>
<td align="right">
Spouse:</td>
<td >
<input
type="text" size="20" name="spo" ></td>
<td align="right">
Occupation:</td>
<td >
<input
type="text" size="20" name="occ2" ></td></tr>
<tr>
<td align="right" width="20">
Contact Person(in case of emergency):</td>
<td >
<input
type="text" size="20" name="cp" ></td>
<td align="right">
Tel. no:</td>
<td >
<input
type="text" size="20" name="tel2" ></td></tr>
<tr>
<td valign="top" align="right" nowrap>
Address:</td>
<td valign="top" align="left">
<input type="text" name="address" size="50"></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Reffered By:</td>
<td valign="top" align="left">
<input type="text" name="reff" size="31"></td>
</tr>
<tr>
<td class="topHeadrow5" valign="top" width="200" colspan="5">
<b><font size="4">
Past Medical History:</font></b></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Allergy:</td>
<td valign="top" align="left">
<input type="text" name="all" size="31"></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Previous illness:</td>
<td valign="top" align="left">
<input type="text" name="ill" size="31"></td>
</tr>
<tr>
<td class="topHeadrow5" valign="top" width="100%" colspan="5">
<b><font size="4">
Heredo-Familial Diseases:</font></b></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Maternal:
</td>
<td valign="top" align="left">
<input type="text" name="mat" size="20"></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Fraternal:
</td>
<td valign="top" align="left">
<input type="text" name="frat" size="20"></td>
</tr>
<tr>
<td class="topHeadrow5" valign="top" width="100%" colspan="5">
<b><font size="4">
Examination:</font></b></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Date / Time:</td>
<td valign="top" align="left">
<input type="text" name="datetime" size="31"></td>
</tr>
<tr>
<td valign="top" align="right" nowrap>
Vital Signs:</td>
<td valign="top" align="left">
<input type="text" name="vs" size="31"></td>
</tr>
<tr>
<td align="center" nowrap>
Complain PPE Findings:</td>
<td valign="top" align="left">
<input type="text" name="ppe" size="31"></td>
</tr>
<tr>
<td align="center" nowrap>
Plan / Management / FF-UP</td>
<td valign="top" align="left">
<input type="text" name="ffup" size="31"></td>
</tr>
<tr>
<td width="10%"> </td>
<td width="90%"><input class="form-button" type="Submit" name="submit" value="Enter information"></td>
</tr>
</table>
</form>
<p> </p>
<?
}
?>
editclient_include_inv.php
<?
if ($num < 1){
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "hmis";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
//printf("<td align=left><font face=Verdana size=1 color=red>There are no Records</font></td>",$num); //prints number
$procedures = "SELECT * FROM incurredcharges WHERE patient_no = '$id'";
$result = mysql_query($procedures);
if (mysql_num_rows($result) >= 1){
$procedures = "SELECT
`incurredcharges`.`procedure_no`,
`c`.`procedure`
FROM
incurredcharges
INNER JOIN (
SELECT `procedure`, `procedure_no` FROM `charges`
UNION ALL
SELECT `confinement`, `procedure_no` FROM `confinement`
UNION ALL
SELECT `service`, `procedure_no` FROM `ultrasound`
) c ON `incurredcharges`.`procedure_no` = c.`procedure_no`
WHERE `incurredcharges`.`patient_no` = '$id'";
$result2 = mysql_query($procedures);
echo "<p><table border=1 cellspacing=0 cellpadding=2 bordercolor=#000000 width=100%>";
echo "<tr align=top>
<td class=topHeadrow5><b>Procedure #</b></td>
<td class=topHeadrow5><b>Charge Incurred</b></td></tr>";
while($row = mysql_fetch_array($result2)){
echo '
<tr>
<td>'.$row[0].'</td>
<td>'.$row[1].'</td>';
echo "</tr>";
}
echo '</table>';
}
else {
echo "<p><table border=1 cellspacing=0 cellpadding=2 bordercolor=#000000 width=100%>";
echo "<tr align=top>
<td class=topHeadrow4><b>There are no Records</b></td></tr></table>";
return false;
}
}
?>
The second code is for the Procedures column which is retrieved from another database.
You haven't posted any code, but from the text of your question, I can see that you're using mysql_connect() to connect to the database.
The first thing to learn here is not to use the mysql_xxx() functions. There are a lot of reasons for this -- for a start, they're deprecated, and also they're insecure.
There are two other APIs built into PHP that you should use instead: either mysqli or PDO.
But in this case, the even better reason for not using the mysql functions is that they make managing multiple DB connections much harder.
On the other hand, mananging multiple DB connections using either mysqli or PDO is extremely easy.
$db1 = new PDO('mysql:host=xxxxx,etc',$user1,$pass1);
$db2 = new PDO('mysql:host=xxxxx,etc',$user2,$pass2);
$db1->query('SELECT * FROM table_on_db1');
$db2->query('SELECT * FROM table_on_db2');
So you can keep as many connection objects active as you need, and just use the one that suits for any given query.
You can learn more about the mysqli API here: http://www.php.net/manual/en/book.mysqli.php
And about the PDO API here: http://php.net/manual/en/book.pdo.php
Hope that helps.
mysql_connect() returns a connection identifier which you need to store, and then pass in to all of your mysql_* functions. This is how you maintain multiple database connections per-script.
However, mysql_* functions are being deprecated and you should move to either PDO or mySQLi. This would have an added benefit of allowing you to initialize and store separate database objects instead of tracking connection identifiers. ie:
$db1 = new PDO('mysql:host=host1;dbname=db1', $user1, $pass1);
$db2 = new PDO('mysql:host=host2;dbname=db2', $user2, $pass2);
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