Problem with PHP insert query
Posted: Fri Sep 07, 2012 6:24 pm
Hi. I am trying to modified some of PHP code. I have php script that insert in data base some rows. Now I want to add more variables that I need to insert in my database. I created the new rows in my table of database but the script is inserting nothing.
This is original query:
and the modified query:
Wher is the problem?
All the cod is :
This is original query:
Code: Select all
$query = "INSERT INTO posts (page_id, title, active, position, content) VALUES ('{$page_id}', '{$title}', '{$active}', '{$position}', '{$content}')";Code: Select all
$query = "INSERT INTO posts (page_id, title, active, position, content, address, phone, web, email, video, map, valid) VALUES ('{$page_id}', '{$title}', '{$active}', '{$position}', '{$content}', '{$address}', '{$phone}', '{$web}', '{$email}', '{$video}', '{$map}', '{$valid}')";All the cod is :
Code: Select all
<?php
/**
*
* eliteCMS - The Lightweight CMS Copyright © 2008 elite-graphix.net.
* eliteCMS is a free software to use for personal websites.
* Anyone can use eliteCMS for free as long as he retain the
* copyright note at the footer.
* If anyone wants to remove the copyright note for commercial
* use of the software can contact raj@elite-graphix.net.
* eliteCMS comes with absolutely no warranty and is provided as-is.
* raj - THE AUTHOR of the software or elite-graphix - THE COMPANY
* will not be held responsible for any damage this software might cause.
* You run this software at your own risk and agree not to hold author or company.
* You are not allowed to make any profit from this software unless you
* have a written authorization from the author to use the software for commercial use.
*
*/
include ("includes/headerRefresh.php");
include ("includes/config.php");
include ("functions/functions.php");
require_once ("includes/session.php");
check_login();
get_settings();
include ("header.php");
$errors = array();
if (isset($_POST['submit'])) {
if ($_POST['title'] == "")
$errors['title'] = "Title of the Post is required !";
if ($_POST['content'] == "")
$errors['content'] = "Content of the Post is required !";
if (empty($errors)) {
$page_id = mysql_prep($_POST['page_id']);
$title = mysql_prep($_POST['title']);
$active = mysql_prep($_POST['active']);
$position = mysql_prep($_POST['position']);
$content = mysql_prep($_POST['content']);
$content = mysql_prep($_POST['address']);
$content = mysql_prep($_POST['phone']);
$content = mysql_prep($_POST['web']);
$content = mysql_prep($_POST['email']);
$content = mysql_prep($_POST['video']);
$content = mysql_prep($_POST['map']);
$content = mysql_prep($_POST['valid']);
$query = "INSERT INTO posts (page_id, title, active, position, content, address, phone, web, email, video, map, valid) VALUES ('{$page_id}', '{$title}', '{$active}', '{$position}', '{$content}', '{$address}', '{$phone}', '{$web}', '{$email}', '{$video}', '{$map}', '{$valid}')";
$result = mysql_query($query);
confirm_query($result);
if ($result) {
$successMSG = "Post Created Successfully !";
redirect_to("manage_posts.php?newpost=1");
} else {
$errorMSG = "Post Creation Failed ! </br>" . mysql_error() . " ";
}
} else {
$displayError = '<div class="errorMSG"><ul style="list-style:none;">';
foreach ($errors as $error) {
$displayError .= "<li>$error</li>";
}
$displayError .= '</ul></div>';
}
} else {
//$errorMSG = "";
}
?>
<?php
if (isset($_GET['new']) && $_GET['new'] == 1) {
$successMSG = "Page created successfully. Now lets add some posts to it !.";
}
?>
<div id="body">
<div class="box bigBox">
<h1>Add New Post</h1>
<?php display_msg(); ?>
<?php selected_page(); ?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<table width="100%" align="center" cellpadding="0" cellspacing="0" id="post_form">
<tr bgcolor="#EEF7FD">
<td width="27%" class="padd">Categoria Companie :</td>
<td width="73%" class="padd">
<select name="page_id" class="select1" onChange="MM_jumpMenu('parent',this,0)">
<?php
if (isset($selected_page['id'])) {
echo "<option value=\"{$selected_page['id']}\">{$selected_page['menu_name']}</option>\n";
} else {
$query = "SELECT * FROM pages ORDER BY id";
$result = mysql_query($query);
confirm_query($result);
while ($pages = mysql_fetch_array($result)) {
echo "<option value=\"add_post.php?page={$pages['id']}\">{$pages['menu_name']}</option>\n";
}
}
?>
</select>
</td>
</tr>
<tr>
<td class="padd">Denumire Companie :</td>
<td class="padd">
<input name="title" type="text" class="input" id="title" value="<?php echo $_POST['title'] ?>"/>
<?php if (!empty($errors['title'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr bgcolor="#EEF7FD">
<td class="padd">Post Published :</td>
<td class="padd">
<select name="active" class="select">
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</td>
</tr>
<tr>
<td valign="bottom" class="padd">Post Position :</td>
<td valign="bottom" class="padd">
<?php if (isset($_GET['page'])) {
display_acquired_posts();
} ?>
<input name="position" type="text" class="inputSmall" id="position" value="<?php echo
$_POST['position'] ?>"/>
<?php if (!empty($errors['position'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr bgcolor="#EEF7FD">
<td class="padd">Descriere Companie</td>
<td class="padd">
<script language="JavaScript1.2" type="text/javascript">
WYSIWYG.attach('content', full);
</script>
<textarea name="content" id="content" class="contentArea"><?php echo $_POST['content'] ?></textarea>
<?php if (!empty($errors['content'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr>
<td class="padd">Adresa Companie :</td>
<td class="padd">
<input name="address" type="text" class="input" id="address" value="<?php echo $_POST['address'] ?>"/>
<?php if (!empty($errors['address'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr>
<td class="padd">Nr. Telefon Companie :</td>
<td class="padd">
<input name="phone" type="text" class="input" id="phone" value="<?php echo $_POST['phone'] ?>"/>
<?php if (!empty($errors['phone'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr>
<td class="padd">Adresa Web :</td>
<td class="padd">
<input name="web" type="text" class="input" id="web" value="<?php echo $_POST['web'] ?>"/>
<?php if (!empty($errors['web'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr>
<td class="padd">Email Companie :</td>
<td class="padd">
<input name="email" type="text" class="input" id="email" value="<?php echo $_POST['email'] ?>"/>
<?php if (!empty($errors['email'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr>
<td class="padd">Video Link :</td>
<td class="padd">
<input name="video" type="text" class="input" id="video" value="<?php echo $_POST['video'] ?>"/>
<?php if (!empty($errors['video'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr>
<td class="padd">Harta Companie :</td>
<td class="padd">
<input name="map" type="text" class="input" id="map" value="<?php echo $_POST['map'] ?>"/>
<?php if (!empty($errors['map'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr>
<td class="padd">Activ pina la: </td>
<td class="padd">
<input name="valid" type="text" class="input" id="valid" value="<?php echo $_POST['valid'] ?>"/>
<?php if (!empty($errors['valid'])) {
echo " <span class=\"mend\">*</span>";
} ?>
</td>
</tr>
<tr>
<td> </td>
<td class="padd">
<input type="submit" name="submit" id="submit" value="Add Post" class="formBU"/>
<input name="reset" type="reset" class="formBU" value="Reset Form" />
<a href="manage_posts.php" target="_self" class="linkBU">Cancel</a></td>
</tr>
</table>
</form>
</div>
</div>
<?php include ("footer.php") ?>