Another n00b messing it up

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Sleeve
Forum Newbie
Posts: 17
Joined: Wed Jan 22, 2003 12:39 am

Post by Sleeve »

Thanks elipollak. Although your code did what it was supposed to do, I still get no data entered into MySQL database. Curoius...do you think I may have too many characters in $query = "INSERT INTO 'requests' once the variables are sent?
I noticed that in creating the tables I wasn't able to use a single line to create all the columns. I had to partially create the table then use the ALTER TABLE command to finnish it off. Could this be in some way related? Would it make sense for me to break up the $query operation? ( if it is a opreation...I'm a n00b)
User avatar
gyardleydn
Forum Commoner
Posts: 27
Joined: Tue Dec 03, 2002 8:27 am

Post by gyardleydn »

Code: Select all

<?php

$query = "INSERT INTO 'requests' 'INSERT INTO `requests` ( `first` , `last` , `title` , 

`salon_name` , `address1` , `address2` , `city` , `state` , `Zip` , `phone` , `email` , 

`requested_cat` , `comments` , `date` ) VALUES ('$FirstName', '$LastName', '$Title', 

'$SalonName','$Address1', '$Address2', '$City', '$State', '$Zip', '$Phone', 

'$Email','$YesNo', '$Date', '$Comments')";
In this version you have two "INSERT INTO"s in your query. How could that work?
User avatar
gyardleydn
Forum Commoner
Posts: 27
Joined: Tue Dec 03, 2002 8:27 am

Post by gyardleydn »

Code: Select all

echo (mysql_affected_rows()?"success":"failure");
I tried an erroneous SQL statement with two inserts and recieved -1 as the return value so an inprovement would be

Code: Select all

echo (mysql_affected_rows() > 0?"success":"failure"),  '<BR>';
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

OMFG! Heres your problem

INSERT INTO 'requests' 'INSERT INTO `requests
----------------------------

You doubled a SQL statement.

Try this:

<?php
$query = "INSERT INTO requests (";
$query .= "'first','last','title','salon_name','address1','address2','city','state','Zip','phone','email','requested_cat','comments','date' ) VALUES (";
$query .= "'$FirstName', '$LastName', '$Title', '$SalonName','$Address1', '$Address2', '$City', '$State', '$Zip', '$Phone', '$Email','$YesNo', '$Comments','$Date' );

if ( mysql_query( $query ) )
{
echo "Entry Success";
}
else
{
echo "Failed!";
}

?>

OK your other problem was you were defining the variables to the VALUES wrong. You HAVE to put the VALUES in as they are in the INSERT SQL Statement.

Hope this works
Sleeve
Forum Newbie
Posts: 17
Joined: Wed Jan 22, 2003 12:39 am

Post by Sleeve »

wow! evilcoder, you're nuts with this stuff! I am Impressed. After working with your code a bit, It worked like a charm. Thanks for your help! All of you!
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

Thank sleeve, but if i was nuts at it, i would be able to figure out the error in a class i just made.. but no worries, ask whenever, we do our best.
Post Reply