The PHP Group PHP Logo
Posted on Jan 18, 2009
Answered by a Fixya Expert

Trustworthy Expert Solutions

At Fixya.com, our trusted experts are meticulously vetted and possess extensive experience in their respective fields. Backed by a community of knowledgeable professionals, our platform ensures that the solutions provided are thoroughly researched and validated.

View Our Top Experts

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

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.

  • ebonyworlds 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
    ".$query." ENDOFSQL
    ";

    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.

  • ebonyworlds Jan 19, 2009

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

×

1 Answer

Anonymous

Level 2:

An expert who has achieved level 2 by getting 100 points

All-Star:

An expert that got 10 achievements.

MVP:

An expert that got 5 achievements.

Vice President:

An expert whose answer got voted for 100 times.

  • Expert 258 Answers
  • Posted on Jan 18, 2009
Anonymous
Expert
Level 2:

An expert who has achieved level 2 by getting 100 points

All-Star:

An expert that got 10 achievements.

MVP:

An expert that got 5 achievements.

Vice President:

An expert whose answer got voted for 100 times.

Joined: Jan 11, 2009
Answers
258
Questions
0
Helped
140187
Points
619

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>";

  • Anonymous 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

  • Anonymous Jan 19, 2009

    Is the database MySQL ?

×

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

1,460 views

Ask a Question

Usually answered in minutes!

Top The PHP Group Computers & Internet Experts

Rob Hill
Rob Hill

Level 3 Expert

1483 Answers

Nikole Brown
Nikole Brown

Level 2 Expert

124 Answers

Syed Bilal
Syed Bilal

Level 3 Expert

252 Answers

Are you a The PHP Group Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...