PHP Classes

PHP insert query

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  PHP insert query  
Subject:PHP insert query
Summary:The content are not inserting in database
Messages:2
Author:tatar roman
Date:2012-09-08 00:04:16
Update:2012-12-05 06:51:11
 

  1. PHP insert query   Reply   Report abuse  
Picture of tatar roman tatar roman - 2012-09-08 01:03:16
Hi. I am trying to modified some of PHP code. I have php script that insert in data base some dates. Now I want to add mo 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:
$query = "INSERT INTO posts (page_id, title, active, position, content) VALUES ('{$page_id}', '{$title}', '{$active}', '{$position}', '{$content}')";

and the modified query:

$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}')";

Wher is the problem?
All the cod is :

<?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 "&nbsp;<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 "&nbsp;<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 "&nbsp;<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 "&nbsp;<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 "&nbsp;<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 "&nbsp;<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 "&nbsp;<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 "&nbsp;<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 "&nbsp;<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 "&nbsp;<span class=\"mend\">*</span>";
} ?>
</td>
</tr>



<tr>
<td>&nbsp;</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") ?>

There is 1 reply in this thread, which is not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.