Page 2 of 2

Posted: Wed Jan 22, 2003 6:13 pm
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)

Posted: Wed Jan 22, 2003 7:31 pm
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?

Posted: Wed Jan 22, 2003 8:03 pm
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>';

Posted: Wed Jan 22, 2003 10:03 pm
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

Posted: Wed Jan 22, 2003 11:22 pm
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!

Posted: Wed Jan 22, 2003 11:27 pm
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.