The14thGOD Posted January 27, 2007 Share Posted January 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
trq Posted January 27, 2007 Share Posted January 27, 2007 Where do you define $id, $user_id and $body?PS; Please use the full </php tag so as to enable syntax highlighting. Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted January 27, 2007 Author Share Posted January 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
Braclayrab Posted January 27, 2007 Share Posted January 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
Braclayrab Posted January 27, 2007 Share Posted January 27, 2007 I heard the 15th god never writes buggy SQL. :P Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted January 27, 2007 Author Share Posted January 27, 2007 well when you said the "having problems connecting to database" i looked at my include line and...i was missing the .php ^_^it must be the "ive been working on this all day and cant fix simple errors" thx for the helpand the15thgod cant..he's dead :(=P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.