PDA

View Full Version : could some one help me with this code


DrewM
03-21-2006, 10:12 PM
Well I'm making a page where you can add, edit pages the add is fine but the edit is not saving to the data base right my php code is:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'Adminpages');

// ################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array();

$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
'site_admin_add',
'site_admin_edit',
);

$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
chdir('/home/rdsx667/public_html/forum/');
require_once('./global.php');

// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################

$navbits = array();
$navbits[$parent] = admin;

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');

// ################ SHOW NO PERMISSION PAGE TO GUESTS ####################

if (!is_member_of($vbulletin->userinfo, 11) AND !is_member_of($vbulletin->userinfo, 6))
{
print_no_permission();
}

// ########################### ADD THE SITE ##############################

if ($_REQUEST['do'] == "add")
{
eval('print_output("' . fetch_template('site_admin_add') . '");');
}

if ($_REQUEST['do'] == "edit")
{
$var = "SELECT * FROM " . TABLE_PREFIX . "page WHERE page_id='".intval($_REQUEST['id'])."'";
$sqlr = $db->query_read($var);
$sr = $db->fetch_array($sqlr);
eval('print_output("' . fetch_template('site_admin_edit') . '");');
}

if ($_REQUEST['save'] == "add")
{
//------------------------------------------------------------
// Add the site to the database if everything is ok.
//------------------------------------------------------------
// Sanitize User Submitted Data
$vbulletin->input->clean_array_gpc('p', array(
'name' => TYPE_STR,
'description' => TYPE_STR
));
$sql = "INSERT INTO " . TABLE_PREFIX . "page
(page_name, page_edit_by, page_status, page_contents) VALUES ('".$db->escape_string($vbulletin->GPC['name'])."','".$db->escape_string($vbulletin->userinfo['username'])."','1','".$db->escape_string($vbulletin->GPC['description'])."')";
$db->query_write($sql);
}

if ($_REQUEST['save'] == "edit")
{
//------------------------------------------------------------
// Update the site if everything is ok.
//------------------------------------------------------------
$vbulletin->input->clean_array_gpc('p', array(
'id' => TYPE_UINT,
'name' => TYPE_STR,
'description' => TYPE_STR
));

$sql = "UPDATE " . TABLE_PREFIX . "page set
page_name='".$db->escape_string($vbulletin->GPC['name'])."',
page_contents='".$db->escape_string($vbulletin->GPC['description'])."',
WHERE page_id='".intval($_REQUEST['id'])."'";
$db->query_write($sql);

// Send the output.
$id = $vbulletin->GPC['id'];
}

?>
My error is:
Database error in vBulletin 3.5.4:

Invalid SQL:
UPDATE page set
name='Eps',
description='OFB Info Movies Pictues',
WHERE page_id='2';

MySQL Error : 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 'WHERE page_id='2'' at line 4
Error Number : 1064
HELP is very much appricated!

DrewM
03-22-2006, 10:13 PM
bump

Paul M
03-22-2006, 11:49 PM
Try this;

$sql = "UPDATE " . TABLE_PREFIX . "page set
page_name='".$db->escape_string($vbulletin->GPC['name'])."',
page_contents='".$db->escape_string($vbulletin->GPC['description'])."',
WHERE page_id=".intval($_REQUEST['id']);

DrewM
03-23-2006, 08:49 AM
thankls will try

Still getting error it's
Database error in vBulletin 3.5.4:

Invalid SQL:
UPDATE page set
page_name='Eps',
page_contents='OFB Info Movies Pictues',
WHERE page_id=2;

MySQL Error : 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 'WHERE page_id=2' at line 4
Error Number : 1064

got it it's:
WHERE `page_id`='".$vbulletin->GPC['id']."'";