PDA

View Full Version : data base php error


DrewM
02-26-2006, 07:50 PM
Well I'm trying to make a page that would allow my users to send links. I have a vb page with the form but the proplem is when you hit summit it saves the data but doesn't include in the data the name, url, and description (felds in the form). The code for the php is:
<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT', 'Sim2world');

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

$specialtemplates = array();

$globaltemplates = array(
'site_link_add',
);

$actiontemplates = array();

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

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude = str_replace('clientscript', $vbulletin->options['bburl'] . '/clientscript', $headinclude);

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################
if ($_REQUEST['do'] == 'save')
{
$vbulletin->db->query_write("INSERT INTO `Links` (`id`, `Name`, `url`, `description`) VALUES ('10', '$name', '$url', '$description');");
}
$navbits = array();
$navbits[$parent] = 'Sim2world';

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


eval('print_output("' . fetch_template('site_link_add') . '");');

?>
the Templates content is:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../main.css" rel="stylesheet" type="text/css">
</head>

<body>
$head_2 $headinclude
<div align="left"><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><a href="index.php">Home</a>&gt;<a href="/Cool%20stuff.php"><strong>Cool
stuff</strong></a></td>
</tr>
</table>
</div>
<div align="center">
<table width="933" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" valign="top"> $toolbar</td>
<td width="75%" valign="top" background="../../Images/content_bg.gif"><div align="center"><img src="../../Images/header.jpg" width="747" height="102"><br>
<font size="+5"><span class="NewsTitle"><strong><u><font size="+3">Add
a link!<br>
</font></u></strong></span></font>
<table width="598" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="598" height="80" valign="top" class="NewsTitle">
<form name="form1" method="post" action="test.php?do=save">
<table width="598" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="598" class="NewsTitle">Name:
<input type="text" name="name"></td>
</tr>
<tr>
<td width="598" class="NewsTitle">Url:
<input name="url" type="text" id="url"></td>
</tr>
<tr>
<td valign="top" class="NewsTitle">Description:<br>
<textarea name="description" id="description"></textarea>
</td>
</tr>
<tr>
<td class="NewsTitle"><input type="submit" name="Submit" value="Add Link!">
<input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form></td>
</tr>
</table>
<font size="+5"><span class="NewsTitle"><strong><u><font size="+3">
</font></u></strong></span></font> <br>
<br>
</div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top"><img src="../../Images/content_bottom.jpg" width="748" height="21"></td>
</tr>
</table>
<br>
$footer<br>
</div>
</body>
</html>

Marco van Herwaarden
02-27-2006, 08:19 AM
<form name="form1" method="post" action="test.php?do=save">

Should be:
<form name="form1" method="post" action="test.php">
<input type="hidden" name="do" value="save" />


Change:
if ($_REQUEST['do'] == 'save')
{
$vbulletin->db->query_write("INSERT INTO `Links` (`id`, `Name`, `url`, `description`) VALUES ('10', '$name', '$url', '$description');");
}

To:
if ($_REQUEST['do'] == 'save')
{
$vbulletin->input->clean_array_gpc('p', array(
'name' => TYPE_STR,
'url' => TYPE_STR,
'description' => TYPE_STR
));

$vbulletin->db->query_write("INSERT INTO `Links` (`id`, `Name`, `url`, `description`)
VALUES ('10'
, '" . $vbulletin->db->escape_string($vbulletin->GPC['name']) . "'
, '" . $vbulletin->db->escape_string($vbulletin->GPC['url']) . "'
, '" . $vbulletin->db->escape_string($vbulletin->GPC['description']) . "'
);");
}

DrewM
02-27-2006, 09:14 AM
thanks, I'm testing it now!

EDIT: It works thanks again

DrewM
03-11-2006, 06:20 PM
this was working fie but I have the idea auto go up so how do I get rid of the id.