Jump to content


Photo

Can't get this work...


  • Please log in to reply
5 replies to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 23 August 2006 - 07:11 PM

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>


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 August 2006 - 07:20 PM

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).

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

Legend has it that reading the manual never killed anyone.
My site

#3 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 23 August 2006 - 07:26 PM

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

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 August 2006 - 07:30 PM

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'.
Legend has it that reading the manual never killed anyone.
My site

#5 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 23 August 2006 - 07:44 PM

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...



#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 August 2006 - 07:46 PM

check the manual for error_reporting ... and turn it on
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users