Forum Moderators: coopster

Message Too Old, No Replies

debugging says something is wrong with this

But I don't know what it is

         

Sarah Atkinson

5:46 am on Jul 9, 2005 (gmt 0)

10+ Year Member



$addnomsql="INSERT INTO $thislist (name,reason) VALUES ('$nomname','$nomreason')";

dreamcatcher

6:44 am on Jul 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sarah,

Only problem here would be with the $thislist variable. Is it populated? Have you echoed it before your query to see what value it holds?

Have you tried using mysql_error()?

$addnomsql="INSERT INTO $thislist (name,reason) VALUES ('$nomname','$nomreason') or die(mysql_error())";

dc

coopster

11:58 am on Jul 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You may also want to addslashes [php.net] or use mysql_real_escape_string() [php.net] on those variables.

Sarah Atkinson

4:51 am on Jul 12, 2005 (gmt 0)

10+ Year Member



HEre is the errror message i get back

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\thegreatest\nominate.php on line 35

not added due to database error:You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '\" (name,reason) VALUES ('testing ','testing one two')' at line

jatar_k

4:55 am on Jul 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that means the query died

2 things

1. echo the full constructed query before sending it to mysql_query
echo '<p>',$addnomsql;

2. add an or die to your query statement
$query = mysql_query($addnomsql) or die ('<p>' . mysql_error());

though that may be the error from mysql, I hate those ones, they don't tell you anything. My guess is that the $thislist var is not a proper tablename or there is something extra in there

Sarah Atkinson

5:17 am on Jul 12, 2005 (gmt 0)

10+ Year Member



now i'm getting
Nominee was not added due to database error:Unknown column 'testing' in 'field list'

.

This is driving me nuts. I cazn't figure it out and my debugger isn't helping my at all. OF course it doesn't help that the only time I get to work on it is aboult 30 min before bed when everything is blurry and my eyes are stinging.

jatar_k

6:11 am on Jul 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what output do you get when you echo your full query.

my guess is it is missing the tablename so it thinks your testing values are the column names

Sarah Atkinson

7:24 am on Jul 13, 2005 (gmt 0)

10+ Year Member



INSERT INTO tg_american (name,reason) VALUES (Testin,123)

Nominee was not added due to database error:Unknown column 'Testin' in 'field list'

Sarah Atkinson

7:47 am on Jul 13, 2005 (gmt 0)

10+ Year Member



I changed it to a different format here is the code and here is the error


if(isset($_POST['name'])){
$sql="SELECT name FROM $thislist";
echo " sql2= $sql<br>";
$results=mysql_query($sql);
if(!$results){
exit('<p>erros retrieving data!<br />' . 'Error:' . mysql_error() . '</p>');}
$validnominecheck='yes';
$nomname=$_POST['name'];
$nomreason=$_POST['reason'];
echo " <br>Nominee name= $nomname";
while($stuff=mysql_fetch_array($results)){
$dbname=$stuff['name'];
if($dbname==$nomname)
{$validnominecheck='no'; }
}
if($validnominecheck=='yes'){
$addnomsql="INSERT INTO $thislist name=$nomname, reason=$nomreason";
echo "$addnomsql <br>";
if(@mysql_query($addnomsql)){
echo'<p>Your nominee has been added</p>';
}else{
echo'<p>Nominee was not added due to database error:' . mysql_error().'</p>';
}
}else{
echo '<p>Nominee not added because nominee has already been nominated</p>';
}
exit();

Nominee name= testing
INSERT INTO tg_american name=testing, reason=123

Nominee was not added due to database error:You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'name=testing, reason=123' at line 1

dreamcatcher

7:55 am on Jul 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sarah,

The syntax you are using for the insert is actually the update syntax. Try:

INSERT INTO $thislist SET (name,reason) VALUES ('$nomname','$nomreason');

dc

Sarah Atkinson

8:36 am on Jul 13, 2005 (gmt 0)

10+ Year Member



that was the first way I was doing it

this is the error i get

Nominee name= testing
INSERT INTO tg_american SET (name,reason) VALUES ('testing','1234')

Nominee was not added due to database error:You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(name,reason) VALUES ('testing','1234')' at line 1

dreamcatcher

8:56 am on Jul 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops, SET shouldnt be used in the INSERT query, sorry about that.

INSERT INTO $thislist (name,reason) VALUES ('$nomname','$nomreason');

I can`t really see any reason for that failing unless there is a problem with the $thislist variable, which there doesn`t seem to be as the name of the table is in the error query.