$path= "Image/".$_FILES["image"]["name"]; - php

"Undefined index: image in
C:\xampp\htdocs\learn_php\Category\insertup.php on line 34" this error
is showing and that line 34 is-
$path= "Image/".$_FILES["image"]["name"];
EDIT.PHP File:-
<?php
if(isset($_GET['id']) && $_GET['id'] != '') {
mysql_connect('localhost', 'root', '');
mysql_select_db('opencart_php');
$id=$_GET['id'];
$query=mysql_query("SELECT * FROM categories WHERE Id='".$id."'");
$row=mysql_fetch_array($query);
$cname = $row['category_name'];
$sname = $row['sort_order'];
$desc = $row['description'];
$image = $row['image'];
} else {
$id = '';
$cname = '';
$sname = '';
$desc = '';
$image = '';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Category Details</title>`
<h1 align="center">Category Details</h1>
</head>
<body>
<table width="400" border="1" align="center">
<tr>
<td><form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form_data">
<table width="334" border="0" align="center">
<tr>
<td><b>Category Name:</b></td>
<td><input type="text" name="cname" value="<?php echo $cname; ?>"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><b>Sort Order:</b></td>
<td><input type="text" name="sorder" size="5" value="<?php echo $sname; ?>"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="40"><b>Description:</b></td>
<td><input type="text" rows="10" cols="20" name="desc" value="<?php echo $desc; ?>" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="37"><b>Image:</b></td>
<td><input type="file" name="image" id="image"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><b>Status:</b></td>
<td><select name="status">
<option value='1'>Enable</option>
<option value='0'>Disable</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<table width="368">
<tr>
<td width="173" align="right"><input type="submit" name="submit" value="Submit"></td>
<td width="183" align="center"><input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
INSERTUP.PHP :-
if($_POST["cname"] != "" && $_POST["desc"] != "" && $_POST["image"] != "") {
$_SESSION['cname']=$_POST["cname"];
//echo $_SESSION['cname'];
$query=mysql_query("SELECT * FROM categories WHERE category_name='".$_SESSION['cname']."'");
$row=mysql_fetch_array($query);
$c_name=$row['category_name'];
$img=$row['image'];
echo $c_name;
//$id=$row['id'];
//if(isset($_FILES["image"])) {
print_r($_FILES);
if($cname != $c_name && $image != $img) {
$path= "Image/".$_FILES["image"]["name"];
if($path != '') {
if(copy($_FILES["image"]["tmp_name"], $path)) {
$sql=mysql_query("INSERT INTO categories (category_name, sort_order, description, image, status)
VALUES ('$cname', '$sorder', '$desc', '$image', '$status')") or die(mysql_error());
header('location: index.php');
} else {
echo "Error in Insertion";
}
} else {
echo "Image not Uploaded";
}
} //}
}
}

On your html there is a typo in (form-data)
change
<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form_data">
to
<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form-data">

In your HTML, in form has to be enctype="multipart/form-data", not enctype="multipart/form_data".
<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form-data">
Then, $_POST['image'] in your condition on line 1 of insertup.php will be probably empty, so change that to
if($_POST["cname"] != "" && $_POST["desc"] != "" && !empty($_FILES["image"]["name"])) {

Related

Want to update a comma-seperated string

I want to make a CMS that is able to update my articles. When I use the update page I get the following error:
Notice: Undefined variable: post_image in C:\xampp\htdocs\website\admin\edit_posts.php on line 105
This is my code:
<?php
session_start();
if(!isset($_SESSION['user_name'])){
header("location: ../login.php");
}
else {
?>
<html>
<head>
<title>Admin Panel</title>
<link rel="stylesheet" href="../apearance/stylesheet.css" />
</head>
<body>
<div id="navbar">
<div id="logo"><img id="logo" src="../apearance/logo.png" height="27px"></div>
<a id="button" href="view_posts.php">View Posts</a>
<a id="button" href="index.php?insert=insert">Insert New Post</a>
<a id="button" href="#">View Comments</a>
<a id="button" href="#">Webshop</a>
<a id="button" href="#">Do do list</a>
<a id="button" href="logout.php"><span style="color:red">Logout</span></a>
<br><hr>
</div>
<?php
include("includes/connect.php");
if(isset($_GET['edit'])){
$edit_id = $_GET['edit'];
$edit_query = "select * from posts where post_id = '$edit_id' ";
$run_edit = mysql_query($edit_query);
while ($edit_row = mysql_fetch_array($run_edit)){
$post_id = $edit_row['post_id'];
$post_title = $edit_row['post_title'];
$post_category = $edit_row['post_category'];
$post_header_image = $edit_row['post_header_image'];
$post_image = $edit_row['post_image'];
$post_content = $edit_row['post_content'];
$post_content2 = $edit_row['post_content2'];
$post_video = $edit_row['post_video'];
}}
?>
<div id="tile" height="100px">
<form method="post" action="edit_posts.php?edit_form=<?php $post_id; ?>" enctype="multipart/form-data">
<table align="center" border="0">
<tr>
<td align="center" colspan="2"><h1>Edit Post Here</h1></td>
</tr>
<tr>
<td align="left">Post Title:</td>
<td><input value="<?php echo $post_title; ?>" type="text" name="title" size="30"></td>
</tr>
<tr>
<td align="left">Post Category:</td>
<td><input value="<?php echo $post_category; ?>" type="text" name="category" size="30"></td>
</tr>
<tr>
<td align="left">Post header Images:</td>
<td>
<input type="file" name="header_image">
</td>
</tr>
<tr>
<td>
</td>
<td>
<img src="../images/<?php echo $post_header_image; ?>" height="100" >
</td>
</tr>
<tr>
<td align="left">Post Content:</td>
<td><textarea name="content" cols="30" rows="15"><?php echo $post_content; ?></textarea></td>
</tr>
<tr>
<td align="left">Post Images:</td>
<td><input type="file" name="files[]" multiple>
</td>
</tr>
<tr>
<td>
</td>
<td>
<?php
$values = explode(',', $post_image);
if( count($values)){
foreach($values as $value){
echo "<img src=\"../images/".$value."\" height=\"100\">";
}
}
?>
</td>
</tr>
<tr>
<td align="left">Post Content2:</td>
<td><textarea name="content2" cols="30" rows="15"><?php echo $post_content2; ?></textarea></td>
</tr>
<tr>
<td align="left">Post Video:</td>
<td><textarea name="video" cols="30" rows="15"><?php echo $post_video; ?></textarea></td>
</tr>
<tr>
<td align="right" colspan="6"><input type="submit" name="submit" value="Update Now"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['update'])){
$update_id = $_GET['edit_form'];
$post_title1 = $_POST['title'];
$post_date1 = date('m-d-y');
$post_category1 = $_POST['category'];
$post_content1 = $_POST['content'];
$post_content21 = $_POST['content2'];
$post_video1 = $_POST['video'];
$post_header_image1= $_FILES['header_image']['name'];
$header_image_tmp= $_FILES['header_image']['tmp_name'];
$filenames = array_values($_FILES['files']['name']);
$post_image1 = rtrim(implode(',', $filenames), ',');
if($post_title1=='' or $post_category1=='' or $post_content1=='' or $post_header_image1==''){
echo "<script>alert('Any of the fields is empty')</script>";
exit();
}
else {
move_uploaded_file($header_image_tmp,"../images/$post_image1");
$update_query = "update posts set post_title='$post_title1',post_date='$post_date1',post_category='$post_category1',post_header_image='$post_header_image1',post_image='$post_image1',post_content='$post_content1',post_content2='$post_content21',post_video='$post_video1' where post_id='$update_id'";
if(mysql_query($update_query)){
echo "<script>alert('Post has been updated')</script>";
echo "<script>window.open('view_posts.php','_self')</script>";
}
}
}
?>
<?php }?>
Any help would be much appreciated.

Page is redirecting without running the processes

This page is redirecting without running the validation processes, if i comment out the header redirect all the processes work as they should, as soon as i uncomment the header tag when the page loads it automatically redirects, this page is modelled from the members registered page i have created which runs fine without this issue, so i cant see the issue, would someone please be kind enough to help me resolve this issue please.
Following is the page code with the header tag commented out
<?php
include_once 'functions.php';
//Start session
sec_session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) == '')) {
header("location: login.php");
exit();
}
if(!isset($_SESSION['login']) == '1') {
header("location: admin_login.php");
exit();
}
?>
<?php
//display users info with checkbox to delete
$sql = "SELECT * FROM `links` LIMIT 0, 30 ";
$result = mysqli_query($mysqli, $sql);
?>
<?php
// define variables and set to empty values
$link_titleErr = $type_of_linkErr = $web_linkErr = "";
$link_title = $type_of_link = $web_link = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$link_title = test_input($_POST["link_title"]);
$type_of_link = test_input($_POST["select"]);
$web_link = test_input($_POST["web_link"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["link_title"])) {
$link_titleErr = "**Link Title is required**";
} else {
$link_title = test_input($_POST["link_title"]);
if (!preg_match("/^[a-zA-Z ]*$/",$link_title)) {
$link_titleErr = "**Only letters and white space allowed**";
}
}
if (empty($_POST["web_link"])) {
$web_linkErr = "**Web Link is required**";
} else {
// do nothing
}
if($_POST['select'] == "") {
$type_of_linkErr = "**Type of Link is required**";
}
else {
// do nothing
}
}
if ($link_titleErr == '' && $web_linkErr == '' && $type_of_linkErr == '') {
$_SESSION['data'] = array($_POST['link_title'],$_POST['web_link'],$_POST['type_of_link']);
//header("Location: add_link.inc.php");
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Add Links</title>
<link href="../styles/main.css" rel="stylesheet" type="text/css">
</head>
<div class="nav"><table width="100%" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="20%" bgcolor="#980002"><div align="center">ADMIN</div></td>
<td width="20%" bgcolor="#980002"><div align="center">FORUM</div></td>
<td width="20%" bgcolor="#980002"><div align="center">ADD PICTURES</div></td>
<td width="20%" bgcolor="#980002"><div align="center">ADD LINKS</div></td>
<td width="%" bgcolor="#980002"><div align="center">ADD EVENTS</div></td>
</tr>
<td height="4"></tr>
</table>
</div>
<div class="subheader">ADD LINKS</div>
<div class="header">logout</div>
<div class="content">
<div id="links_form">
<form action="add_link.inc.php" method="post" id="links_form">
<fieldset>
<legend>Add Link</legend>
<table width="100%">
<tbody>
<tr>
<td width="33%"><div>
<div align="right">Link Title:</div>
</div></td>
<td width="33%"><div id="form_box">
<input name="link_title" type="text" id="link_title" value="<?php echo $link_title;?>" size="40">
</div></td>
<td width="33%"><div align="left"><span class="error" style="color: red"><?php echo $link_titleErr;?></span></div></td>
</tr>
<tr>
<td width="33%"><div align="right">Website Link:</div></td>
<td width="33%"><div id="form_box">
<input name="web_link" type="text" id="web_link" value="<?php echo $web_link;?>" size="40">
</div></td>
<td width="33%"><div align="left"><span class="error" style="color: red" ><?php echo $web_linkErr;?></span></div></td>
</tr>
<tr>
<td width="33%"><div align="right">Type of Business or Service:</div></td>
<td width="33%"><div id="form_box">
<select name="select" id="select">
<option value="">SELECT TYPE OF LINK</option>
<option value="Pub/Restaurant">Pub/Restaurant</option>
<option value="Shop/Store">Shop/Store</option>
<option value="Motorcycle/Car">Motorcycle/Car</option>
<option value="Other">Other</option>
</select>
</div></td>
<td width="33%"><div align="left"><span class="error" style="color: red"><?php echo $type_of_linkErr;?></span></div></td>
</tr>
<tr>
<td> </td>
<td><div align="center">
<input type="submit" name="submit" id="submit" value="Add Link" formaction="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" formmethod="post">
</div></td>
<td> </td>
</tr>
</tbody>
</table>
</fieldset>
</form>
</div>
<p> </p>
<div id="delete_link"><form><fieldset><legend>Delete Link</legend>
<?php while($row = mysqli_fetch_array($result)): ?>
<label>
<input type="checkbox" value="<?php echo $row['linkid']; ?>" name="delete[]" />
<?php echo $row['linkid']; ?> - <?php echo $row['link_title']; ?> - <?php echo $row['type_of_link']?> - <?php echo $row['web_link']?> <?php echo '<br/>'?>
</label>
<?php endwhile; ?>
<br>
<input name="submit" type="submit" value="Delete Link" formmethod="post" formaction="delete_link.inc.php"/>
</p>
<p> </p>
</form>
</form></div>
</div>
<div class="footer" >All contents on this site are Copyright of the TVC.</div>
</body>
</html>
Change this line:
if(!isset($_SESSION['login']) == '1') {
to
if(isset($_SESSION['login']) && $_SESSION['login'] == '1') {

Editing a row in mysql database

I have a database which I am using to collect test data.
It shows each record on a new line with an edit and delete link at the end and also an add new record link.
Everything is working apart from the edit section. I can't see where I'm going wrong?
When I click the edit link, it shows me the layout of the table with the fields etc, but it is only passing across the row ID, and showing it in the date field. If i type into the fields and submit, it will change. It just won't pass over the data.
Here is my edit page, and the edit script.
<?php
function valid($date,$error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edit Records</title>
</head>
<body>
<?php
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $date; ?>"/>
<table border="1">
<tr>
<td colspan="2"><b><font color='Red'>Edit Records </font></b></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Date</font></b></td>
<td><label>
<input type="text" name="date" value="<?php echo $date; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Ammonia</em></font></b></td>
<td><label>
<input type="text" name="amm" value="<?php echo $amm; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Nitrate</font></b></td>
<td><label>
<input type="text" name="nat" value="<?php echo $nat; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Nitrite</font></b></td>
<td><label>
<input type="text" name="nit" value="<?php echo $nit; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>pH</font></b></td>
<td><label>
<input type="text" name="ph" value="<?php echo $ph; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Alkalinity</font></b></td>
<td><label>
<input type="text" name="alk" value="<?php echo $alk; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>SG</font></b></td>
<td><label>
<input type="text" name="sg" value="<?php echo $sg; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Temperature</font></b></td>
<td><label>
<input type="text" name="temp" value="<?php echo $temp; ?>" />
</label></td>
</tr>
<tr align="Right">
<td colspan="2"><label>
<input type="submit" name="submit" value="Edit Records">
</label></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
include('config.php');
if (isset($_POST['submit']))
{
if (is_numeric($_POST['id']))
{
$id = $_POST['id'];
$date = mysql_real_escape_string(htmlspecialchars($_POST['date']));
$amm = mysql_real_escape_string(htmlspecialchars($_POST['amm']));
$nat = mysql_real_escape_string(htmlspecialchars($_POST['nat']));
$nit = mysql_real_escape_string(htmlspecialchars($_POST['nit']));
$ph = mysql_real_escape_string(htmlspecialchars($_POST['ph']));
$alk = mysql_real_escape_string(htmlspecialchars($_POST['alk']));
$sg = mysql_real_escape_string(htmlspecialchars($_POST['sg']));
$temp = mysql_real_escape_string(htmlspecialchars($_POST['temp']));
if ($date == '')
{
$error = 'ERROR: Please fill in all required fields!';
valid($date, $error);
}
else
{
mysql_query("UPDATE employee SET date='$date', amm='$amm', nat='$nat', nit='$nit', ph='$ph', alk='$alk', sg='$sg', temp='$temp'")
or die(mysql_error());
header("Location: view.php");
}
}
else
{
echo 'Error!';
}
}
else
{
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM employee WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$date = $row['date'];
$amm = $row['amm'];
$nat = $row['nat'];
$nit = $row['nit'];
$ph = $row['ph'];
$alk = $row['alk'];
$sg = $row['sg'];
$temp = $row['temp'];
valid($id,'');
}
else
{
echo "No results!";
}
}
else
{
echo 'Error!';
}
}
?>
The function valid is responsible for rendering your form. But you only pass the $date into this function, so this is the only thing it can fill in. You have to pass the other values, too!
check this:
UPDATE employee SET date='$date', amm='$amm', nat='$nat', nit='$nit', ph='$ph', alk='$alk', sg='$sg', temp='$temp' WHERE id='$id'

I am not able to post data with php using mySQL query, can some assist?

At the moment I am having an issue which is not allowing me to insert content from a form on my website to my database. The form has worked before but since adding the tinyMCE editor it throws up the following error when I hit the submit button:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'category='sdcnd j sdjcj', type='sdck sjdc ' ,text='cdscjdnjc ' at line 1 (the jibberish input is just for testing purposes)
It seems here that its having trouble inserting into several fields but I can't find anything, would someone be able to point out what is causing this and a probable solution?
See below the insertRecord.php file:
<?php
session_start();
if (! isset($_SESSION['user'])) {
header("Location: admin_login.php");
}
function valid($id, $url, $heading, $friendlyUrl, $category, $type, $text, $age, $imageName, $location, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Insert Records</title>
<script type="text/javascript" src="/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas"
});
</script>
</head>
<body>
<?php
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<table border="1">
<tr>
<td colspan="2"><b><font color='Red'>Insert Records </font></b></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>URL<em>*</em></font></b></td>
<td><label>
<input type="text" name="url" value="<?php echo $url; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Heading<em>*</em></font></b></td>
<td><label>
<input type="text" name="heading" value="<?php echo $heading; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Friendly URL<em>*</em></font></b></td>
<td><label>
<input type="text" name="friendlyUrl" value="<?php echo $friendlyUrl; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Category<em>*</em></font></b></td>
<td><label>
<input type="text" name="category" value="<?php echo $category; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Type<em>*</em></font></b></td>
<td><label>
<input type="text" name="type" value="<?php echo $type; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Text<em>*</em></font></b></td>
<td><label>
<textarea name="text" value="<?php echo $text; ?>" ></textarea>
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Age<em>*</em></font></b></td>
<td><label>
<input type="text" name="age" value="<?php echo $age; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Image Name<em>*</em></font></b></td>
<td><label>
<input type="text" name="imageName" value="<?php echo $imageName; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Location<em>*</em></font></b></td>
<td><label>
<input type="text" name="location" value="<?php echo $location; ?>" />
</label></td>
</tr>
<tr align="Right">
<td colspan="2"><label>
<input type="submit" name="submit" value="Insert Records">
</label></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
include('config.php');
if (isset($_POST['submit']))
{
$id = $_POST['id'];
$url = mysql_real_escape_string(htmlspecialchars($_POST['url']));
$heading = mysql_real_escape_string(htmlspecialchars($_POST['heading']));
$friendlyUrl = mysql_real_escape_string(htmlspecialchars($_POST['friendlyUrl']));
$category = mysql_real_escape_string(htmlspecialchars($_POST['category']));
$type = mysql_real_escape_string(htmlspecialchars($_POST['type']));
$text = mysql_real_escape_string(htmlspecialchars($_POST['text']));
$age = mysql_real_escape_string(htmlspecialchars($_POST['age']));
$imageName = mysql_real_escape_string(htmlspecialchars($_POST['imageName']));
$location = mysql_real_escape_string(htmlspecialchars($_POST['location']));
if ($url == '' || $heading == '' || $friendlyUrl == '' || $category == '' || $type == '' || $text == '' || $age == '' || $imageName == '' || $location == '')
{
$error = 'Please enter the details!';
valid($id, $url, $heading, $friendlyUrl, $category, $type, $text, $age, $imageName, $location, $error);
}
else
{
mysql_query("INSERT podContent SET url='$url', heading='$heading' ,friendlyUrl='$friendlyUrl' category='$category', type='$type' ,text='$text' age='$age', imageName='$imageName' ,location='$location'")
or die(mysql_error());
header("Location: view.php");
}
}
else
{
valid('','','','');
}
?>
Any contribution is appreciated.
Thanks
Missing a comma:
friendlyUrl='$friendlyUrl', category='$category' and
text='$text', age='$age'
Your insert statement is incorrect. It should look like:
insert into <tablename>
(field1, field2, field3)
values
(1, 'string ', 'string')
Your insert is done like an update statement
update <tablename>
set
field2 = 'string',
field3 = 'string'
where field1 = 1

Date picker & combo box values are not going to mysql

I am making a registration form in PHP and when submitting the form Date(Check In, for which I have used Date Picker), Combo boxes(Sex & Room No) & check box(taxi) is not getting inserted.
I have looked enough in to the code but not getting what is wrong..though other combo box and check box working just fine.
PHP Code -
<?php
$passport = $_POST['passport'];
$name = $_POST['name'];
$sex = $_POST['sex'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$country = $_POST['country'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$roomNo = $_POST['roomNo'];
if(isset($_POST['food']) && $_POST['food'] == 'food')
{
$food = 'yes';
}
else
{
$food = 'no';
}
if(isset($_POST['car']) && $_POST['car'] == 'car')
{
$car = 'yes';
}
else
{
$car = 'no';
}
if(isset($_POST['others']) && $_POST['others'] == 'others')
{
$others = 'yes';
}
else
{
$others = 'no';
}
$checkIn = $_POST['checkIn'];
mysql_connect("localhost","root","");
mysql_select_db("guesthouse");
$personal_query = "INSERT INTO personal_details VALUES(
'',
'$name',
'$sex',
'$address1',
'$address2',
'$city',
'$country',
'$contact',
'$email')";
mysql_query($personal_query);
$result = mysql_affected_rows();
if($result == 1)
{
echo "Personal Details Submitted";
}
$booking_query = "INSERT INTO booking VALUES(
'',
'$name',
'$roomno',
'$food',
'$taxi',
'$others',
'$checkIn')";
mysql_query($booking_query);
$result = mysql_affected_rows();
if($result == 1) {
echo "<br/>Booking Details Submitted";
}
?>
HTML -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
new JsDatePick({
useMode:2,
target:"checkIn",
dateFormat:"%d-%M-%Y"
/*selectedDate:{
day:5,
month:9,
year:2006
},
yearsRange:[1978,2020],
limitToToday:false,
cellColorScheme:"beige",
dateFormat:"%m-%d-%Y",
imgPath:"img/",
weekStartDay:1*/
});
};
</script>
</head>
<form name="form1" method="post" action="registration_handle.php">
<table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center" bgcolor="#0099FF">Room Reservation Details :</td>
</tr>
<tr>
<td width="33%" align="center" bgcolor="#66FFCC">Passport No </td>
<td width="67%"><label for="textfield"></label>
<input type="text" name="passport" id="passport"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Name</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Sex</td>
<td><label for="select3"></label>
<select name="sex" id="sex">
<option value="" selected>Male</option>
<option value="" >Female</option>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Address 1</td>
<td><input type="text" name="address1" id="address1"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Address2</td>
<td><input type="text" name="address2" id="address2"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">City</td>
<td><input type="text" name="city" id="city" /></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Country</td>
<td><label for="select2"></label>
<select name="country" id="country">
<?php
mysql_connect("localhost","root","");
mysql_select_db("guesthouse");
$query = "SELECT name FROM country";
$query_result = mysql_query($query);
while($result = mysql_fetch_assoc($query_result))
{
?>
<option value = "<?php echo $result['name'] ?>"><?php echo $result['name'] ?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Contact No</td>
<td><input type="text" name="contact" id="contact"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">E-Mail </td>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Room No</td>
<td><label for="select4"></label>
<select name="roomNo" id="roomNo">
<?php
mysql_connect("localhost","root","");
mysql_select_db("guesthouse");
$query = "SELECT name FROM roomno";
$query_result = mysql_query($query);
while($result = mysql_fetch_assoc($query_result))
{
?>
<option value = "<?php echo $result['name'] ?>"><?php echo $result['name'] ?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Extra Service</td>
<td><p>
<label> </label>
<input type="checkbox" name="food" value="food" />Food
<input type="checkbox" name="car" value="car" />Car
<input type="checkbox" name="others" value="others" />Others<br>
</p></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Check In </td>
<td><label for="textfield3"></label>
<input type="text" size="16" name="checkIn" id="checkIn"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit">
<input type="reset" name="Reset" id="Reset" value="Reset" />
<input type="submit" name="cancel" id="cancel" value="Cancel" /></td>
</tr>
</table>
</form>
</html>
value of sex is "" (if you want default, don't type value="")
-Tested-
<html>
<body>
<select onchange="alert(this.value);">
<option>Volvo</option>
<option>Saab</option>
<option value=''>Mercedes</option>
<option>Audi</option>
</select>
</body>
</html>
you never give any value to $taxi (wich is called car in your form)
You initialte $roomNo and store $roomno
--- found these errors because I tend to do same things. here's a tip, always verify your variables name first, 99% of your probs will be fixed --- (works for me :) )

Categories