/    Sign up×
Community /Pin to ProfileBookmark

sending form data to database?!?!?!

i know its simple but it not working for me at all nothing seems to be sending over to the DB

[B]heres my html form[/B]

[code=html]<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>jQuery UI Example Page</title>
<link type=”text/css” href=”css/ui-lightness/jquery-ui-1.8.14.custom.css” rel=”stylesheet” />
<script type=”text/javascript” src=”js/jquery-1.5.1.min.js”></script>
<script type=”text/javascript” src=”js/jquery-ui-1.8.14.custom.min.js”></script>
<script>
$(function() {
$( “#datepicker” ).datepicker();
});
</script>
<style type=”text/css”>
/*demo page css*/
#datepicker{ font: 9px “Trebuchet MS”, sans-serif; margin: 50px;}

</style>
</head>
<body>
<form method=”post” action=”sendto db.php”><br/>
first name<input type=”text” name=”firstname” id=”firstname”><br/>
last name<input type=”text” name=”lastname” id=”lastnamename”><br/>
email<input type=”text” name=”email” id=”email”><br/>
<div id=”datepicker”></div> <br/>
<input type=”button” value=”submit” >
</form>

</body>
</html>[/code]

[B]Heres my PHP[/B]

[code=php]<?php

$firstname = $_POST[‘firstname’];
$lastname = $_POST[‘lastname’];
$email = $_POST[’email’];
$datepicker = $_POST[‘datepicker’];

mysql_connect (“localhost”, “xxxx”, “xxxx”) or die (‘Error: ‘ . msql_error());
mysql_select_db (“xxxx”);

$query=”INSERT INTO allymccoist (id, firstname, lastname, email, datepicker)
VALUES (‘NULL’, ‘”.$firstname.”‘, ‘”.$lastname.”‘, ‘”.$email.”‘, ‘”.$datepicker.”‘)”;

mysql_query($query) or die (‘Error Updating database’);

echo “Database updated with:” .$firstname. “” .$lastname. “” .$email. “” .$datepicker. ;
?>[/code]

[B]And heres how my Db looks[/B]

[URL=/][IMG]http://img717.imageshack.us/img717/9508/43345118.png[/IMG][/URL]

to post a comment
PHP

22 Comments(s)

Copy linkTweet thisAlerts:
@GalwayJul 28.2011 — What sort of errors are you getting?

Try echoing the $_POST variables to make sure at least the form submission is working.

And the line

[code=php]
echo "Database updated with:" .$firstname. "" .$lastname. "" .$email. "" .$datepicker. ;
[/code]


has an extra . at the end

Also make sure the table name is correct.
Copy linkTweet thisAlerts:
@popcopauthorJul 29.2011 — when i click the submit button absolutley nothing happens at all
Copy linkTweet thisAlerts:
@GalwayJul 29.2011 — change this line:

[code=html]
<input type="button" value="submit" >
[/code]


to this

[code=html]
<input type="submit" value="submit" >
[/code]
Copy linkTweet thisAlerts:
@popcopauthorJul 29.2011 — ok gettin somewhere,,, it says error updating database

do u think this maybe something to do with me using the jquery datepick to submit a date to the database??
Copy linkTweet thisAlerts:
@GalwayJul 29.2011 — Try getting rid of the
[code=php]
or die("Error updating database")
[/code]


line

if you really need to, use something like this:

[code=php]
or die('MYSQL error: ' . mysql_error());
[/code]
Copy linkTweet thisAlerts:
@popcopauthorJul 29.2011 — Fatal error: Call to undefined function mssql_get_last_message() in /home/gezzamon/public_html/tablename/send.php on line 14
Copy linkTweet thisAlerts:
@popcopauthorJul 29.2011 — any suggestions?
Copy linkTweet thisAlerts:
@GalwayJul 29.2011 — any suggestions?[/QUOTE]

that was my bad. recheck my last post.
Copy linkTweet thisAlerts:
@popcopauthorJul 29.2011 — have you edited ur post???

its exactly the same!!
Copy linkTweet thisAlerts:
@popcopauthorJul 29.2011 — Parse error: syntax error, unexpected ';' in /home/gezzamon/public_html/tablename/send.php on line 17
Copy linkTweet thisAlerts:
@Nateishere2011Jul 29.2011 — Don't you need a textbox in order for the date too appear?
Copy linkTweet thisAlerts:
@popcopauthorJul 29.2011 — I wanted to use the jquery date picker that i have on the page, would that not work??

Im trying to do a webpage where people try and guess the corrent date that somethin is goin to happen
Copy linkTweet thisAlerts:
@Nateishere2011Jul 29.2011 — Yeah well you would still need somewhere for the user to put the date in.
Copy linkTweet thisAlerts:
@popcopauthorJul 30.2011 — i was using the inline code to display the jquery UI datepicker

which was just to insert a div with the datepicker id, but i know what you mean by needing somewhere to put the date in.

does this mean i can use that?
Copy linkTweet thisAlerts:
@NvenomJul 30.2011 — wow.. this thread is all over the place..

This should get you going in the right direction.

  • 1. Escape all those variables. |Guide Here|

  • 2. Your db structure has id set as no Null so that there cant be an empty row.

    So dont send the ID row at all. let it fill its self out.

  • 3. No reason to have the form action to another page simply put the script above and act on a if(isset) command.


  • Here is the way it should look (or at least a start. I did not do the security part for you.)

    [code=php]
    <?php
    if(isset($_POST['fmsub'])){
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $datepicker = $_POST['datepicker'];

    mysql_connect("127.0.0.1", "name", "pass") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());

    $query="INSERT INTO allymccoist (firstname, lastname, email, datepicker)
    VALUES ('$firstname', '$lastname', '$email', '$datepicker')";

    mysql_query($query) or die(mysql_error());

    echo "Database updated with:$firstname, $lastname, $email, $datepicker";
    }
    ?>

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>jQuery UI Example Page</title>
    <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css" rel="stylesheet" />
    <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
    <script>
    $(function() {
    $( "#datepicker" ).datepicker();
    });
    </script>
    <style type="text/css">
    /*demo page css*/
    #datepicker{ font: 9px "Trebuchet MS", sans-serif; margin: 50px;}

    </style>
    </head>
    <body>
    <form method="post"><br/>
    first name<input type="text" name="firstname" id="firstname"><br/>
    last name<input type="text" name="lastname" id="lastnamename"><br/>
    email<input type="text" name="email" id="email"><br/>
    <div id="datepicker"></div> <br/>
    <input type="button" value="submit" name="fmsub">
    </form>

    </body>
    </html>
    [/code]


    Good luck with it, barely scratching the surface with it so experiment.

    some other tips..

    When you echo variables in ""'s you dont need ".$variable here." it will read out just fine without those.

    like this "hello $name"

    Avoid sending information as that usually bogs down people just have the information grabbed within the page with a if(isset).

    if(isset($_POST['Name of submit button'])){

    script here..

    }

    Enjoy.
    Copy linkTweet thisAlerts:
    @popcopauthorJul 30.2011 — thanks

    the issue im havin is that the date never seems to send by just selecting the date from the datepicker

    have a look

    http://www.gezzamondo.co.uk/allymccoist/form.php
    Copy linkTweet thisAlerts:
    @NvenomJul 30.2011 — Thats because your jquery is messed up try this. You may need to work on it a bit use the examples here if the script below dosent work

    Jquery UI Datepicker

    [code=php]
    <?php
    if(isset($_POST['fmsub'])){
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $datepicker = $_POST['datepicker'];

    mysql_connect("127.0.0.1", "name", "pass") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());

    $query="INSERT INTO allymccoist (firstname, lastname, email, datepicker)
    VALUES ('$firstname', '$lastname', '$email', '$datepicker')";

    mysql_query($query) or die(mysql_error());

    echo "Database updated with:$firstname, $lastname, $email, $datepicker";
    }
    ?>

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>jQuery UI Example Page</title>
    <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css" rel="stylesheet" />
    <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
    <script>
    $(function() {
    $( "#datepicker" ).datepicker();
    });
    </script>
    <style type="text/css">
    /*demo page css*/
    #datepicker{ font: 9px "Trebuchet MS", sans-serif; margin: 50px;}

    </style>
    </head>
    <body>
    <form method="post"><br/>
    first name<input type="text" name="firstname" id="firstname"><br/>
    last name<input type="text" name="lastname" id="lastnamename"><br/>
    email<input type="text" name="email" id="email"><br/>

    <script>
    $(function() {
    $( "#datepicker" ).datepicker();
    });
    </script>
    <div>
    <p>Date: <input id="datepicker" type="text"></p>
    </div>

    <input type="button" value="submit" name="fmsub">
    </form>

    </body>
    </html>
    [/code]
    Copy linkTweet thisAlerts:
    @popcopauthorJul 30.2011 — yeah still gettin an error

    Unknown column 'datepicker' in 'field list'

    the problem is that i wanted to show the actual datepicker inline, show that i was alwasy display rather than having to click on the text field for it to show
    Copy linkTweet thisAlerts:
    @NvenomJul 30.2011 — change
    [code=php]
    $query="INSERT INTO allymccoist (firstname, lastname, email, datepicker)
    VALUES ('$firstname', '$lastname', '$email', '$datepicker')";
    [/code]


    to

    [code=php]
    $query="INSERT INTO allymccoist (firstname, lastname, email, date)
    VALUES ('$firstname', '$lastname', '$email', '$datepicker')";
    [/code]


    And check your db structure. if that dosent work change date in your db from date type to var char.
    Copy linkTweet thisAlerts:
    @popcopauthorJul 30.2011 — the date is still appearing in the database as 0000-00-00

    this is a return of what is being send to the database in my last attempt:

    Array ( [firstname] => gerry [lastname] => mckay [email] => [email protected] [date] => 08/25/2011 ) Database updated with:[email protected]
    Copy linkTweet thisAlerts:
    @NvenomJul 30.2011 — Thats because your database structure.. did you change your date field from date type to varchar and try it??
    Copy linkTweet thisAlerts:
    @popcopauthorJul 30.2011 — yeah it didnt work

    ive got it working now though by using this

    $new_date = date('Y-m-d',strtotime($_POST['date']));
    ×

    Success!

    Help @popcop spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.6,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...