SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form value, php echo problem

    I have analysed every bit of code from my form and i dont understand why when i submit the form the value for my 'email' and 'event' fields are not storing the submitted data...

    <?php
    if(isset($_POST['submit'])){

    $dbc= mysqli_connect('localhost','user_alien','alien123','mookle');
    $email=mysqli_real_escape_string($dbc,trim($_POST['email']));
    $event=mysqli_real_escape_string($dbc,trim($_POST['eventname']));
    $datefrom=mysqli_real_escape_string($dbc,trim($_POST['datefrom']));
    $dateto= mysqli_real_escape_string($dbc,trim($_POST['dateto']));
    $description=mysqli_real_escape_string($dbc,trim($_POST['ret']));
    $website=mysqli_real_escape_string($dbc,trim($_POST['website']));
    $industry=$_POST['industry'];

    //check required fields//
    $error=array();
    if(empty($email)){$error[]='Please enter your email address';}
    if(empty($description)){$error[]='Please enter your description!';}
    if(empty($event)){$error[]='Please enter your event name!';}
    if(count($error)==0){

    //connect to database//
    $dbc= mysqli_connect('localhost','user_alien','alien123','mookle')
    or die('mysql error has occured');
    $query="INSERT INTO mookle_events VALUES('$email','$event','$datefrom','$dateto','$description','$website','$industry')";
    $result=mysqli_query($dbc,$query)
    or die('try again, mysql error occurered');
    if($result){
    echo ('your event is now in our system!');}
    else{'result aint working';}

    }
    else {
    echo implode('<br />',$error);}

    }

    ?>

    <table width="950" height="54" border="0" align="center" cellpadding="0" cellspacing="0" ba bgcolor="#3300CC">
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>

    ...

    <form method="post" action="newevent.php"/>
    <span class="style2">
    <label for="email">Your Email</label>
    <input type="text" name="email" id="email" class="BigText" value="<?php echo $email; ?>"/>
    </span>
    <p class="style2">
    <label for="eventname">Event Name</label>
    <input type="text" name="eventname" id="eventname" class= "BigText" value="<?php echo $event;?>"/>
    </p><p class="style2">
    <label for="date">Date: From</label>
    <input type="text" id="datefrom" name="datefrom" class="BigText"/>To:
    <input type="text" id="dateto" name="dateto" class="BigText"/>
    </p>
    <label for="eventdes" class="style2">Event <br />
    Description</label>
    <p>
    <textarea name="ret" cols="54" rows="10"/><?php echo $description;?></textarea>
    </p><p class="style2">
    <label for="website">Event Website</label>
    <input type="text" id="website" name="website" class="BigText" />
    </p>
    <p class="style2">
    <label for="industry">Industry</label>
    <input type="text" name="industry" id="industry" class="BigText"/>
    </p>
    <input type="submit" value="New Event" name="submit" id="submit"/>
    </form></p>

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't looked into the code, but try to echo $query to check the query. Another thing, aren't you connecting to the database twice?

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked the query and it seems to be ok.

    INSERT INTO mookle_events VALUES('test@gmail.com','test','test','test','test','test','test')

  4. #4
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't know if it's the forum or your code,
    But in the mysql insert the $industry variable has a space inside it

    Are any errors shown?
    The form itself looks fine as far as I can see (providing you've declared the $email,$event and $description prior to the conditional statement)

    Personally (though some may disagree) may I suggest dropping the use of mysqli_real_escape_string? For maybe htmlentities
    Or at the very least remove the 2nd mysqli_connect, while I'm not familiar with procedural mysqli, I'm quite sure it being declared twice is overkill

  5. #5
    SitePoint Zealot Jaanboy's Avatar
    Join Date
    Sep 2007
    Location
    UK
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As pointed out, you only need to connect to the DB once, so you can remove the second call to mysqli_connect.

    Pretty sure the problem is because you're not specifying which columns to insert the data into. If the values you are not inserting are not in order, you need to tell the DB whereabouts they go:

    PHP Code:
    "INSERT INTO mookle_events
    (`column1`, `column2`, `column3`, etc..)
    VALUES
    ('
    $email','$event','$datefrom','$dateto','$description','$website','$industry')"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •