The PHP Group PHP
Problem for The PHP Group PHP

Database talks to code but code won't talk to database




By ebonyworlds on Jan 18, 2009

" "
My code does not produce any error messages. I have 3 files: share.html where the user inputs data into a simple html form, insert.php which says Thank you, $Name then has the code that is supposed to insert the user's input into the database, favorites.php which uses a while loop to display the data from the database. After being thanked the user clicks a link going to favorites.php. The display works fine and will display data I input in PHPMyAdmin. Also I checked and if I put an invalid database name in insert.php it produces the string I wrote for or die. Also input from the form does appear on the insert.php page if I just use REQUEST but that's as far as it goes. Buteven though the correct database name produces no error the input from the html form is not inserted into the database and does not appear on the display page.
Comments:

Jan 18, 2009

- Greetings,
Thanks for your response. I think we may be closer to a solution but I still need help on how to get there. This is the error message produced after I added the code you provided:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/river/public_html/conraise/insert.php on line 17
and this is the line it is referring to:

16 $query="INSERT INTO Main VALUES
17 ('', '$Namefield','$Classfield','$Whyfield')";
18 echo "SQL ==>" STARTOFSQL<br>".$query." ENDOFSQL<br>";
19 mysql_query ($query);

For the life of me I do not see why or where it would be expecting a comma or seni colon there.

Jan 19, 2009

- I tried it but it didn't make the code pass the info to the database. Thanks

Best Solution

posted on Jan 18, 2009
Helpful)

HPCSolutions

Rank: Wiz 
Rating: 83%, 142 votes
Make sure you are connecting to the database,then just before you call your sql to insert use an echo statement to display the sql and check it for syntax:-
$sql = 'insert into table1 values('.$no.','.$no.',"block","'.$value3.'", "'.$value4.'")';
echo "SQL ==>" STARTOFSQL<br>".$sql." ENDOFSQL<br>";
Comments:

Jan 18, 2009

- I always use single quotes around the outside and double quotes around each field string, so try this

$query='INSERT INTO Main VALUES ("", "'.$Namefield.'","'.$Classfield.'","'.$Whyfield."')';

I enclose each field around a pair of double quotes so if $Namefield has a value red it changes to "red" in the insert statement,
so each '". is a double quote, single quote, then fullstop
and ."' is a fullstop, single quote, double quote
years of unix coding makes understanding quotes essential
let me know if you understand, ta HPC

Jan 19, 2009

- Is the database MySQL ?
Was this helpful?
Yes
No

Popular Solutions for The PHP Group PHP


Questions and Unsolved Problems for The PHP Group PHP


Do you recommend The PHP Group PHP?
Answer

Answer
I ruined ccsearch.php can I get a new one ?

Answer
I want to execute java command for a software which is stored on my web server with the help of... (More)

Answer
subject avaluation system php w/ mysql codes how to evaluate subject using php w/ mysql

Answer
Hi there, I am using PHP5, where i need to mail with attachement. exact thing is, am getting the... (More)


Didn't find what you were looking for?

Describe your problem:

Select a Category:







Ask our Experts

 

Solve Your Problem Now!
Chat Live with an Expert
Chat Now
Browse popular Problems
More Common Problems
Most Common Problems for:
For The PHP Group PHP:

Top Programming Tool Experts

Rank: Guru Guru  

Solutions: 1369
Member Since: July 2009

Experience: I have owned a computer networking sales and service company.

Ask Me
Find more Programming Tool Experts

Top Computer & Laptop Repair

(513) 874-3306
We fix and repair laptop motherboard no video, no...
LaptopOnCall Inc.

(952) 890-7770
Zkarlo.com provides discount and used laptop parts...
Zkarlo.com


       
Solve Your Problem Now!
Chat Live with an Expert
Chat Now

X
Continue
When the original poster rates a solution that was given to his own problem, that rating is locked!
X

Are you sure the solution content is Inappropriate?
   
Tech buddies can communicate directly to answer questions. Become a Tech Buddy and have direct access to your favorite expert for FREE!
Insert Link
Insert Image
Insert You-Tube clip
Insert List
Insert List
Spell Check

What is this?



Select