Link to my site: http://www.df-barracks.com
SMF version: SMF 2.0 RC5
TP version: TP ver. 1.104
Default Forum Language: english
Theme name and version: blue moon
Browser Name and Version: Firefox 6.x
Mods installed: A few here
Related Error messages:
I'm getting error messages when I try the one that I could find. What I'm looking for is just a small sample of a PHP script that I can add to an article. Just to see if it works. I never done this before and the sample I did fine, Doesn't work, I was getting errors from the tbsub.php and one other one that I don't remember. Just some thing to try to see if I can get this to work,
echo'
<h2>Hello World</h2>
';
Doesn't get much simpler than that ;) . Note, there are no php tags, don't put the php tags in a block, as the block is already in php.
Thanks Willy, It's just I have a larger PHP code that I been trying to get to work, and it just fails like crazy.
Here are some of the errors.
Parse error: syntax error, unexpected T_ELSE in /home/dfbarrac/public_html/Sources/TPSubs.php(3487) : eval()'d code on line 85
Fatal error: Function name must be a string in /home/dfbarrac/public_html/Sources/TPortal.php on line 3041
From what I been able to find out is that the PHP script call db_query() and that where some of the errors are. Have any idea what's wrong and how to fix it.
I am not a coder, but why don't you post the code (in a code block please) and maybe someone will take a look at it. Did posting my test code work?
Yes it did. I do PHP coding my self and the code seems ok, It's run when I run it. Any way the code is below and in a code block
global $user_info, $db_prefix, $scripturl, $ID_MEMBER;
$page_title = "<center><h1>Page Title</h1></center>"; // The title of your form. Use any html code you want to here.
$intro_table = "This is where you give information about the table in general -- explaining to the viewers what they're seeing."; // Can include html
$intro_form = "This is where you give any instructions for filling out the form."; // Can include html
// Define your fields. All of these values need to be defined, even if they are empty.
// The fields will be displayed in the order in which they are listed in the array.
// $fielddef = array(
// array( 'type' => "", // text, radio, select, checkbox, textarea
// 'caption' => "", // caption to be displayed on the form. Can include symbols and spaces.
// 'name' => "", // a unique name for the field. No symbols or spaces
// 'options' => "", // for radio and select fields. List in order you wish them to appear, separated by commas; for checkboxes, it's the value to be saved and displayed next to the box
// 'defaultvalue' => "", // the default value for the field. Can be a variable or text. Be sure to enclose text in quotation marks
// 'label' => "", // Label for the table column on the results display
// 'required' => 0 // 0 or 1 -- use 1 if the field must be filled out. use 0 if it's optional; never set a checkbox to be required
// ),
// );
$fielddef = array(
array( 'type' => "text",
'caption' => "Name",
'name' => "name",
'options' => "",
'defaultvalue' => "",
'label' => "Name",
'required' => 1
),
array( 'type' => "radio",
'caption' => "Gender",
'name' => "gender",
'options' => "Male,Female",
'defaultvalue' => "",
'label' => "Gender",
'required' => 0
),
array( 'type' => "checkbox",
'caption' => "Do you want to be on the mailing list?",
'name' => "list",
'options' => "Yes",
'defaultvalue' => "",
'label' => "Mailing List",
'required' => 0
),
array( 'type' => "select",
'caption' => "Where did you hear about us",
'name' => "hear",
'options' => "-----,Google,Other search engine,Yahoo,Other website,Pony Express,smoke signals",
'defaultvalue' => "Google",
'label' => "Referrer",
'required' => 0
),
array( 'type' => "textarea",
'caption' => "What do you want to be if you grow up?",
'name' => "grow",
'options' => "",
'defaultvalue' => "",
'label' => "Future",
'required' => 0
),
);
///////////////////////////////////////////////////////////////////////////////////////////////////////
db_query("CREATE TABLE IF NOT EXISTS `{$db_prefix}db_data`(
`dbid` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ID_MEMBER` INT( 11 ) NOT NULL DEFAULT '0',
`field` TINYTEXT NOT NULL ,
`value` TEXT NOT NULL)", __FILE__, __LINE__);
///////////////////////////////////////////////////
$show_form = 'false';
$errors=array();
$fieldvalue = array();
if (isset($_POST['submitted']) && $ID_MEMBER > 0) {
if (isset($_POST['deleteentry']) && ($_POST['deleteentry'] == 1))
db_query("DELETE FROM `{$db_prefix}db_data`
WHERE ID_MEMBER = $ID_MEMBER", __FILE__, __LINE__);
else {
// Check that all required fields have values
foreach ($fielddef as $field)
if (empty($_POST[$field['name']]) && ($field['required'] == 1)){ $errors[] = $field['name']; }
// There's at least one field missing
if (isset($errors[0])) {
$show_form = 'true';
foreach ($_POST as $key => $value)
$fieldvalue[$key] = $value;
}
// All is well
else {
// Is there already a record for this person?
$query = db_query(
"SELECT *
FROM {$db_prefix}db_data
WHERE ID_MEMBER LIKE $ID_MEMBER", __FILE__, __LINE__);
// There's a record for this person so we'll modify the record
if(db_affected_rows() != 0) {
db_query("DELETE FROM `{$db_prefix}db_data`
WHERE ID_MEMBER = $ID_MEMBER", __FILE__, __LINE__);
}
foreach ($fielddef as $field) {
if (isset($_POST[$field['name']]))
$value = addslashes(trim($_POST[$field['name']]));
else
$value = "";
$fieldname = $field['name'];
db_query("INSERT INTO `{$db_prefix}db_data`
( `dbid` , `ID_MEMBER` , `field` , `value` )
VALUES ('', '$ID_MEMBER', '$fieldname', '$value')", __FILE__, __LINE__);
}
}
}
}
elseif (isset($_GET['cleardb']) && ($_GET['cleardb']==1) && ($user_info['is_admin'])) {
echo '<center>';
echo 'Are you sure you want to clear the database?<br>';
echo '<a href="' . $scripturl . '?page=' . $_GET['page'] . '&cleardb=2">Yes, I want to clear it.</a> -- <a href="' . $scripturl . '?page=' . $_GET['page'] . '">No, I changed my mind</a>';
echo '</center>';
}
elseif (isset($_GET['cleardb']) && ($_GET['cleardb']==2) && ($user_info['is_admin'])) {
db_query("TRUNCATE TABLE `{$db_prefix}db_data`", __FILE__, __LINE__);
echo '<center>';
echo 'Database cleared';
echo '</center>';
}
else {
if (isset($_GET['form']) && ($_GET['form']==1) && ($ID_MEMBER > 0)) {
// They've asked for the form
$show_form = 'true';
$query = db_query(
"SELECT *
FROM {$db_prefix}db_data
WHERE ID_MEMBER LIKE $ID_MEMBER", __FILE__, __LINE__);
// There's already a record for this person, so fill in the form with previous details
if(db_affected_rows() != 0)
{
while ($row = mysql_fetch_assoc($query))
$fieldvalue[$row['field']] = $row['value'];
$previousrecord = 1;
}
// No record, so we're adding a new one with the default values
else {
foreach ($fielddef as $field)
$fieldvalue[$field['name']] = $field['defaultvalue'];
$previousrecord = 0;
}
}
}
echo $page_title . "<br>";
// Looks like you want the form, but only if you're a registered member
if ($show_form == 'true' && $ID_MEMBER > 0) {
echo $intro_form . "<br>";
if (isset($errors[0])) { echo '<div style:"color: red;">Please fill in all fields with a *.</div>'; }
echo '<form action="' . $scripturl . '?page=' . $_GET['page'] . '" method="post">
<INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
<center><table>';
$bg = 'windowbg2';
foreach ($fielddef as $field) {
if ($field['type'] == 'text') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
if ($field['required'] == 1) { echo '* '; }
echo $field['caption'] . ':</TD>
<TD align="left"><INPUT id="' . $field['name'] . '" name="' . $field['name'] . '" type="text" value ="' . $fieldvalue[$field['name']] . '" /></TD>
</TR>';
}
elseif ($field['type'] == 'radio') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
if ($field['required'] == 1) { echo '* '; }
echo $field['caption'] . ':</TD>
<TD align="left">';
$options = explode(',',$field['options']);
foreach ($options as $option) {
echo '<INPUT TYPE="RADIO" NAME="' . $field['name'] . '" VALUE="'. $option . '"';
if ((isset($fieldvalue[$field['name']])) && ($option == $fieldvalue[$field['name']])) { echo ' CHECKED'; }
echo '>' . $option . ' ';
}
echo '</TD>
</TR>';
}
elseif ($field['type'] == 'checkbox') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
echo $field['caption'] . ':</TD>
<TD align="left">';
echo '<INPUT TYPE="CHECKBOX" NAME="' . $field['name'] . '" VALUE="'. $field['options'] . '"';
if (isset($fieldvalue[$field['name']]) && ($fieldvalue[$field['name']]==$field['options'])) { echo ' CHECKED'; }
echo '>' . $field['options'] . '
</TR>';
}
elseif ($field['type'] == 'select') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
if ($field['required'] == 1) { echo '* '; }
echo $field['caption'] . ':</TD>
<TD align="left"><SELECT id="' . $field['name'] . '" name="' . $field['name'] . '" style="WIDTH: 152px" value ="';
echo '" />';
$options = explode(',',$field['options']);
foreach ($options as $option) {
echo '<OPTION value="' . $option . '"';
if ((isset($fieldvalue[$field['name']])) && ($option == $fieldvalue[$field['name']])) { echo ' selected'; }
echo '>' . $option . '</OPTION>';
}
echo '</SELECT></TD>
</TR>';
}
elseif ($field['type'] == 'textarea') {
echo '<TR class ="' . $bg . '">
<TD width = "200px" align="right">';
if ($field['required'] == 1) { echo '* '; }
echo $field['caption'] . ':</TD>
<TD align="left"><TEXTAREA id="' . $field['name'] . '" name="' . $field['name'] . '" rows="4" cols="40">';
echo $fieldvalue[$field['name']];
echo '</' . 'TEXTAREA></TD>
</TR>';
}
if ($bg == 'windowbg2') { $bg = 'windowbg'; }
else { $bg = 'windowbg2'; }
}
if ($previousrecord == 1) {
echo '<tr class ="' . $bg . '"><td colspan="2"><INPUT TYPE="CHECKBOX" NAME="deleteentry" VALUE="1"> Delete this entry</td></tr>';
if ($bg == 'windowbg2') { $bg = 'windowbg'; }
else { $bg = 'windowbg2'; }
}
echo '
<TR class ="' . $bg . '">
<TD colspan="2" align="center">
<INPUT type="submit" value="Submit">
<INPUT type="reset" value="Reset"></TD>
</TR></TABLE></center></form>';
}
// If you don't want the form, you want the table -- when first coming to the page or after submitting a record
else {
echo $intro_table . "<br>";
$members = array();
$query = db_query(
"SELECT *
FROM {$db_prefix}db_data", __FILE__, __LINE__);
if(db_affected_rows() != 0)
{
while ($row = mysql_fetch_assoc($query)) {
if ($row['value'] == '') { $row['value'] = "&nb" . "sp;"; }
$displayvalue[$row['ID_MEMBER']][$row['field']] = $row['value'];
if (!in_array($row['ID_MEMBER'],$members))
$members[] = $row['ID_MEMBER'];
}
$memberlist = implode(" OR ID_MEMBER = ",$members);
$query = db_query(
"SELECT ID_MEMBER, realName
FROM {$db_prefix}members
WHERE ID_MEMBER = $memberlist
ORDER BY realName", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query))
$displaymember[$row['ID_MEMBER']] = $row['realName'];
echo '<center><table border="1"><tr><td>&nb' . 'sp;</td>';
foreach ($fielddef as $field)
echo '<td>'. $field['label'] . '</td>';
echo '</tr>';
foreach ($displaymember as $number => $name) {
echo '<tr><td><a href="' . $scripturl . '?action=profile;u=' . $number . '">' . $name . '</a></td>';
foreach ($fielddef as $field)
echo '<td>'. $displayvalue[$number][$field['name']] . '</td>';
echo '</tr>';
}
echo '</table></center>';
}
else { echo "No records in the database yet."; }
echo '<br><br>';
if ($ID_MEMBER > 0)
echo '<a href="' . $scripturl . '?page=' . $_GET['page'] . '&form=1">Add or modify your information</a>';
if ($user_info['is_admin'])
echo '<br><a href="' . $scripturl . '?page=' . $_GET['page'] . '&cleardb=1">Empty the database</a>';
}
Oh and the errors I get seem to be in the db_query(). It's trying to access the mysql database
You are using SMF1 database code, it changed in SMF2.
Take a look at this :
$smcFunc & Database Functions SMF 2 (http://wiki.simplemachines.org/smf/$smcFunc#Database_Functions)
Thanks Freddy, I just fount that out about an hour ago. This is why I don't like taking crap that I fount on google and then tried to use it. I check the date on this and it is dated 2008, So it quite old.
Thanks
Joe
This is way to advance for me. I need some one to make me a small sample. Nothing that's too big or complex...
Some thing that will create a table if it doesn't exist.
just a forum that has 2 labels. A name and an email address
Then add them to the table that was created.
Or does any one know where I can find sample for TP: Ver 1.104
I'm assuming you got that to work in your other topic?
Yes I did, and Now I'm working on a way to send a html page when some one clicks a link or button. Thanks IchBin for all your help.
I'll remember this when I get paid next month
Ice