Jump to content

Archived

This topic is now archived and is closed to further replies.

jwwceo

Can't get this work...

Recommended Posts

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>

Share this post


Link to post
Share on other sites
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">

<?php
if(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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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'.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
check the manual for error_reporting ... and turn it on

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.