How to fix error in html [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have created one HTML form and i have written php script also to connect to database. If i enter data in form and hit UPDATE button in form, its showing error like below,
<form action="process.php" method="Post"/>
<style>
p{
float:left;
}
</style>
<fieldset>
<legend align="center"><FONT color=default>Enter information Of SO's</legend>
<p align="center">
<label for="SO_ID"><FONT color=white>SO_ID</label>
<br/>
<input type="varchar" id="SO_ID" name="SO_ID"required/>
</p>
<p align="center">
<label for="No.of_samples"><FONT color=white>No.of samples</label>
<br/>
<input type="int" id="No.of_samples" name="No.of_samples"required/>
</p>
<p align="center">
<label for="Sample name"><FONT color=white>Sample name</label>
<br />
<input type="varchar" id="Sample name" name="Sample name"required/>
</p>
<p align="center">
<label for="Client name"><FONT color=white>Client name</label>
<br />
<input type="text" id="Client name" name="Client name"required/>
</p>
<p align="center">
<label for="Institution"><FONT color=white>Institution</label>
<br/>
<input type="text" id="Institution" name="Institution"required/>
</p>
<p align="center">
<label for="Run number "><FONT color=white>Run number </label>
<br/>
<input type="int" id="Run number" name="Run number"required/>
</p>
<p align="center">
<label for="Obtained reads"><FONT color=white>Obtained reads</label>
<br/>
<input type="int" id="Obtained reads" name="Obtained reads"required/>
</p>
<p align="center">
<label for="Re run Info"><FONT color=white>Re run Info</label>
<br/>
<input type="text" id="Re run Info" name="Re run Info"required/>
</p>
<p align="center">
<label for="Total reads"><FONT color=white>Total reads</label>
<br/>
<input type="int" id="Total reads" name="Total reads"required/>
</p>
<p align="center">
<label for="Run date"><FONT color=white>Run date</label>
<br/>
<input type="date" id="Run date" name="Run date"required/>
</p>
<p align="center">
<label for="Raw data location"><FONT color=white>Raw data location</label>
<br/>
<input type="varchar" id="Raw data location" name="Raw data location"required/>
</p>
<p align="center">
<label for="Analyst"><FONT color=white>Analyst</label>
<br/>
<input type="varchar" id="Analyst" name="Analyst"required/>
</p>
<p align="center">
<label for="Mentor"><FONT color=white>Mentor</label>
<br/>
<input type="text" id="Mentor" name="Mentor"required/>
</p>
<p align="center">
<label for="Analysis start date"><FONT color=white>Analysis start date</label>
<br/>
<input type="date" id="Analysis start date" name="Analysis start date"required/>
</p>
<p align="center">
<label for="Analysis end date"><FONT color=white>Analysis end date</label>
<br/>
<input type="date" id="Analysis end date" name="Analysis end date"required/>
</p>
<p align="center">
<label for="Report location"><FONT color=white>Report location</label>
<br/>
<input type="varchar" id="Report location" name="Report location"required/>
</p>
</fieldset>
<div style="text-align:center">
<button action= "process.php" method="post" >
<img alt="ok" src=
"http://www.blueprintcss.org/blueprint/plugins/buttons/icons/tick.png" />
UPDATE
</button>
</form>
the above script is saved in "process.html"
now below PHP script.
<?php
define('DB_NAME','ProcessTrackingSystem');
define('DB_USER','root');
define('DB_PASSWORD','');
define('DB_HOST','localhost');
$link=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if(!$link){
die('couldnot connect:'.mysql_error());
}
$db_selected=mysql_select_db(DB_NAME,$link);
if(!$db_selected){
die('cannot use'.DB_NAME.':'.mysql_error());
}
$value1 =$_POST['SO_ID'];
$value2 =$_POST['No.of samples'];
$value3 =$_POST['Sample name'];
$value4 =$_POST['Client name'];
$value5 =$_POST['Institution'];
$value6 =$_POST['Run number '];
$value7 =$_POST['Obtained reads'];
$value8 =$_POST['Re run Info'];
$value9 =$_POST['Total reads'];
$value10 =$_POST['Run date'];
$value11 =$_POST['Raw data location'];
$value12 =$_POST['Analyst'];
$value13 =$_POST['Mentor'];
$value14 =$_POST['Analysis start date'];
$value15 =$_POST['Analysis end date'];
$value16 =$_POST['Report location'];
$sql="INSERT INTO ProcessDetails (SO_ID, No.of_samples, Sample_name, Client_name, Institution, Run_number, Obtained_reads, Re_run_Info, Total_reads, Run_date, Raw_data_location, Analyst, Mentor, Analysis_start_date, Analysis_end_date, Report_location) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5','$value6', '$value7', '$value8', '$value9', '$value10','$value11', '$value12', '$value13', '$value14', '$value15','$value16')";
if(!mysql_query($sql)){
die('error:'.mysql_error());
}
header('Location:process.html');
mysql_close();
?>
now if i enter the data into html form, its showing error that "error:Unknown column 'No.of_samples' in 'field list'".
anyone help me out to fix this error and get desired output.
Thanks in advance....

Assuming that a No.of_samples column exists in your table, quote the name with backticks (`) in your query:
$sql="INSERT INTO ProcessDetails (SO_ID, `No.of_samples`, Sample_name, Client_name, Institution, Run_number, Obtained_reads, Re_run_Info, Total_reads, Run_date, Raw_data_location, Analyst, Mentor, Analysis_start_date, Analysis_end_date, Report_location) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5','$value6', '$value7', '$value8', '$value9', '$value10','$value11', '$value12', '$value13', '$value14', '$value15','$value16')";
Also, you might want to look into SQL injection security risks, and into using the non-deprecated mysqli_* functions instead of the deprecated mysql_* ones.

You are inserting to column No.of_samples which does not exist!

Related

i want to store values in two tables but i'm able store in single table

i have two table rooinventory and reservation i want to store values in that tables but its getting inserting in rooinventory table only..
demo.php
<form name="checkoutForm" method="post" action="order.php">
<div class="container" style="float: left; width: 299px; margin-left: 12px;">
<span class="top-label">
<span class="label-txt">Room Details</span>
</span>
<div class="content-area" style="border-radius:15px;">
<div>
</div>
<div class="content drop-here">
<div id="cart-icon">
<img src="img/Shoppingcart_128x128.png" alt="shopping cart" class="pngfix" width="128" height="128" />
<img src="img/ajax_load_2.gif" alt="loading.." id="ajax-loader" width="16" height="16" />
</div>
<input name="start" type="hidden" value="<?php echo $arival; ?>" />
<input name="end" type="hidden" value="<?php echo $departure; ?>" />
<input name="numnights" type="hidden" value=<?php echo $numberofnights; ?>" />
<div>
<div id="item-list">
</div>
<div id="total"></div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<span class="top-label">
<span class="label-txt">Personal Details</span>
</span>
<div class="content-area" style="border-radius:15px; padding-bottom: 25px;">
<div>
Firstname:<br>
<input type="text" name="fname" id="boxy" pattern="[A-Za-z]{1,32}" required="" /><br>
lastname:<br>
<input type="text" name="lname" id="boxy" required="" /><br>
Address:<br>
<input type="text" name="address" id="boxy" pattern="[A-Za-z]{1,32}" required="" /><br>
City:<br>
<input type="text" name="city" id="boxy" required="" /><br>
Country:<br>
<input type="text" name="country" id="boxy" required="" /><br>
Email:<br>
<input type="email" name="email" id="boxy" /><br>
Contact Number:<br>
<input type="text" name="contact" id="boxy" required="" /><br>
<input type="hidden" name="confirmation" id="boxy" value="<?php echo $confirmation ?>" /><br>
<input type="submit" name="check" onclick="document.forms.checkoutForm.submit(); return false;" class="button" value="Checkout" id="boxy" style="width: 147px; margin-top: 18px;">
</div>
</div>
</div>
</form>
order.php
<?php
$confirmation = $_POST['confirmation'];
$numnights=round($_POST['numnights']);
$arival=$_POST['start'];
$departure=$_POST['end'];
$firstname=$_POST['fname'];
$lastname=$_POST['lname'];
$address=$_POST['address'];
$city=$_POST['city'];
$country=$_POST['country'];
$email=$_POST['email'];
$contact=$_POST['contact'];
$stat='active';
$roomid=$_POST['id'];
$qty=$_POST['qty'];
$price=$_POST['price'];
$roomname=$_POST['roomname'];
$N = count($roomid);
$ip_sqlq=mysql_query("select * from rooinventory where confirmation='$confirmation' and arrival='$arival'and departure='$departure'");
$countq=mysql_num_rows($ip_sqlq);
if($countq==0)
{
for($i=0; $i < $N; $i++)
{
mysql_query("INSERT INTO rooinventory (room, qty, arrival, departure, status, confirmation) VALUES ('$roomid[$i]','$qty[$i]','$arival','$departure','$stat','$confirmation')");
echo '<h2>'.$qty[$i].' x '.$roomname[$i].' = '.$ble=$qty[$i]*$price[$i].'</h2>';
echo '<div style="display:none;">';
$dddd=$ble;
$total=$total+$dddd;
echo '</div>';
}
mysql_query("INSERT INTO reservation (firstname, lastname, city, address, country, email, contact, arrival, departure, result, payable, status, confirmation) VALUES ('$firstname','$lastname','$city','$address','$country','$email','$contact','$arival','$departure','$numnights','$total','$stat','$confirmation')");
header("location: paypalpayout.php?confirm=$confirmation");
}
else{
header("location: ../index.php");
}
?>
Could it be the data in one of your variables is causing the second query to fail? Since they're not bound as parameters or at least escaped, they could be altering your actual query. For instance, if there's an apostrophe in any of your data, it's going to break the query.

Can't insert values in database using form

I have a form where users can register other accounts. It was working fine until I changed the data type of the column date to data type date (I was using varchar so I changed it to date). After changing the datatype, the registration stopped working. I don't get an error but I can't see the new account when I try to view the records.
Here's my form:
<div class="main">
<div class="one">
<div class="register">
<center><h3>Add Account</h3></center>
<form name="reg" action="code_exec.php" onsubmit="return validateForm()" method="post">
<div>
<label>ID</label>
<input type="text" name="id" required>
</div>
<div>
<label>First Name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lastname" required>
</div>
<div>
<label>Email</label>
<input type="text" name="email" placeholder="user#teamspan.com" required>
</div>
<div>
<label>Username</label>
<input type="text" name="username" required>
</div>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<div>
<label>Street Address</label>
<input type="text" name="street" required>
</div>
<div>
<label>Town/Suburb</label>
<input type="text" name="town" required>
</div>
<div>
<label>City</label>
<input type="text" name="city" required>
</div>
<div>
<label>Contact</label>
<input type="text" name="contact" required>
</div>
<div>
<label>Gender</label>
<select name="gender" required>
<option disabled selected hidden>Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div>
<label>User Levels</label>
<select name="user_levels" required>
<option disabled selected hidden>Select Access Level</option>
<option value="0">Employee</option>
<option value="1">Administrator</option>
<option value="2">Manager</option>
<option value="1">HR</option>
</select>
</div>
<div>
<label>Date</label>
<input type="text" readonly="readonly" name="date" value="<?php echo date("m/j/Y");?>" required>
</div>
<div>
<label>Sick Leave</label>
<input type="text" name="sickleave" required>
</div>
<div>
<label>Vacation Leave</label>
<input type="text" name="vacationleave" required>
</div>
<div>
<label>Picture (Link)</label>
<input type="text" name="picture" value="img/emp/" required>
</div>
<div>
<label></label>
<input type="submit" name="submit" value="Add Account" class="button" style="color: white;" />
<a href="hr_panel.php"><input type="button" value="Back" class="button" style="color: white;" />
</div>
</form>
</div>
</div>
And here's code_exec.php
<?php
session_start();
include('connection.php');
$id=$_POST['id'];
$username=$_POST['username'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$street=$_POST['street'];
$town=$_POST['town'];
$city=$_POST['city'];
$contact=$_POST['contact'];
$gender=$_POST['gender'];
$password=$_POST['password'];
$user_levels=$_POST['user_levels'];
$date=$_POST['date'];
$picture=$_POST['picture'];
$sickleave=$_POST['sickleave'];
$vacationleave=$_POST['vacationleave'];
mysqli_query($bd, "INSERT INTO employee(id, firstname, lastname, username, email, street, town, city, contact, gender, password, user_levels, date, picture, sickleave, vacationleave)
VALUES ('$id', '$firstname', '$lastname', '$username', '$email', '$street', '$town', '$city', '$contact', '$gender', '$password', '$user_levels', '$date', '$picture', '$sickleave', '$vacationleave')");
echo "<script>alert('Successfully Added!'); window.location='register.php'</script>";
mysqli_close($con);
?>
Database Schema:
DB Schema
As others have already stated, your date format may not be correct. And you need to look at securing your queries against sql injection.
In order to get you date issue fixed try replacing:
$date=$_POST['date'];
With:
$date=date('Y-m-d', strtotime($_POST['date']));
The Date format for sql is described as YYYY-MM-DD meaning a four digit year-two digit month - two digit day.
You need to convert the received date from your input date :
$dt = \DateTime::createFromFormat('m/j/Y', $_POST['date']);
See this StackOverflow answer for more informations.
Moreover, as #Syscall said, you should also pay attention to your query which is open to SQL injections. To prevent that, you should use a PDO statement, for example :
$stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name');
$stmt->execute(array('name' => $name));
Example taken from How can I prevent SQL injection in PHP?

Timestamp in html

I am trying to store a timestamp in my database. HTML code:
<form action="insert.php" method="POST"/>
<style>
p{
float:center;
}
</style>
<Font color=red > <center>Support or Analysis Tracker (SoAT) </center></Font>
</br>
</br>
<p align="left">
<label for="PROCESS"><FONT color=default>Analysis/Support</label> &nbsp</t>
<select id="PROCESS" name="PROCESS">
<option value="Analysis">Analysis</option>
<option value="Support">Support</option>
</select>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<label for="SO_NUMBER"><FONT color=default>SO_Number</label>
<input type="text" id="SO_NUMBER" name="SO_NUMBER" value ="SO_" required/>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<label for="PERSON_INCHARGE"><FONT color=default>Person_Incharge</label>
<input type="text" id="PERSON_INCHARGE" name="PERSON_INCHARGE" required/></br>
</br></br>
</br>
</p>
<p align="left">
<label for="DESCRIPTION"><FONT color=default>Description</label>
<input type="text" id="DESCRIPTION" name="DESCRIPTION" />
</p>
</br>
</br>
<div style="text-align:center">
<button>
<img alt="ok" src=
"http://www.blueprintcss.org/blueprint/plugins/buttons/icons/tick.png" />
INSERT
</button>
</fieldset>
</form>
After hitting the insert button, I need to store the current time and date in the database. The backend database structure is as following:
In these cases you can use from now() function of mysql.
Insert INTO tablename(RECEIVED) VALUES(now())
with this structure it use from mysql server date and time

Mysql Empty Post Error

<form action="gonder.php" method="post">
<fieldset>
<label for="ad">Ad:</label>
<input type="text" id="ad" placeholder="Tam Adınızı Giriniz" />
<label for="soyad">Soyad:</label>
<input type="text" id="soyad" placeholder="Soyadınızı Giriniz" />
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Email Adresinizi Giriniz" />
<label for="mesaj">Mesaj:</label>
<textarea id="mesaj" placeholder="Mesajınız"></textarea>
<center></center>
<center><input type="submit" value="Onaya Gönder" /></center>
</fieldset>
</form>
This one is my post form and this one ise gonder.php
<?php
$con=mysqli_connect("localhost","root","","yeniziyaretci");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO mesajlar (ad, soyad, email, mesaj)
VALUES ('$_POST[ad]','$_POST[soyad]','$_POST[email]','$_POST[mesaj]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "";
mysqli_close($con);
header("location:index.php?cmd=1");
?>
When I tried to post. They dont give eny error but they send it to mysql as a empty . Like this.
Your input elements have no name attributes.
Also, please read up on the thing called 'sql injection'.
You must select the inputs by name not by id.
change
<input type="text" id="ad" placeholder="Tam Adınızı Giriniz" />
to
<input type="text" name="ad" id="ad" placeholder="Tam Adınızı Giriniz" />
You're using wrong and insecure way to query your database. To get the one you have working, just change your $sql declaration as follows:
$sql = sprintf('INSERT INTO mesajlar (ad, soyad, email, mesaj) VALUES ("%s", "%s", "%s", "%s")', $_POST['ad'], $_POST['soyad'], $_POST['email'], $_POST['mesaj']);
But I would suggest you to learn ways to avoid mysql injection.
EDIT
And yes, you're missing "name" attributes on your form.
Put this, it will work:
<form action="gonder.php" method="post">
<fieldset>
<label for="ad">Ad:</label>
<input type="text" id="ad" name=="ad" placeholder="Tam Adınızı Giriniz" />
<label for="soyad">Soyad:</label>
<input type="text" id="soyad" name="soyad" placeholder="Soyadınızı Giriniz" />
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Email Adresinizi Giriniz" />
<label for="mesaj">Mesaj:</label>
<textarea id="mesaj" name="mesaj" placeholder="Mesajınız"></textarea>
<center></center>
<center><input type="submit" value="Onaya Gönder" /></center>
</fieldset>
</form>
Either try
$sql="INSERT INTO mesajlar (ad, soyad, email, mesaj)
VALUES
('".$_POST[ad]."','".$_POST[soyad]."','".$_POST[email]."','".$_POST[mesaj]."')";
or
$sql="INSERT INTO mesajlar (ad, soyad, email, mesaj)
VALUES
('{$_POST[ad]}','{$_POST[soyad]}','{$_POST[email]}','{$_POST[mesaj]}')";
EDIT
Sorry I didn't notice but there is an issue in your html form too
you need to have name="" attributes into you form elements as suggested by Ø Hanky Panky Ø
<form action="gonder.php" method="post">
<fieldset>
<label for="ad">Ad:</label>
<input type="text" id="ad" name="ad" placeholder="Tam Adınızı Giriniz" />
</fieldset>
</form>

Form placement in a div [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I tried to create a form that covers almost all of the content of my page. Since the input field is scattered, it verifies but still proceeds to the next page afterwards. I don't know what the problem is; it works fine in HTML and PHP formats when I try it offline. The problem happens when I upload it to the server.
The script:
<form method="post" action="step.php" id="form1">
<div id="content">
<center>
<br><br><br>
<input id="sig" name="sig" type="text" class="validate[sign] text-input" style="margin-left:-180px;visibility:hidden;height:0px;"/>
<div id="signatureparent">
<div id="signature"></div>
</div>
</div>
</center>
<!====================================================================================>
<div id="content">
<div id="wrapper">
<div id="form-div">
<center><strong>Please enter the information for the person who will be the primary contact for our account set up team. If left blank we will use the information in the billing section.</strong></center>
<div id="wrapper3">
<div id="form-div">
<center>
<table cellpadding='0' cellspacing='27'>
<tr>
<td>
<!====================================================================================>
<div style="display:none">
<label for="name"><strong>First Name<font color=red size=3> *</font></strong></label>
<p class="name">
<input name="name" readonly="readonly" type="text" class="validate[custom[name]] text-input" id="Name" value="<?php echo $_POST["name"]; ?>" />
</p>
<label for="last" style="margin-left:45px;"><strong>Last Name<font color=red size=3> *</font></strong></label>
<p class="last">
<input name="last" style="margin-left:45px;" readonly="readonly" type="text" class="validate[custom[last]] text-input" id="last" value="<?php echo $_POST["last"]; ?>" />
</p>
</div>
<!====================================================================================>
<label for="cname"><strong>First Name<font color=red size=3> *</font></strong></label>
<p class="cname">
<input name="cname" type="text" class="validate[custom[cname]] text-input" id="cname" value="" />
</p>
<label for="cemail"><strong>E-mail<font color=red size=3> *</font></strong></label>
<p class="cemail">
<input name="cemail" type="text" class="validate[custom[cemail]] text-input" id="cemail" value="" />
</p>
<!====================================================================================>
</td><td>
<label for="clast" style="margin-left:45px;"><strong>Last Name<font color=red size=3> *</font></strong></label>
<p class="clast">
<input name="clast" style="margin-left:45px;" type="text" class="validate[custom[clast]] text-input" id="clast" value="" />
</p>
<label for="cphone" style="margin-left:45px;"><strong>Phone<font color=red size=3> *</font></strong></label>
<p class="cphone">
<input type="text" class="validate[custom[mob]] text-input" name="cphone" id="cphone" style="margin-left:45px;width:100px" />
<b>ext</b><input style="width:25px; margin-left:5px;" type="text" class="validate[custom[ext]] text-input" name="cext1" id="cext1" />
</p>
</td><td>
<!====================================================================================>
<label for="ccom" style="margin-left:45px;"><strong>Company<font color=red size=3> *</font></strong></label>
<p class="com">
<input type="text" class="validate[custom[ccom]] text-input"name="ccom" id="ccom" onblur="this.value = this.value.toTitleCase();" style="margin-left:45px;" />
</p>
<label for="cmob" style="margin-left:45px;"><strong>Mobile#</strong></label>
<p class="mob">
<input type="text" class="validate[custom[mob]] text-input" name="cmob" id="cmob" style="margin-left:45px;width:100px;" />
<b>ext</b><input style="width:25px; margin-left:5px;" type="text" class="validate[custom[ext]] text-input" name="cext2" id="cext2" />
</p>
</div></div></div></div></div>
</center>
</td></tr></table>
<div>
<!====================================================================================>
<br>
<div id="wrapper">
<div id="form-div">
<table><tr><td><div style="margin-left:210px;" >
<p><font color=red size=2%><b>Clicking this button means that you accept the terms and conditions of our service </b></font></td><td>
<div id="accept"><button style="margin-left:10px;border: 0; background: transparent" type="submit"><img src=img/acept.png height=30 /></button>
</div>
</tr></td></table>
</div>
</div>
<br><br><br>
</form>
It should first verify the contents, then proceed.
It appears that your form does not run any code on submitting it. You'd want your form to have:
<form method="post" action="step.php" id="form1" onsubmit="return validate()">
This is assuming that your validation code is as a JavaScript function.

Categories