simple form not sending data to database

Discussion in 'PHP' started by dougvcd, Jun 27, 2007.

  1. #1
    ok this is the form

    <form action="add.php" method="post">
    <div id="info" style="width:360px;">
    
        <div align="left">
          <input type="text" name="name"> 
          <strong>Name:</strong>    <br>
          <br />
          <input type="text" name="username"> 
          <strong>Username:</strong>    <br>
          <br />
          <input type="text" name="password"> 
          <strong>Password:</strong>    <br> 
          <br />
          <input type="text" name = "email"> 
          <strong>Email      </strong><br>
          <br />
          <input type="text" name="parkname"> 
          <strong>Park Name:</strong>    <br>
          <br />
          <input type="text" name="parklocation"> 
          <strong>Park Location</strong>:
        <br>
          <br />
          <input type="text" name="caravandetails"> 
          <strong>Caravan Details</strong>:
        <p><strong>
        <br/>
          <input type="submit" value="submit"> 
        </div>
    </form>
    </div>
    HTML:
    this is the php code
    <?php 
    
    //This gets all the other information from the form 
    $name=$_POST['name'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $email=$_POST['email']; 
    $parkname=$_POST['parkname'];
    $parklocation=$_POST['parklocation'];
    $caravandetails=$_POST['caravandetails']; 
    
    // Connects to your Database 
    mysql_connect("s", "", "s") or die(mysql_error()); 
    mysql_select_db("u") or die(mysql_error()); 
    
    //Writes the information to the database 
    mysql_query("INSERT INTO `members` VALUES ('$name', '$username', '$password', '$email', '$parkname', '$parklocation', '$caravandetails')"); 
     
    		
    ?> 
    <?php
    echo "your information has been added to the directory You will be redirected to Add Photo in three seconds!><br /><br /> 
    
    					<div class='info'>If you don't wish to wait, <a href='email.php'>click here</a>";
    					echo'<meta http-equiv="REFRESH" content="3;url=email.php">';
    ?>					
     
    PHP:

     
    dougvcd, Jun 27, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    try adding the die(mysql_error()) to the mysql_query(), i'm almost positive that your problem lies there.
     
    ansi, Jun 27, 2007 IP
  3. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Are you using any auto_increment field in members table?, If so pass a null value to that column
     
    tamilsoft, Jun 27, 2007 IP
  4. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok
    thanks for info working now my fault had more fields in database than on form

    ok can you tell me is this possable in this code

    <?php 
    
    //This gets all the other information from the form 
    $name=$_POST['name'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $email=$_POST['email']; 
    $parkname=$_POST['parkname'];
    $parklocation=$_POST['parklocation'];
    $caravandetails=$_POST['caravandetails']; 
    $pname=$_POST['pname'];
    // Connects to your Database 
    mysql_connect("s", "d", "s") or die(mysql_error()); 
    mysql_select_db("u") or die(mysql_error()); 
    
    //Writes the information to the database 
    mysql_query("INSERT INTO `members` VALUES ('$name', '$username', '$password', '$email', '$parkname', '$parklocation', '$caravandetails', '$pname')"); 
     
    		
    ?> 
    PHP:
    $pname=$_POST['pname']; can i say some thing like if pname ="" then let pname ="pic0.jpg"
    so that if the field pname is blank it will insert the other into it
    cheers
    Doug
     
    dougvcd, Jun 28, 2007 IP
  5. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If the data type is similar, you can
     
    tamilsoft, Jun 28, 2007 IP
  6. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yes i want it to be text pic0.jpeg not a jpg file
    how do i code it
    cheers
    Doug
     
    dougvcd, Jun 28, 2007 IP