jwwceo Posted August 23, 2006 Share Posted August 23, 2006 Hey all..I am trying to write my first PHP file that will write to a database, MySQL. I just can't get this to work. I've been playing with this for hours...any obvious things wrong with this code...thanks in advance...<html><head><title>Add A Shirt</title></head><body bgcolor="#FFFFFF"><?if($_POST['submit']){ mysql_connect("localhost","root","9579"); mysql_select_db("tees"); $shirt_id=$_POST['shirt_id']; $name=$_POST['name']; $comment=$_POST['comment']; $link=$_POST['link']; $site=$_POST['site']; $image=$_POST['image']; $active=$_POST['active']; $commission=$_POST['commission']; $result="INSERT INTO shirts (shirt_id,name,comment,link,site,image,active,commission) VALUES ('NULL', '$name', '$comment', '$link', '$site', '$image', '$active', '$commission' )"; mysql_query($result); echo "Thanks for adding the tee"; ?><?else{?><form method="post" action="add.php"><TABLE><TR> <TD>Name:</TD> <TD><INPUT TYPE='TEXT' NAME='name' size=100></TD></TR><TR> <TD>Comment</TD> <TD><INPUT TYPE='TEXT' NAME='comment' size=100></TD></TR><TR> <TD>Link</TD> <TD><INPUT TYPE='TEXT' NAME='link' size=100></TD></TR><TR> <TD>Site</TD> <TD><INPUT TYPE='TEXT' NAME='site' size=100></TD></TR><TR> <TD>Image</TD> <TD><INPUT TYPE='TEXT' NAME='image' size=100></TD></TR><TR> <TD>Active</TD> <TD><INPUT TYPE='TEXT' NAME='active' size=100></TD></TR><TR> <TD>Commission</TD> <TD><INPUT TYPE='TEXT' NAME='commission' size=100></TD></TR><TR> <TD></TD><br> <TD><INPUT TYPE="submit" name="submit" value="Add this Tee"></TD></TR></TABLE></form><?} ?></body> </html> Link to comment https://forums.phpfreaks.com/topic/18461-cant-get-this-work/ Share on other sites More sharing options...
AndyB Posted August 23, 2006 Share Posted August 23, 2006 Try this variant. If it "doesn't work" then please be specific about what you see, what happens, what doesn't happen, etc. since it helps resolve the problem(s).[code]<html><head><title>Add A Shirt</title></head><body bgcolor="#FFFFFF"><?phpif(isset($_POST['submit'])) { mysql_connect("localhost","root","9579"); mysql_select_db("tees"); $shirt_id=$_POST['shirt_id']; $name=$_POST['name']; $comment=$_POST['comment']; $link=$_POST['link']; $site=$_POST['site']; $image=$_POST['image']; $active=$_POST['active']; $commission=$_POST['commission']; $query="INSERT INTO shirts (shirt_id,name,comment,link,site,image,active,commission) VALUES ('NULL', '$name', '$comment', '$link', '$site', '$image', '$active', '$commission' )"; $result = mysql_query($query) or die("Eror: ". mysql_error(). " with query ". $query); echo "Thanks for adding the tee";} else {?><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"><TABLE><TR> <TD>Name:</TD> <TD><INPUT TYPE='TEXT' NAME='name' size=100></TD></TR><TR> <TD>Comment</TD> <TD><INPUT TYPE='TEXT' NAME='comment' size=100></TD></TR><TR> <TD>Link</TD> <TD><INPUT TYPE='TEXT' NAME='link' size=100></TD></TR><TR> <TD>Site</TD> <TD><INPUT TYPE='TEXT' NAME='site' size=100></TD></TR><TR> <TD>Image</TD> <TD><INPUT TYPE='TEXT' NAME='image' size=100></TD></TR><TR> <TD>Active</TD> <TD><INPUT TYPE='TEXT' NAME='active' size=100></TD></TR><TR> <TD>Commission</TD> <TD><INPUT TYPE='TEXT' NAME='commission' size=100></TD></TR><TR> <TD></TD> <TD><INPUT TYPE="submit" name="submit" value="Add this Tee"></TD></TR></TABLE></form><?php}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/18461-cant-get-this-work/#findComment-79425 Share on other sites More sharing options...
jwwceo Posted August 23, 2006 Author Share Posted August 23, 2006 That worked. I totally appreciate it. I noticed what you changed..but what was wrong? I copied several online tutorials to the tee...THANKS AGAIN!JAMES Link to comment https://forums.phpfreaks.com/topic/18461-cant-get-this-work/#findComment-79436 Share on other sites More sharing options...
AndyB Posted August 23, 2006 Share Posted August 23, 2006 What was wrong? Mostly that you had omitted the closing curly brace } in the uppermost loop of your code. The other changes were 'cosmetic/constructive'. Link to comment https://forums.phpfreaks.com/topic/18461-cant-get-this-work/#findComment-79441 Share on other sites More sharing options...
jwwceo Posted August 23, 2006 Author Share Posted August 23, 2006 That was probably it...The page would load but when you submitted the form..nothing happened...it simply cleared the data, like a reload....Is there any place to check error logs so I can see if there is a syntax error on line X??? I have error logs on Apache..and the browser will display the MySQL error if I have the tags set up right...but I can't find a place to find error logs for the PHP itself... Link to comment https://forums.phpfreaks.com/topic/18461-cant-get-this-work/#findComment-79454 Share on other sites More sharing options...
AndyB Posted August 23, 2006 Share Posted August 23, 2006 check the manual for error_reporting ... and turn it on Link to comment https://forums.phpfreaks.com/topic/18461-cant-get-this-work/#findComment-79456 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.