Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-14-2006, 01:42 AM
chilllax chilllax is offline
 
Join Date: Nov 2005
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Submit info to database error

PHP Code:
<?php
  $gamertag
=$_POST['gamertag'];
  
$eaddress=$_POST['eaddress'];
  
  if (!
$gamertag || !$eaddress)
  {
      echo 
'You have not entered all of the required information.<br />'
           
.'Please go back and try again.';
      exit;
  }
  if (!
get_magic_quotes_gpc())
  {
      
$gamertag addslashes($gamertag);
      
$eaddress addslashes($eaddress);
  }
  
  @ 
$db = new mysqli('localhost''chilllax_chill''red123''chilllax_participants');
  
if (
mysqli_connect_error())
{
    echo 
'Error: Could not connect to database. Please try again later.';
    exit;
}

$query "insert into participants values
          ('
$gamertag', '$eaddress'}";
$result $db->query($query);
if (
$result)
    echo 
$db->affected_rows.' participant added.
    
$db->close();
?>
Theres the code in my script. I have the database set up and also the correct number of tables. My problem is whenever I try and run this script this error comes up parse error, unexpected $. Why is this. Also I am going by a php book thats infront of me and I dont really understand the bit of code that actually inserts the data into the database. How does it know which table to place the variables into? I hope this made sense. Thanks for any help.
Reply With Quote
  #2  
Old 04-14-2006, 06:55 AM
Guest190829
Guest
 
Posts: n/a
Default

The below should work, but it's 4am here:

PHP Code:
$query "INSERT INTO " TABLE_PREFIX ." participants (fieldname, fieldname)
              VALUES ("' $gamertag . '", "' . $eaddress . '")"

Also, you should use some of vBulletin coding standards. Such as santizing variables with $vbulletin->input->clean_array_gpc() and you don't have to connect to a database if your using this a vbulletin hack. (Since you would be including global.php)
Reply With Quote
  #3  
Old 04-14-2006, 10:48 AM
chilllax chilllax is offline
 
Join Date: Nov 2005
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, and Im not using it as a vbulletin hack but I will keep that in mind. One more quesiton though. Where participants is should that be the name of the database? Because thats the name of the database. And the table prefix is that only if my table has a prefix becuase it does not. So I am guessing the prefixless table name goes there. Correct?
Reply With Quote
  #4  
Old 04-14-2006, 12:18 PM
Guest190829
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by chilllax
Thanks, and Im not using it as a vbulletin hack but I will keep that in mind. One more quesiton though. Where participants is should that be the name of the database? Because thats the name of the database. And the table prefix is that only if my table has a prefix becuase it does not. So I am guessing the prefixless table name goes there. Correct?
participants should be replaced by the table name, not database. Also, I see your using some of vbulletin's coding such as:

PHP Code:
$db->query 
So you should be able to use any other vbulletin code, if your using that.
Reply With Quote
  #5  
Old 04-15-2006, 07:45 PM
chilllax chilllax is offline
 
Join Date: Nov 2005
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It still will not work. I changed the original value of $query to what you told me to. I substituted the column names for the fieldnames, is that correct?ffa is the name of my table. Also when I try and run this script it brings up this error
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/chilllax/public_html/tournament/yourentry.php on line 40

If you need me to I can also post the code of the forms.

PHP Code:
<html>
<head>
<title>Your Entry</title>
</head>
<table align="center">
 <tr>
  <td>
<a href="http://www.officalhalo.com">Home</a> | 

<a href="/tournament/FFA.htm">FFA</a> |

<a href="/tournament/signup.htm">Sign Up</a> |

<a href="/tournament/results.htm">Results</a>
</td>
 </tr>
</table>
<body>
<h3 align="center">Your Entry</h3>
<?php
  $gamertag
=$_POST['gamertag'];
  
$eaddress=$_POST['eaddress'];
  
  if (!
$gamertag || !$eaddress)
  {
      echo 
'You have not entered all of the required information.<br />'
           
.'Please go back and try again.';
      exit;
  }

  @ 
$db = new mysqli('localhost''chilllax_chillla''red123''chilllax_tournament');
  
if (
mysqli_connect_errno())
{
    echo 
'Error: Could not connect to database. Please try again later.';
    exit;
}

$query "INSERT INTO " TABLE_PREFIX ." ffa (gamertag, eaddress)
              VALUES ("' $gamertag . '", "' . $eaddress . '")"
;  

$result $db->query($query);
if (
$result)
    echo 
$db->affected_rows.' Entry submitted into database.';
        
$db->close();

?>
</body>
</html>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:44 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03821 seconds
  • Memory Usage 2,215KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (3)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete