Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old June 11th, 2003, 12:47 PM
beeman81 beeman81 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Jakobstad, Finland
Posts: 59 beeman81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
submit button doesn´t work!!

Why does the submit button not work?
when I run the file (user_add.php) this message shows up (before the form):
Notice: Undefined variable: submit in C:WebsitesphpsitephpB6.tmp on line 2

I used php for the first time 2 days ago, so look out for dumb mistakes!!

the code (focus on the submit button!):
php Code:
Original - php Code
  1.  
  2. <?php
  3.    if ($submit)
  4.       {
  5.          include("db_conn.php");
  6.          include("kjellmantest.php");
  7.  
  8.          $query = "INSERT INTO forsale (`make`,`model`,`useage`,`price`)
  9.           VALUES ('$make', '$model', '$useage', '$price')";
  10.          $result = mysql_query($query) or die("Error in query. "  .mysql_error());
  11.       }
  12. // if the form hasn't been submitted we need to display it
  13.    else
  14.       {
  15. // here is the form
  16. ?>
  17.    <h1>Machines</h1>
  18.    <form class="cent" action="<?php PHP_SELF ?>" method="post">
  19.      <table class="form" width="70%" border="0" cellpadding="0" cellspacing="0">
  20.         <tr>
  21.            <td colspan="2">
  22.               Please Enter the Details<br>
  23.            </td>
  24.         </tr>
  25.         <tr>
  26.            <td>
  27.               <br>
  28.               make
  29.            </td>
  30.            <td>
  31.               <br>
  32.               <input type="Text" name="make">
  33.               <br>
  34.            </td>
  35.         </tr>
  36.         <tr>
  37.            <td>
  38.               <br>
  39.               model
  40.            </td>
  41.            <td>
  42.               <br>
  43.               <input type="Text" name="model">
  44.               <br>
  45.            </td>
  46.         </tr>
  47.         <tr>
  48.            <td>
  49.               <br>
  50.               useage
  51.            </td>
  52.            <td>
  53.               <br>
  54.               <input type="Text" name="useage">
  55.               <br>
  56.            </td>
  57.         </tr>
  58.         <tr>
  59.            <td>
  60.            <br>
  61.               price
  62.            </td>
  63.            <td>
  64.               <br>
  65.               <input type="Text" name="price">
  66.               <br>
  67.            </td>
  68.         </tr>
  69.         <tr>
  70.            <td colspan="2">
  71.            </td>
  72.         </tr>
  73.       <tr>
  74.          <td colspan="2">
  75.             <input type="submit" name="submit" value="submit">
  76.          </td>
  77.       </tr>
  78.         <tr>
  79.            <td colspan="2">
  80.  
  81.            </td>
  82.         </tr>
  83.      </table>
  84.    </form>
  85. <?php
  86.       }
  87. ?>
  88.                         </td>
  89.                   </tr>
  90.                </table>
  91.             </td>
  92.          </tr>
  93.       </table>
  94. </body>
  95. </html>


The db_conn.php - file only includes connection to the MySql database... what the heck... here´s the code if for any use..:

php Code:
Original - php Code
  1.  
  2. <?php
  3. // variables used to open connection to the database
  4. $server = "localhost";
  5. $user = "";
  6. $pass = "";
  7. $db = "kjellman";
  8.  
  9. // open connection
  10. $connection = mysql_connect($server, $user, $pass);
  11.  
  12. // select database
  13. mysql_select_db($db, $connection);


And the code for kjellmantest.php if needed:

php Code:
Original - php Code
  1.  
  2. <html>
  3. <body>
  4.  
  5. <?php
  6.  
  7. include("db_conn.php");
  8.  
  9. $result = mysql_query("SELECT * FROM forsale",$connection);
  10.  
  11.     echo "<table border=1>n";
  12.     echo "<tr><td>make</td><td>model</td><td>useage</td><td>price</tr>n";
  13.  
  14. while ($myrow = mysql_fetch_row($result))
  15. {
  16.       echo "<tr><td>";
  17.       echo $myrow[0] ;
  18.       echo "</td><td>";
  19.       echo $myrow[1] ;
  20.       echo "</td><td>";
  21.       echo $myrow[2] ;
  22.       echo "</td><td>";
  23.       echo $myrow[3] ;
  24.       echo "</td></tr>n";
  25. }
  26. echo "</table>n";
  27.  
  28. mysql_close($connection);
  29. ?>
  30.  
  31. </body>
  32. </html>


Thanks in advance!!

Reply With Quote
  #2  
Old June 11th, 2003, 03:00 PM
sliver's Avatar
sliver sliver is offline
Moderator
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: WI, USA
Posts: 906 sliver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 18 m 35 sec
Reputation Power: 2
Send a message via AIM to sliver Send a message via XFire to sliver
RE: submit button doesn´t work!!

OK you may need to replace the post variable like $submit with $_POST['submit']. Also in the user_add.php script you have:
php Code:
Original - php Code
  1.  
  2. <form class="cent" action="<?php PHP_SELF ?>" method="post">

when it should be:
php Code:
Original - php Code
  1.  
  2. <form class="cent" action="<?php $PHP_SELF ?>" method="post">

Reply With Quote
  #3  
Old June 12th, 2003, 05:50 AM
beeman81 beeman81 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Jakobstad, Finland
Posts: 59 beeman81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
It still doesn't work..

You wrote: "OK you may need to replace the post variable like $submit with $_POST['submit']..."

Where do I put in that?? Be more specific

Reply With Quote
  #4  
Old June 12th, 2003, 02:33 PM
sliver's Avatar
sliver sliver is offline
Moderator
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: WI, USA
Posts: 906 sliver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 18 m 35 sec
Reputation Power: 2
Send a message via AIM to sliver Send a message via XFire to sliver
RE: submit button doesn´t work!!

Whereever you have variable posted through a post form you need to use them like this:
php Code:
Original - php Code
  1.  
  2. $name=$_POST['name'];

or whatever the name of the variable would be:
php Code:
Original - php Code
  1.  
  2. <form action=myform.php method=post>
  3. Name: <input type=text name=name><br>
  4. <input type=submit name=sub value="Submit">
  5. </form>


Myform.php:
php Code:
Original - php Code
  1.  
  2. if($_POST['sub']) {
  3.    print "Hi ".$_POST['name'];
  4. }

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > submit button doesn´t work!!


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 |