vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Basic SQL query question (https://vborg.vbsupport.ru/showthread.php?t=146032)

Guest210212002 04-29-2007 03:31 PM

Basic SQL query question
 
I realize this is really basic, I'm learning as I go.

I'm trying to make a simple page to add data to a database. The database is named 'php', and I have a table with: id (int, auto increment) and text fields named lastname, firstname, org, cdate and notes.

My form input is a quick table, the inputs look like this:

Code:

<td width="100">Lastname</td>
<td><input name="lastname" type="text" id="lastname"></td>

So I assume that's posting "lastname".

I've defined these variables to grab the post data:

Code:

$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$org = $_POST['org'];
$cdate = $_POST['cdate'];
$notes = $_POST['notes'];

And here's my query:

Code:

// Add the info
$query = "INSERT INTO users (lastname, firstname, org, cdate, notes) VALUES ('$lastname', '$firstname', '$org', '$cdate', '$notes')";
mysql_query($query) or die('Error, insert query failed');

Which as you can guess, doesn't work. :D I'm reading and googling, but right now I'm kind of stuck at this point and not sure what I'm missing. If anyone could enlighten me, I'd really appreciate it. :)

calorie 04-29-2007 03:41 PM

Replace the query line with this to see the error being generated:
Code:

mysql_query($query) or die(mysql_error());
Also, it is generally not a good idea to insert GPC data directly. See example 1396 on this page for how to escape data.

Guest210212002 04-29-2007 03:49 PM

Aah, thanks. :D

Quote:

Access denied; you need the RELOAD privilege for this operation
That's the error I get with the actual output string. I'll definitely check that page out, right now I'm just trying to get the hang of things.

Edit: Woohoo! I got it! :D

That error is because I'm going by the O'Reilly book and was flushing privelages after the submit. Honestly I don't even know what it does (hehehe) so I dumped it and it works now. :)

Thank you very much! :)


All times are GMT. The time now is 01:04 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.01122 seconds
  • Memory Usage 1,718KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete