Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Data not going into database

    once the user enters data and clicks submit the data doesnt go onto the database i dont know whats wrong. Heres my code
    PHP Code:
    <?php
    2 ob_start
    ();
    3 $host="localhost"// Host name 
    4 $username="****"// Mysql username 
    5 $password="*****"// Mysql password 
    6 $db_name="*****"// Database name 
    7 $tbl_name="MainT"// Table name 

    // Connect to server and select databse.
    10 mysql_connect("$host""$username""$password")or die("cannot connect"); 
    11 mysql_select_db("$db_name")or die("cannot select DB");
    12 
    13 $myusername1 
    $_POST['myusername1'];
    14 $mypassword1 $_POST['mypassword1'];
    15 $mymail $_POST['mymail'];
    16 $D1 $_POST['D1'];
    17 
    18 
    //insert the values
    19 $mysql_query "INSERT INTO `MainT` VALUES (\'\',\'$myusername1\',\'$mypassword1\',\'$mymail\',\'D1\',\'1000\',\'1\',\'0\',\'0\',\'0\',\'0\',\'0 \',\'0\',\'0\',\'0\',\'20\',\'5000\')";
    20 echo "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=index.php>Click here to login</a><br></font>";
    21
    22 
    echo "Your name and password have been submitted into our database :)";
    23 ob_end_flush();
    24 ?>
    I dont get any errors but does show the "Welcome, You have successfully signed up"but doesnt add the data and i know it does connect successfully because i can login with data that is already on my db any help would be great.
    Last edited by 2y2d; 08-10-2007 at 12:46 AM.

  • #2
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Looks like you're missing the function call to actually execute the query you constructed. Try:

    PHP Code:
    mysql_query($mysql_query); 
    Also, you don't need to escape the single quotes in your query, since you've got double quotes around the entire text.

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SteveBach View Post
    Looks like you're missing the function call to actually execute the query you constructed. Try:

    PHP Code:
    mysql_query($mysql_query); 
    Also, you don't need to escape the single quotes in your query, since you've got double quotes around the entire text.
    that goes in line 20 yer ? If so its still not working, would it be the single quotes ?

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    An Update - i added ("Add Error") so i would know if the error was before or after, I was wondering if it could be the data "D1" as this is a drop down menu and i dont think its coded right so this might be adding an invalid data type or wouldnt that matter ?

    PHP Code:
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    $myusername1 = $_POST['myusername'];
    $mypassword1 = $_POST['mypassword'];
    $mymail = $_POST['mymail'];
    $D1 = $_POST['D1'];

    <?php
    $mysql_query 
    "INSERT INTO MainT VALUES = (\'\',\'$myusername\',\'$mypassword\',\'$mymail\',\'D1\',\'1000\',\'1\',\'0\',\'0\',\'0\',\'0\',\'0\',\'0\',\'0\',\'0\',\'20\',\'5000\',\'0\',\'0\',\'0\')";
    mysql_query($mysql_query)or die("Add Error");
    echo 
    "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=index.php>Click here to login</a><br></font>";

    echo 
    "Your name and password have been submitted into our database :)";
    ob_end_flush();
    ?>

  • #5
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try changing your query so that you dont escape the single quotes as follows:
    PHP Code:
    $mysql_query "INSERT INTO MainT VALUES = ('',$myusername,$mypassword,$mymail,'D1','1000','1','0','0','0','0','0','0','0','0','20','5000','0','0','0')"
    Also is D1 meant to be a variable, if so in the insert you have missed the $ before it, as is it will just use D1 as the value which i assume you do not want therefore should be as follows:
    PHP Code:
    $mysql_query "INSERT INTO MainT VALUES = ('',$myusername,$mypassword,$mymail,$D1,'1000','1','0','0','0','0','0','0','0','0','20','5000','0','0','0')"
    Last point, just wondering, are you using the object buffer for a reason?
    Last edited by anarchy3200; 08-10-2007 at 09:19 PM.
    Mike

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by anarchy3200 View Post

    Last point, just wondering, are you using the object buffer for a reason?
    I used the Object Buffer because it said somewhere on another site that it was best to use it when using php5 (to be honest i dont know what the object buffer does) should i not use it ?

    Still doesnt work lol
    Last edited by 2y2d; 08-10-2007 at 09:35 PM.

  • #7
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    You can try setting it up differently like this

    $query = doquery("INSERT INTO {{table}} SET id='',regdate=NOW(),verify='1',username='$username',password='$password',mymail='$mymail',d1='$d1',n ame='$name',gender='$gender',country='$country',msn='$msn',aim='$aim',yim='$yim',icq='$icq'", "MainT") or die(mysql_error());

  • #8
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thats more confusing lol so in that one it defines as it adds ? :S
    can i not change my $mysql_query to the doquery ? lol im totally lost and probably talking rubbish now :S lol
    ill give it a go anyway ill just copy what ive got to a notepad first, anything is better than not rying lol ill keep you posted if it works

    =
    Fatal error: Call to undefined function: doquery()
    Last edited by 2y2d; 08-10-2007 at 09:57 PM.

  • #9
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    You will have to set it with your own strings and all. But that line updates the user in that table.

  • #10
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by masterofollies View Post
    You will have to set it with your own strings and all. But that line updates the user in that table.
    What do i define it as ? the error says - Fatal error: Call to undefined function: doquery()

  • #11
    New Coder
    Join Date
    Apr 2007
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:
    PHP Code:
    $mysql_query "INSERT INTO MainT VALUES = ('','$myusername','$mypassword','$mymail','$D1','1000','1','0','0','0','0','0','0','0','0','20','5000','0','0','0')";
    mysql_query($mysql_query); 

  • #12
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by argothian View Post
    Try this:
    PHP Code:
    $mysql_query "INSERT INTO MainT VALUES = ('','$myusername','$mypassword','$mymail','$D1','1000','1','0','0','0','0','0','0','0','0','20','5000','0','0','0')";
    mysql_query($mysql_query); 
    Nope didnt work either i cant see anything wrong with it though all my sql login details are fine, everything is defined that needs to be, ive got every column covered in the query :S its weird.
    Is there any other way of adding data to my table ?

  • #13
    New Coder
    Join Date
    Apr 2007
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heh, I looked a bit closer at the statement, there's a stray =, try this:
    PHP Code:
    $mysql_query "INSERT INTO MainT VALUES ('','$myusername','$mypassword','$mymail','$D1','1000','1','0','0','0','0','0','0','0','0','20','5000','0','0','0')"
    mysql_query($mysql_query); 
    If it still doesn't add the entry add this line to get the error:
    PHP Code:
    echo mysql_error(); 

  • #14
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by argothian View Post
    Heh, I looked a bit closer at the statement, there's a stray =, try this:
    PHP Code:
    $mysql_query "INSERT INTO MainT VALUES ('','$myusername','$mypassword','$mymail','$D1','1000','1','0','0','0','0','0','0','0','0','20','5000','0','0','0')"
    mysql_query($mysql_query); 
    If it still doesn't add the entry add this line to get the error:
    PHP Code:
    echo mysql_error(); 
    After 4 long days of looking at the same little bit of code its now sorted lol thank you very much.
    All help is greatly appreciated


  •  

    Posting Permissions

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