SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 26th, 2002, 11:54 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
form making blank entry

I have a form page used to edit data in database (mysql), and the form works fine. But, what it also does is when I even visit the form, without editing a row of data, is it adds a blank row....just by visiting the page.

The page has a session check at the beginning...it is set up similar to Ben's tutorial on making a basic form and database ( PHP and Mysql basics : I think) in that it just displays the data, editable, and repost it. Can also delete it.

Anyway, what would cause blank data to be entered ( a post ) without hitting the INPUT button?
__________________
bow wow!

Reply With Quote
  #2  
Old November 27th, 2002, 03:20 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Can you post the source? I would guess you're not doing any checking if the form has been submit before you insert/update the data.. but I can't say for sure without actually seeing the source
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #3  
Old November 27th, 2002, 11:36 AM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Here is the code...

I am sorry, but I can't seem to get the php code to load all colored...how to do this?

PHP Code:
<?php
  session_start
();

  echo 
"<h1>Members only</h1>";

  
// check session variable

  
if (session_is_registered("valid_user"))
  {
    echo 
"<p>You are logged in as $valid_user.</p>";
  }
  else
  {
    echo 
"You are not logged in, try logging again at: <a href='authmain.php'>Teacher Log In</a>.";
    die();
  }
  if (
$valid_user != "edit")
  {
  echo 
"You are not autherized to use this page, try logging again at: <a href='http://www.aq.com/teacherlogin.php'>Teacher Log In</a>.";
    die();
  }
  else
  {
   echo 
"<p>Good to see you again $valid_user.</p>";
  }
  
?>

<html><title>Book Input</title>
<body bgcolor="#999999" text="#000000"></i> 
</a>
<div align = "right"><br>
</div>
<div align="center"> 
  <p><font size="4"><b>Aquarian Book/ Video/ Media Database Input</b></font></p>
  
</div>
<br>
<br>
<tablewidth="700" border="1">
<tr>
<td>
<?php
$db_name 
"aquaria_books";
$table_name "bookinput";
$connection = @mysql_connect("localhost""user""pass") or die(mysql_error());
$db = @mysql_select_db($db_name$connection) or die(mysql_error());
$sql "INSERT INTO $table_name (title, authorname, mediatype, subject, publisher, edition, copyright,isbn, quantity, location, description) VALUES ('$_POST[title]', '$_POST[authorname]', '$_POST[mediatype]', '$_POST[subject]', '$_POST[publisher]', '$_POST[edition]', '$_POST[copyright]','$_POST[isbn]', '$_POST[quantity]', '$_POST[location]', '$_POST[description]')";
$result = @mysql_query($sql$connection) or die(mysql_error());
if (
$submit) { 
// here if no ID then adding else we're editing 
if ($id) { 
$sql "UPDATE bookinput SET title='$title',authorname='$authorname',mediatype=  '$mediatype',subject= '$subject',publisher='$publisher', edition= '$edition', copyright= '$copyright',isbn='$isbn', quantity='$quantity',location='$location',descript  ion='$description'  WHERE id=$id"
} else {
$sql "INSERT INTO bookinput (title,authorname,mediatype,subject,publisher,edit  ion,copyright,isbn,quantity,location,description) VALUES ('$title', '$authorname','$mediatype','$subject','$publisher'  ,'$edition','$copyright','$isbn', '$quantity','$location','$description')"

// run SQL against the DB 
$result mysql_query($sql); 
echo 
"Record updated/edited!<p>"
} elseif (
$delete) { 
// delete a record 
$sql "DELETE FROM bookinput WHERE id=$id";    
$result mysql_query($sql); 
echo 
"$sql Record deleted!<p>"
} else { 
// this part happens if we don't press submit 
if (!$id) { 
// print the list if there is not editing 
echo "<a href='book.php'>All Reconds in DB</a>";

?>
</td>
<form method="post" action="<?PHP echo $PHP_SELF?>">  
<?PHP 
if ($id) { 
// editing so select a record 
$sql "SELECT * FROM bookinput WHERE id=$id"
$result mysql_query($sql); 
$myrow mysql_fetch_array($result); 
$id $myrow["id"]; 
$title $myrow["title"];
$authorname $myrow["authorname"]; 
$mediatype $myrow["mediatype"];
$subject $myrow["subject"];
$publisher $myrow["publisher"]; 
$edition $myrow["edition"];
$copyright $myrow["copyright"];
$isbn $myrow["isbn"];
$quantity $myrow["quantity"];
$location $myrow["location"];
$description $myrow["description"]; 
// print the id for editing 
?> 
<input type=hidden name="id" value="<?PHP echo $id ?>"> 
<?PHP 

?> 
<td>&nbsp;</td>
<td>
<TABLE CELLSPACING=3 CELLPADDING=3>
<TD VALIGN=TOP>
        <P><STRONG>Title:(Full Title)</strong><br>
          <INPUT TYPE="text" NAME="title" VALUE="<?PHP echo $title ?>" SIZE=25 MAXLENGTH=50>
          <br>
        </P>
        <P><font color="#FF0000">Example: National Geographic<br>
          and : PHP Fast and Easy</font></P>
        </TD>
<TD VALIGN=TOP>
<P><STRONG>Author:(Full Name)</STRONG><BR>
<INPUT TYPE="text" NAME="authorname" VALUE="<?PHP echo $authorname ?>" SIZE=25 MAXLENGTH=35>
          <br>
          <br>
          <font color="#FF0000">Example: John Smith</font></P>
</TD>
<TD VALIGN=TOP>
<P><STRONG>Media Type:</STRONG><br>
<INPUT TYPE="radio" NAME="mediatype" VALUE="TextBook">Text Book<br>
<INPUT TYPE="radio" NAME="mediatype" VALUE="Book">Book<br>
<INPUT TYPE="radio" NAME="mediatype" VALUE="Magazine">Magazine<br>
<INPUT TYPE="radio" NAME="mediatype" VALUE="Video">Video<br>
<INPUT TYPE="radio" NAME="mediatype" VALUE="Software">
          Software<br>
<INPUT TYPE="radio" NAME="mediatype" VALUE="Maps">
          Maps<br>
<INPUT TYPE="radio" NAME="mediatype" VALUE="Misc">
          Misc.<br>                   
          <font color="#FF0000"><br>
          Pick the closest match.</font></P>
</TD>
</TR>
<TR>
<TD VALIGN=TOP>
        <P><STRONG>Publisher: </STRONG><BR>
          <font color="#FF0000">
          <INPUT TYPE="text" NAME="publisher" VALUE = "<?PHP echo $publisher ?>" SIZE=25 MAXLENGTH=35>
          </font></P>
        <P><font color="#FF0000">Example: Western Book Press</font></P>
</TD>
<TD VALIGN=TOP>
<P><STRONG>Subject: (Choose Closest)</STRONG><br>
<INPUT TYPE="radio" NAME="subject" VALUE="Science">Science<br>
<INPUT TYPE="radio" NAME="subject" VALUE="Social_Studies">Social Studies<br>
<INPUT TYPE="radio" NAME="subject" VALUE="English">English<br>
<INPUT TYPE="radio" NAME="subject" VALUE="Spanish">Spanish<br>
<INPUT TYPE="radio" NAME="subject" VALUE="Math">Math<br>
<INPUT TYPE="radio" NAME="subject" VALUE="Professional">Professional<br>
<INPUT TYPE="radio" NAME="subject" VALUE="Leveled_Readers">Leveled Readers<br>
<INPUT TYPE="radio" NAME="subject" VALUE="Information">Information<br>
</P>
</TD>
</TR>
<TD VALIGN=TOP>
<P><STRONG>Edition:(1st, 2nd, or Date) </STRONG><BR>
<INPUT TYPE="text" NAME="edition"  VALUE= "<?PHP echo $edition ?>" SIZE="35" MAXLENGTH=100></P>
</TD>
<TR>
<TD VALIGN=TOP>
        <P><STRONG>Copyright: </STRONG><BR>
<INPUT TYPE="text" NAME="copyright" VALUE= "<?PHP echo $copyright ?>" SIZE=25 MAXLENGTH=35>
          <br>
          <font color="#FF0000">Example: 2002 Western Press</font></P>
</TD>
</TR>
      <TD VALIGN=TOP height="70"> 
        <P><STRONG>ISBN:(or Library of Congress) </STRONG><BR>
<INPUT TYPE="text" NAME="isbn" VALUE= "<?PHP echo $isbn ?>" SIZE=25 MAXLENGTH=35>
          <br>
          <font color="#FF0000">Example: 123-1223-992-088</font> </P>
</TD>
      <TD VALIGN=TOP height="70"> 
        <P><STRONG>Location: (Room #, Book Room, etc.) </STRONG><BR>
          <select name="location">
            <option>Location:</option>
            <option value="Room 1">Room 1</option>
            <option value="Room 2">Room 2</option>
            <option value="Room 3">Room 3</option>
            <option value="Room 4">Room 4</option>
            <option value="Room 5">Room 5</option>
            <option value="Room 6">Room 6</option>
            <option value="Room 7">Room 7</option>
            <option value="Book Room">Book Room</option>
            <option value="Computer Lab">Computer Lab : Room 10</option>
            <option value="Library">Library</option>
            <option value="Room 13">Room 13</option>
            <option value="Room 14">Room 14</option>
            <option value="Room 15">Room 15</option>
            <option value="Room 16">Room 16</option>
            <option value="Teacher Work Room">Teacher Work Room</option>
          </select>
          <br>
        </P>
</TD>
      <TD VALIGN=TOP height="70"> 
        <P><STRONG>Quantity: </STRONG><BR>
          <INPUT TYPE="text" NAME="quantity"  VALUE= "<?PHP echo $quantity ?>" SIZE=10 MAXLENGTH=35>
          <br>
          <font color="#FF0000">Example: 4<br>
          Only Give Numerical Entry!<br>
          State if Book Set and # in set<br>
          under "Description" Box.<br>
          If several copies exist, list total number!</font></P>
        </TD>
<TR>
<TD VALIGN=TOP COLSPAN=2 ALIGN=CENTER>
        <P align="left"><STRONG>Description: (Be brief) </STRONG><BR>
          <font color="#FF0000"> 
          <TEXTAREA NAME="description" COLS=50 ROWS=5 WRAP=virtual><?PHP echo $description ?>
</TEXTAREA>
          <br>
          Give brief description of the media type. List articles in magazine. 
          Be specific.<br>
          Queries of database are done using the "key words" listed 
          in the above boxes!</font><font color="#FF0000"><br>
          Record Book Sets here, and the quantity of each set.</font><br>
          <font color="#FF0000">Check to see all areas are completed before Adding 
          a Record. Where unsure: NA. </font></P>
   <input type="Submit" name="submit" value="Enter information">
    <a href="<?PHP echo $PHP_SELF?>">Clear and Refresh</a>
</TD>
</TR>
</TABLE>
</FORM> 
<p>&nbsp;</p>
<?PHP 

?> 
</body> 
</html>


I hope this works...

This is "edit" code. Trying to figure out why it posts from just a visit to the page, and not posting when SUBMIT is pressed.

Last edited by littleblackdog : November 27th, 2002 at 11:40 AM.

Reply With Quote
  #4  
Old November 30th, 2002, 07:44 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Sorry to post so long...

This is rather long, sorry for such a long post. I am having trouble...Lindset suggested I might be:

I would guess you're not doing any checking if the form has been submit before you insert/update the data..

I am hoping to get someone to look at the long posted code and see if I am checking for the form....I'm not sure how to do this.. with an if statement...

What is happening is the form is posting from just visiting the page, withought hitting "submit".

Any ideas?

Reply With Quote
  #5  
Old November 30th, 2002, 10:48 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Re: Here is the code...

Quote:
Originally posted by littleblackdog

PHP Code:
<?php
$db_name 
"aquaria_books";
$table_name "bookinput";
$connection = @mysql_connect("localhost""user""pass") or die(mysql_error());
$db = @mysql_select_db($db_name$connection) or die(mysql_error());
$sql "INSERT INTO $table_name (title, authorname, mediatype, subject, publisher, edition, copyright,isbn, quantity, location, description) VALUES ('$_POST[title]', '$_POST[authorname]', '$_POST[mediatype]', '$_POST[subject]', '$_POST[publisher]', '$_POST[edition]', '$_POST[copyright]','$_POST[isbn]', '$_POST[quantity]', '$_POST[location]', '$_POST[description]')";
$result = @mysql_query($sql$connection) or die(mysql_error());
if (
$submit) { 
// here if no ID then adding else we're editing 
if ($id) {



This is where you problem lies... If you notice, you have an INSERT statement before checking for your "$submit" value... Your validation is done underneath.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #6  
Old December 2nd, 2002, 11:16 AM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Thanks Frankie!

Thanks Frankie! That did it! I was inserting before the submit and that was the problem... too much cut and paste and not enough checking. : )

Wow! Feels good to finish at least part of a project!

Reply With Quote
  #7  
Old December 6th, 2002, 01:46 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
No problem... I'm glad to help out!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > form making blank entry


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway