Jump to content

MYSQL Insert problem


The14thGOD

Recommended Posts

Me again, I've been working on this site for quite some time today so maybe im just getting tired of code and can't figure out small problems or what, but heres my error.
The code:
[code]<?php
session_start();
import_request_variables('pg');
include("includes/include_connect_db");
$date = date("Y-m-d");
if ($_SESSION[username]) {
$query = "INSERT INTO $select_table ($art_id, user_id, date, body, status) ";
$query .= "VALUES ($id,$user_id,'$date','$body','enabled')";
}
elseif (!$_SESSION[username]) {
$log = 'nolog';
header("Location: login.php?log=$log");
exit(0);
}
if(mysql_query($query)) {
$msg = 'com';
header("Location: art_piece.php?type=$art_id&id=$select_id&msg=$msg#com");
exit(0);
}
echo($query);
?>[/code]

The problem:
i get as a result:
INSERT INTO art_fractal_comments (fractal_id, user_id, date, body, status) VALUES ( 2, 1,'2007-01-27','dd','enabled')

I put that into mysql and it enters data just fine...so why my query is failing is a loss to me..

Thanks in advance
Link to comment
Share on other sites

oh sorry bout the php thing, idk how to use the code thing ^_^

i define them in my form which is:
[code]<?php
$user_query = "SELECT * FROM user WHERE username='$_SESSION[username]' ";
$user_results = mysql_query($user_query);
$user_row = mysql_fetch_array($user_results);
$select_table = "art_$art_type";
$select_table .= "_comments";
$select_id = "$id";
$select_id .= "_id";
$art_id = "$type";
$art_id .= "_id";
?>
<form method="post" action="add_comment.php">
<tr>
<td><textarea name="body" rows="5" cols="70"></textarea></td>
</tr>
<tr>
<td align="right"><input type="submit" value="Add Comment" /></td>
</tr>
<input type="hidden" name="select_table" value="<? echo($select_table) ?>" />
<input type="hidden" name="select_id" value="<? echo($select_id) ?>" />
<input type="hidden" name="art_id" value="<? echo($art_id) ?>" />
<input type="hidden" name="user_id" value="<? echo($user_row[id]) ?>" />
<input type="hidden" name="id" value="<? echo($_GET[id]) ?>" />
</form>
</table>[/code]

i hate to use so many hidden's but i couldnt figure out a way to send them any other way
*edit* added in where some variables were actually made*

thanks again for the help
Link to comment
Share on other sites

What are the datatypes on your columns?  Can you also get the SQL Error Message?  Also, I think thorpe wanted to see how the SQL was actually being executed, all we can see is that you are echoing it.  If you can execute the SQL fine from some other UI then it is likely that you have a problem connecting to your database.

if you're using mysql_query() then you can do something like this:

mysql_query($szQuery);
if(mysql_error() != "")
{
echo(mysql_error());
}

You'd most likely want something more sophisticated eventually but this is good enough to get some debug info during early develpment.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.