It is a regitration page in php where image is also uploading along with other user data but it is always showing error please help me to figure out the problem.It is always showing fail but i am using correct image. I also want to know how to set default value for profile image in phpmyadmin and how to query to update it when user enter his choice along with other user data that is to be inserted into database with insert query. and how to do insertion and updation at same time i.e inserting user data and updating default image.
<?php
include_once 'conn.inc';
if(isset($_POST["btnsave"])) {
$filename=$_FILES['file']['name'];
$size=$_FILES['file']['name'];
$extenstion=pathinfo($filename,PATHINFO_EXTENSION);
if($extenstion=='jpeg' || $extenstion=='png' || $extenstion=='jpg' && $size<=30000) {
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
}
else {
echo "failhhhhhhhhhh";
}
$name=mysql_real_escape_string($_POST["txtname"]);
$fname=mysql_real_escape_string($_POST["txtfname"]);
$gender=mysql_real_escape_string($_POST["gender"]);
$image=$_FILES['file']['name'];
$des=mysql_real_escape_string($_POST["des"]);
$job=mysql_real_escape_string($_POST["txtjob"]);
$country=mysql_real_escape_string($_POST["txtcountry"]);
$state=mysql_real_escape_string($_POST["txtstate"]);
$city=mysql_real_escape_string($_POST["txtcity"]);
$contact=mysql_real_escape_string($_POST["txtcontact"]);
$contactst=mysql_real_escape_string($_POST["contactst"]);
$email=mysql_real_escape_string($_POST["txtemail"]);
$emailst=mysql_real_escape_string($_POST["emailst"]);
$query="insert into tblregistration values
('','$name','$fname','$gender','$image','$des','$job','$country','$state','$city','$contact','$contactst','$email','$emailst')" or die('neverve'.mysql_error());
$res=mysql_query($query) or die('error 1'.mysql_error());
if(mysql_affected_rows())
{
echo "success";
}
else {
echo "failure";
}
}
?>
html form
<form method="post" action="registration.php" enctype="multipart/form-data">
<table>
<tr>
<td><label for="txtname">Name</label></td>
<td><input type="text" name="txtname" value="Enter your name"/></td>
</tr>
<tr>
<td><label for="txtfname">Father Name</label></td>
<td><input type="text" name="txtfname" value="Enter your father's name"/></td>
</tr>
<tr>
<td><label>Gender</label></td>
<td>Male<input type="radio" name="gender" checked="checked" value="m" />
Female<input type="radio" name="gender" value="f" />
</td>
</tr>
<tr>
<td>
<input onchange="readURL(this);" type="file" name="file" /></td>
<td><img alt="Image Display Here" id="test" src="./upload/icon3.jpg" height="100px" width="100px" /></td>
</tr>
<tr>
<td><label>Designation</label></td>
<td><select name="des">
<option value="-1">Select Designation</option>
<option value="Employed">Employed</option>
<option value="selfemployed">Self-Employed</option>
<option value="retired">Retired</option>
</select></td>
</tr>
<tr>
<td>
<label>Title of Job</label></td>
<td><input type="text" name="txtjob" value="title of job" /></td>
</tr>
<tr>
<td>
<label>Country</label></td>
<td><input type="text" name="txtcountry" value="Enter your country" /></td>
</tr>
<tr>
<td>
<label>State</label></td>
<td><input type="text" name="txtstate" value="Enter your State" /></td>
</tr>
<tr>
<td>
<label>City</label></td>
<td><input type="text" name="txtcity" value="Enter your city" /></td>
</tr>
<tr>
<td>
<label>Contact no</label></td>
<td><input type="tel" name="txtcontact" value="Enter your contact no" />
Private<input type="radio" name="contactst" value="0" /> Public<input type="radio" name="contactst" checked="checked" value="1"/>
</td>
</tr>
<tr>
<td>
<label>Email</label></td>
<td><input type="email" name="txtemail" value="Enter your email" />
Private<input type="radio" name="emailst" value="0" /> Public<input type="radio" name="emailst" checked="checked" value="1" />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnsave" value="submit" /></td>
</tr>
</table>
</form>
$size=$_FILES['file']['name']; please check this condition
Replace
$size=$_FILES['file']['name'];
with
$size=$_FILES['file']['size'];
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Guys following is my html code.
<form method="post">
<table class="table-entry" cellpadding="1" cellspacing="0" width= "100%">
<tbody>
<tr>
<td><input type="label" name="team" id="team" value="Team:" readonly="readonly" /></td>
<td>
<input list="tm" name="teamv" id="teamv" placeholder="Team" />
<datalist id="tm">
<option value="Pre-press"></option>
<option value="eBooks"></option>
</datalist>
</td>
</tr>
<tr>
<td><input type="label" name="prno" id="prno" value="Project No.:" readonly="readonly" /></td>
<td>
<input list="prct" name="prjctv" id="prjctv" placeholder="Project Number" />
<datalist id="prct">
<option value="Project001"></option>
<option value="Project002"></option>
</datalist>
</td>
</tr>
<tr>
<td><input type="label" name="isbn" id="isbn" value="ISBN:" readonly="readonly" /></td>
<td><input type="number" name="isbnv" id="isbnv" maxlength="13" placeholder="ISBN" /></td>
</tr>
<tr>
<td><input type="label" name="eisbn" id="eisbn" value="eISBN:" readonly="readonly" /></td>
<td><input type="number" name="eisbnv" id="eisbnv" maxlength="13" placeholder="eISBN" /></td>
</tr>
<tr>
<td><input type="label" name="title" id="title" value="Title:" readonly="readonly" /></td>
<td><input type="text" name="titlev" id="titlev" placeholder="Title" autocomplete="on" /></td>
</tr>
<tr>
<td><input type="label" name="authr" id="authr" value="Author:" readonly="readonly" /></td>
<td><input type="text" name="authrv" id="authrv" placeholder="Author" autocomplete="on" /></td>
</tr>
<tr>
<td><input type="label" name="publr" id="publr" value="Publisher:" readonly="readonly" /></td>
<td><input type="text" name="publrv" id="publrv" placeholder="Publisher" autocomplete="on" /></td>
</tr>
<tr>
<td><input type="label" name="page" id="page" value="Pages:" readonly="readonly" /></td>
<td><input type="number" name="pagev" id="pagev" placeholder="Pages" /></td>
</tr>
<tr>
<td><input type="label" name="scope" id="scope" value="Scope:" readonly="readonly" /></td>
<td>
<input list="scp" name="scopev" id="scopev" placeholder="Scope" />
<datalist id="scp">
<option value="PDF to ePub"></option>
<option value="PDF to PRC"></option>
</datalist>
</td>
</tr>
<tr>
<td><input type="label" name="process" id="process" value="Process:" readonly="readonly" /></td>
<td>
<input list="prcs" name="processv" id="processv" placeholder="Process" />
<datalist id="prcs">
<option value="Reflow"></option>
<option value="Fixed"></option>
</datalist>
</td>
</tr>
<tr>
<td><input type="label" name="complx" id="complx" value="Complexity:" readonly="readonly" /></td>
<td>
<input list="cmplx" name="complxv" id="complxv" placeholder="Complexity" />
<datalist id="cmplx">
<option value="Light"></option>
<option value="Simple"></option>
<option value="Medium"></option>
<option value="Complex"></option>
<option value="Heavy Complex"></option>
<option value="Custom"></option>
</datalist>
</td>
</tr>
<tr>
<td><input type="label" name="recdte" id="recdte" value="Received Date:" readonly="readonly" /></td>
<td><input type="date" id="recdtev" name="recdtev" /></td>
</tr>
<tr>
<td><input type="label" name="cnfdte" id="cnfdte" value="Confirm Date:" readonly="readonly" /></td>
<td><input type="date" id="cnfdtev" name="cnfdtev" /></td>
</tr>
<tr>
<td><input type="label" name="duedte" id="duedte" value="Due Date:" readonly="readonly" /></td>
<td><input type="date" id="duedtev" name="duedtev" /></td>
</tr>
<tr>
<td><input type="label" name="esthr" id="esthr" value="Estimated Hours:" readonly="readonly" /></td>
<td><input type="text" name="esthrv" id="esthrv" placeholder="Estimated Hrs" /></td>
</tr>
<tr>
<td><input type="label" name="manpwr" id="manpwr" value="Man Power:" readonly="readonly" /></td>
<td><input type="number" name="manpwrv" id="manpwrv" placeholder="Manpower" /></td>
</tr>
<tr>
<td><input type="label" name="dlvrydte" id="dlvrydte" value="Delivery Date:" readonly="readonly" /></td>
<td><input type="date" id="dlvrydtev" name="dlvrydtev" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="add" id="add" value="Add" /></td>
</tr>
</tbody>
</table>
</form>
Now what i need is, to display the data stored in database, in their respective fields based the option selected first.
Example:
<tr>
<td><input type="label" name="team" id="team" value="Team:" readonly="readonly" /></td>
<td>
<input list="tm" name="teamv" id="teamv" placeholder="Team" />
<datalist id="tm">
<option value="Pre-press"></option>
<option value="eBooks"></option>
</datalist>
</td>
</tr>
<tr>
<td><input type="label" name="prno" id="prno" value="Project No.:" readonly="readonly" /></td>
<td>
<input list="prct" name="prjctv" id="prjctv" placeholder="Project Number" />
<datalist id="prct">
<option value="Project001"></option>
<option value="Project002"></option>
</datalist>
</td>
</tr>
In above code if am selecting any one of the team i.e either pre-press or ebooks, the project number relevant to the team should be listed from the database instead of giving it like this:
<input list="prct" name="prjctv" id="prjctv" placeholder="Project Number" />
<datalist id="prct">
<option value="Project001"></option>
<option value="Project002"></option>
</datalist>
Can someone help me with this. i've already tried some methods but of no use.
Guys if cant understand a question just ask for clarification, don't just put the question on hold.
Thought this would be best for newbies but its not. If am genius to find the solution why hell should i need help from people out there.
Am really very disappointed.
First you need to get the data from the database. Here a doc regarding pdo: http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
then, set the attribute seleted of your option if it is the same as in the database:
<input list="prct" name="prjctv" id="prjctv" placeholder="Project Number" />
<datalist id="prct">
<option value="Project001" <?php echo $databasevalue == "Project001" ? 'selected=true':""; ?>></option>
<option value="Project002" <?php echo $databasevalue == "Project002" ? 'selected=true':""; ?>></option>
</datalist>
Inline not the nice way, but it does the trick and shows the idea
I want to update the subject and other fields by adding multiple subjects, but the issue is it only saves one of subject which I have checked.
How can I solve this issue ?
Below is my code :
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$host="localhost";//host name
$username="root"; //database username
$word="";//database word
$db_name="tuichk";//database name
$tbl_name="data"; //table name
$con=mysqli_connect("$host", "$username", "$word","$db_name")or die("cannot connect");//connection string
$id=$_REQUEST['id'];
$name =$_REQUEST['name'];
$stu_ic = $_REQUEST['stu_ic'];
$address = $_REQUEST['address'];
$contact = $_REQUEST['contact'];
$checkbox1=$_REQUEST['subject'];
$chk="";
$update="update data set name='".$name."', stu_ic='".$stu_ic."', address='".$address."', contact='".$contact."', sub='".$checkbox1."' where id='".$id."'";
mysql_query($update) or die(mysql_error());
$status = "Record Updated Successfully. </br></br><a href='view.php'>View Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}else {
?>
this is my html form
<form name="form" method="post" action="">
<input type="hidden" name="new" value="1" />
<input name="id" type="hidden" value="<?php echo $row['id'];?>" />
<p><input type="text" name="name" placeholder="Enter Name" required value="<?php echo $row['name'];?>" /><input type="text" name="stu_ic" placeholder="Enter Student IC" required value="<?php echo $row['stu_ic'];?>" /></p>
<p><input type="text" name="address" placeholder="Enter Address" required value="<?php echo $row['address'];?>" /><input type="text" name="contact" placeholder="Enter Contact" required value="<?php echo $row['contact'];?>" /></p>
<div style="text-align:center">
<div style="width:400px;border-radius:6px;margin:0px auto">
<table border="1">
<tr>
<td colspan="2">Select Subject:</td>
</tr>
<tr>
<td>Bahasa Melayu</td>
<td><input type="checkbox" name="subject" value="Bahasa Melayu"></td>
</tr>
<tr>
<td>English</td>
<td><input type="checkbox" name="subject" value="English"></td>
</tr>
<tr>
<td>Mathematics</td>
<td><input type="checkbox" name="subject" value="Mathematics"></td>
</tr>
<tr>
<td>Science</td>
<td><input type="checkbox" name="subject" value="Science"></td>
</tr>
<tr>
<td>Sejarah</td>
<td><input type="checkbox" name="subject" value="Sejarah"></td>
</tr>
<tr>
<td>Geography</td>
<td><input type="checkbox" name="subject" value="Geography"></td>
</tr>
<tr>
<td>Additional Mathematics</td>
<td><input type="checkbox" name="subject" value="Additional Mathematics"></td>
</tr>
<tr>
<td>Chemistry</td>
<td><input type="checkbox" name="subject" value="Chemistry"></td>
</tr>
<tr>
<td>Physics</td>
<td><input type="checkbox" name="subject" value="Physics"></td>
</tr>
<tr>
<td>Biology</td>
<td><input type="checkbox" name="subject" value="Biology"></td>
</tr><tr>
<td>Principle Of Accounting</td>
<td><input type="checkbox" name="subject" value="Principle Of Accounting"></td>
</tr><tr>
<td>Ekonomi Asas</td>
<td><input type="checkbox" name="subject" value="Ekonomi Asas"></td>
</tr><tr>
<td>Perdagangan</td>
<td><input type="checkbox" name="subject" value="Perdagangan"></td>
</tr>
</table>
</div>
</form>
HTML input should be
<input type="checkbox" name="subject[]" value="Subject1">
<input type="checkbox" name="subject[]" value="Subject2">
In PHP have many options.
Option 1:
save subjects as string
$subjects = implode(',', $_POST['subject']);
retrieve as string and convert to array
$subjects = explode(',', $field);
Option 2: can save as JSON and retrieve as JSON and decode it.
this is my code inc html form:
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$host="localhost";//host name
$username="root"; //database username
$word="";//database word
$db_name="tuichk";//database name
$tbl_name="data"; //table name
$con=mysqli_connect("$host", "$username", "$word","$db_name")or die("cannot connect");//connection string
$id=$_REQUEST['id'];
$name =$_REQUEST['name'];
$stu_ic = $_REQUEST['stu_ic'];
$address = $_REQUEST['address'];
$contact = $_REQUEST['contact'];
$checkbox1=$_REQUEST['subject'];
$subjects = implode(',', $_POST['subject']);
$subjects = explode(',', $field);
$chk="";
$update="update data set name='".$name."', stu_ic='".$stu_ic."', address='".$address."', contact='".$contact."', sub='".$checkbox1."' where id='".$id."'";
mysql_query($update) or die(mysql_error());
$status = "Record Updated Successfully. </br></br><a href='view.php'>View Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}else {
?>
<div>
<form name="form" method="post" action="">
<input type="hidden" name="new" value="1" />
<input name="id" type="hidden" value="<?php echo $row['id'];?>" />
<p><input type="text" name="name" placeholder="Enter Name" required value="<?php echo $row['name'];?>" /><input type="text" name="stu_ic" placeholder="Enter Student IC" required value="<?php echo $row['stu_ic'];?>" /></p>
<p><input type="text" name="address" placeholder="Enter Address" required value="<?php echo $row['address'];?>" /><input type="text" name="contact" placeholder="Enter Contact" required value="<?php echo $row['contact'];?>" /></p>
<div style="text-align:center">
<div style="width:400px;border-radius:6px;margin:0px auto">
<table border="1">
<tr>
<td colspan="2">Select Subject:</td>
</tr>
<tr>
<td>Bahasa Melayu</td>
<td><input type="checkbox" name="subject[]" value="Bahasa Melayu"></td>
</tr>
<tr>
<td>English</td>
<td><input type="checkbox" name="subject[]" value="English"></td>
</tr>
<tr>
<td>Mathematics</td>
<td><input type="checkbox" name="subject[]" value="Mathematics"></td>
</tr>
<tr>
<td>Science</td>
<td><input type="checkbox" name="subject[]" value="Science"></td>
</tr>
<tr>
<td>Sejarah</td>
<td><input type="checkbox" name="subject[]" value="Sejarah"></td>
</tr>
<tr>
<td>Geography</td>
<td><input type="checkbox" name="subject[]" value="Geography"></td>
</tr>
<tr>
<td>Additional Mathematics</td>
<td><input type="checkbox" name="subject[]" value="Additional Mathematics"></td>
</tr>
<tr>
<td>Chemistry</td>
<td><input type="checkbox" name="subject[]" value="Chemistry"></td>
</tr>
<tr>
<td>Physics</td>
<td><input type="checkbox" name="subject[]" value="Physics"></td>
</tr>
<tr>
<td>Biology</td>
<td><input type="checkbox" name="subject[]" value="Biology"></td>
</tr><tr>
<td>Principle Of Accounting</td>
<td><input type="checkbox" name="subject[]" value="Principle Of Accounting"></td>
</tr><tr>
<td>Ekonomi Asas</td>
<td><input type="checkbox" name="subject[]" value="Ekonomi Asas"></td>
</tr><tr>
<td>Perdagangan</td>
<td><input type="checkbox" name="subject[]" value="Perdagangan"></td>
</tr>
</table>
</div>
</form>
<p><input name="submit" type="submit" value="Update" /></p>
</form>
<?php } ?>
<form action="execute_new.php" id="modalform" method="post">
<td width="147"> <strong>
<font color="#033">Sticker No:</font><font color="#FF0000">*</font></td>
<td width="146"><input type="text" name="stickerno" /></td>
<tr>
<td><strong>
<font color="#033">TO : </font></td>
</tr>
<tr>
<td >
<input name="fname" type="text" />
</td>
<td >
<input name="mname" type="text" />
</td>
<td width="143" align="right">
<input name="lname" type="text" />
</td>
</tr>
<tr>
<td>
First Name</font><font color="#FF0000">*</font>
</td>
<td >
Middle Name</font><font color="#FF0000">*</font>
</td>
<td>
Last Name</font><font color="#FF0000">*</font>
</td>
</tr>
</table><br>
<br>
<table>
<tr>
<td><strong>
<font color="#033"> ADDRESS:</font></font><font color="#FF0000">*</font> </td>
<td align="center"><input name="address" type="text" value="" size="70"></td>
</tr>
</table>
<p> </p>
<font color="#033">
<table border="15" bgcolor="#00FF66" bordercolor="#000000" width="650" cellpadding="1" cellspacing="1">
<br>
<br>
<tr>
<td >LICENSE NO:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="license"/></td>
<td >BIRTH DATE:</td>
<td align="center"><input name="bdate" id="demo1" type="text"><img src="cal.gif" width="16" height="16" border="0"></td>
<tr>
<td >PLATE NO:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="plateno"/></td>
<td >PUV BODY NAME:</td>
<td align="center"><input type="text" name="puvbname" /></td>
</tr>
<tr>
<td >TYPE OF VEHICLE:</td>
<td align="center"><select id="vehicletype" name="vehicletype" style="width:134px">
<option value="Private">Private</option>
<option value="Public">Public</option>
</select>
<td >PUV BODY NO:</td>
<td align="center"><input type="text" name="puvbno" /></td>
</tr>
<tr>
<td >OWNER OF VEHICLE:</td>
<td align="center"><input type="text" name="vehicleowner" /></td>
<td >ADDRESS:</td>
<td align="center"><input type="text" name="taddress" /></td>
</tr>
<tr>
<td >PLACE OF VIOLATION:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="violationplace" /></td>
<td>DATE / TIME:<font color="#FF0000">*</font></td>
<td align="center"><input name="datetime" id="demo2" type="text"><img src="cal.gif" width="16" height="16" border="0">
</tr>
</table><br>
<table border="15" bordercolor="#000000" width="150" cellpadding="1" cellspacing="1">
<tr>Confiscated:</tr>
<br>
<tr><td><input type="radio" name="RadioGroup1" value="License ID" id="RadioGroup1_0" checked>License ID</tr><br>
<tr><td><input type="radio" name="RadioGroup1" value="License O.R." id="RadioGroup1_1">License O.R.</tr>
<tr>
<td> <input type="radio" name="RadioGroup1" value="TCP/TOP" id="RadioGroup1_2">
TCP/TOP</tr>
<tr><td><input type="radio" name="RadioGroup1" value="License Plate" id="RadioGroup1_3">
License Plate</tr>
<tr><td><input type="radio" name="RadioGroup1" value="Not Confiscated" id="RadioGroup1_4">
Not Confiscated</tr>
</tr></table><br />
<center><strong>You are hereby cited for committing the traffic violations / checked hereunder</strong><br /></center>
<br>
<br> <table width="100%px" border="7" cellspacing="1" cellpadding="1" bordercolordark="#000000" style="font-size:13px">
<tr>
<td><input type="checkbox" name="cbox[]" value="Unattended/Illegaly Parked Vehicle" />
Unattended / Illegaly Parked Vehicle</td>
<td><input type="checkbox" name="cbox[]" value="Out of Line Operation/Route Violation" />
Out of Line Operation/Route Violation</br></td>
<tr>
<td><input type="checkbox" name="cbox[]" value="Illegal Parking" />
Illegal Parking</td>
<td><input type="checkbox" name="cbox[]" value="Trip Cutting" />
Trip Cutting</br></td>
<tr>
<td><input type="checkbox" name="cbox[]" value="Illegal Topload" />
Illegal Topload</td>
<td>
<input type="checkbox" name="cbox[]" value="Over Charging" />
Over Charging</td></tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Truck Ban/Tricycle Ban" />
Truck Ban/Tricycle Ban</td>
<td><input type="checkbox" name="cbox[]" value="Refusal to Convey Passenger"/>
Refusal to Convey Passenger</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving in Slippers/Sleeveless shirt" />
Driving in Slippers/Sleeveless shirt</td>
<td>
<input type="checkbox" name="cbox[]" value="Overspeeding/Drag Racing/Reckless Driving" />Overspeeding/Drag Racing/Reckless Driving</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving w/o License/Expired/Invalid License" />
Driving w/o License/Expired/Invalid License</td>
<td><input type="checkbox" name="cbox[]" value="One-way Street Violation" />One-way Street Violation</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No PUV ID" />
No PUV ID</td>
<td><input type="checkbox" name="cbox[]" value="Illegal Loading/Unloading" />Illegal Loading/Unloading</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving Dilapidated">
Driving Dilapidated</td>
<td><input type="checkbox" name="cbox[]" value="Traffic Obstruction"/>Traffic Obstruction</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Junk Vehicle" />
Junk Vehicle</td>
<td><input type="checkbox" name="cbox[]" value="Disregarding Traffic Sign/Light" />Disregarding Traffic Sign/Light</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Smoking 20% Discount Sticker" />
No "No Smoking"/20% Discount Sticker</td>
<td><input type="checkbox" name="cbox[]" value="Illegal Blowing of Horn" />Illegal Blowing of Horn</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Permit Decalsticker" />
No Permit Decalsticker</td>
<td><input type="checkbox" name="cbox[]" value="Failure to obey Police Order" />Failure to obey Police Order</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Stereo Set Operated at Excessive Sound Volume" />
Stereo Set Operated at Excessive Sound Volume</td>
<td>
<input type="checkbox" name="cbox[]" value="No Helmet/Head Gear" />
No Helmet/Head Gear</td>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Trash Can/Receptacle" />
No Trash Can/Receptacle</td>
<td><input type="checkbox" name="cbox[]" value="Smoke Belching" />
Smoke Belching</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Colorum PUV" />
Colorum PUV</td>
<td><input type="checkbox" name="cbox[]" value="Failure to Switch Headlights" />Failure to Switch Headlights</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Plate" />
No Plate</td>
<td><input type="checkbox" name="cbox[]" value="No U-turn" /> No U-turn</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving under the Influence of Liquor" />
Driving under the Influence of Liquor</td>
<td><input type="checkbox" name="cbox[]" value="Dirty Plate" />
Dirty Plate</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Counter Flow" />
Counter Flow</td>
<td><input type="checkbox" name="cbox[]" value="Arrogant Driver/Conductor" />Arrogant Driver/Conductor</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driver's/Conductor's Uniform/I.D." />
Driver's/Conductor's Uniform / I.D.</td>
<td><input type="text" name="oviolation" />
Other Traffic Violations(Specify)</td>
</tr></table>
<br>
</label>
<p align="center">
<p align="center"><strong>Apprehending Office ( Rank & Name )</strong><font color="#FF0000">*</font></p>
<label> </label>
<select name="type" size="1">
<option>Job Order</option>
<option>Permanent</option>
</select>
<input type="text" name="officer" placeholder="Officer Name"/>
</p>
<h5 align="center">PUBLIC ORDER & SAFETY OFFICE</h5>
<h5 align="center"> </h5>
<h5 align="center">
</h5>
</font>
<input type="submit" name="register" value="Add" class="adds"/>
<input type="reset" name="cancel" value="Reset" class="add"/>
<br />
</h5>
</form>
<?php
date_default_timezone_set('Asia/Manila');
$conn=mysql_connect("localhost","root","");
mysql_select_db("dbposo",$conn);
if(isset($_POST['register']))
{
$license=$_POST['license'];
$query = mysql_query("SELECT * FROM tblviolator WHERE license = '$license'");
$fetch_rows = mysql_num_rows($query);
if ( $fetch_rows > 0 )
{
echo "<script>alert('License # already exist')</script>";
header("Refresh: 0;url=new.php");
}
elseif( empty($_POST['stickerno']))
{
echo "<script>alert('Please check if all the * marker field is filled!')</script>";
header("Refresh: 0;url=new.php");
}
else
{
$stickerno=$_POST['stickerno'];
$fname=$_POST['fname'];
$mname=$_POST['mname'];
$lname=$_POST['lname'];
$address=$_POST['address'];
$bdate=$_POST['bdate'];
$plateno=$_POST['plateno'];
$puvbname=$_POST['puvbname'];
$vehicletype=$_POST['vehicletype'];
$puvbno=$_POST['puvbno'];
$vehicleowner=$_POST['vehicleowner'];
$taddress=$_POST['taddress'];
$violationplace=$_POST['violationplace'];
$datetime=$_POST['datetime'];
$confiscated=$_POST['RadioGroup1'];
$violation=$_POST['cbox'];
$oviolation=$_POST['oviolation'];
$type=$_POST['type'];
$officer=$_POST['officer'];
mysql_query("insert into tblviolator(license, stickerno, fname, mname, lname, address, bdate, plateno, puvbname, vehicletype, puvbno, vehicleowner, taddress, violationplace, datetime, confiscated, violation, oviolation, type, officer) values('$license','$stickerno','$fname','$mname','$lname','$address','$bdate','$plateno','$puvbname','$vehicletype','$puvbno','$vehicleowner','$taddress','$violationplace','$datetime','$confiscated','$violation','$oviolation','$type','$officer')",$conn) or die(mysql_error());
echo "<script>alert('Successfully Recorded, <br>
First penalty: 100php!')</script>";
header("Refresh: 0;url=new.php");
}
}
?>
What is my error here?
if you select more than one checkbox then $_POST['cbox'] becomes array .so try this
if(is_array($_POST['cbox']))
$violation=implode(',',$_POST['cbox']);
else
$violation=$_POST['cbox'];
To avoid injection better use http://php.net/manual/de/function.mysql-real-escape-string.php
If you check more than one option for the checkbox the variable $violation will be an array. Try to check multiple options and just safe the first one.
Probably if you want to store it as varchar you shoud concatenate all values.
Hi everyone, i'm new to programming. I need to develop a rating system with check boxes and text-fields where user clicks the subjects from the list and add his rating/experience in the text field. All these subjects and ratings are added to the database with the subject id and the rating. So the issue is, I don't know how to write the associate array to get the selected subjects and their appropriate rating to insert into the database. Can anyone please provide me some codes or samples similar to this. So, I can get some idea how to do this. Thanks in advance :)
This is the HTML sample code
<form action="" method="post">
<table width="372" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="24"><input type="checkbox" name="subid1" value="1" id="subid1"></td>
<td width="203">Maths</td>`enter code here`
<td width="145"><input type="text" name="sub1" id="sub1"></td>
</tr>
<tr>
<td><input type="checkbox" name="subid2" value="2" id="subid2" /></td>
<td>Physics</td>
<td><input type="text" name="subid2" id="subid2" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid3" value="3" id="subid3" /></td>
<td>Computing</td>
<td><input type="text" name="subid3" id="subid3" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid4" value="4" id="subid4" /></td>
<td>Chemistry</td>
<td><input type="text" name="subid4" id="subid4" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid5" value="5" id="subid5" /></td>
<td>Biology</td>
<td><input type="text" name="subid5" id="subid5" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid7" value="6" id="subid7" /></td>
<td>Human Biology</td>
<td><input type="text" name="subid6" id="subid6" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
This will do the job on client side:
<input type="checkbox" name="cb[myID1]" value="1" />
<input type="text" name="t[myID1]" value="" />
<input type="checkbox" name="cb[myID2]" value="1" />
<input type="text" name="t[myID2]" value="" />
and this can be used on server side:
$usedTexts = array();
if ( array_key_exists("t", $_POST) && is_array($_POST["t"])
&& array_key_exists("cb", $_POST) && is_array($_POST["cb"])
)
{
$usedTexts = array_intersect_key($_POST["t"], $_POST["cb"]);
}
see manual for server side: http://us3.php.net/array_intersect_key
edit: fixed to POST; added array_key_exists() and is_array()
My users can enter more than one address but I want an actual button that generates the extra fields as only one address is compulsory and empty fields will look ugly! I also need the extra addresses to go into mysql database.
How would I do with Javascript if PHP is not possible
Some code that may help:
<td width="732" valign="top"><p>
<h3 class="main">Address Details</h3>
<p class="normal"> You are able to add up to 3 addresses but only 1 is compulsory.
However it would be helpful if you could insert 3 addresses:
<ul>
<li>Permanent home address</li>
<li>Postal address (where you will be from June to September)</li>
<li>Local address (where you currently live)</li>
</ul>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* $e <br>";
}
echo "</div>";
}
?>
<br>
<form action="address.php" method="post" name="regForm" id="regForm" >
<table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms">
<tr>
<td>Street<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Street" type="text" id="Street" class="required" size="50">
</tr>
<tr>
<td>Line 2
</td>
<td><input name="Line2" type="text" id="Line2" class="required" size="50">
</tr>
<tr>
<td>Line 3
</td>
<td><input name="Line3" type="text" id="Line3" class="required" size="50">
</tr>
<tr>
<td>Town<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Town" type="text" id="Town" class="required" size="30">
</tr>
<tr>
<td>Postcode<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Postcode" type="text" id="Postcode" class="required" size="10">
</tr>
<tr>
<td>Country <font color="#CC0000">*</font></span></td>
<td><select name="Country" class="required" id="select8">
<option value="" selected></option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
(etc)
</select></td>
</tr>
<tr>
<td>Telephone Number<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Tele" type="text" id="Tele" class="required" >
</tr>
<tr>
<td>Fax<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Fax" type="text" id="Fax" class="required" >
</tr>
<tr>
<td>Mobile<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Mobile" type="text" id="Mobile" class="required" >
</tr>
<tr>
<td>Type <font color="#CC0000">*</font></span></td>
<td><select name="Type" class="required" id="select8">
<option value="" selected></option>
<option value="H">Home</option>
<option value="P">Postal</option>
<option value="L">Local</option>
</table>
<p align="center">
<input name="doAddress" type="submit" id="doAddress" value="Submit">
to fix your parse error - put ; at the end of line $numrows = 0 + $_GET['numrows']
to generate more fields dynamically - use javascript, really, it's way better for this task than php