Author Topic: Data wont push  (Read 116 times)

alvinareed

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Data wont push
« on: February 02, 2012, 02:38:03 PM »
I have a form when I enter the information it wont post to the database.

PHP Code: [Select]

<?php
$hostname
="myelstonfamily.db.#######.hostedresource.com";
$dbuser="myelstonfamily";
$pass="password";
$username =$_POST['username'];
$adultfees =$_POST['adultfees'];
$youthfees =$_POST['youthfees'];
$childrenfees =$_POST['childrenfees'];
$tyouthsmall =$_POST['tyouthsmall'];
$tyouthmedium =$_POST['tyouthmedium'];
$tyouthlarge =$_POST['tyouthlarge'];
$tadultsmall =$_POST['tadultsmall'];
$tadultmedium =$_POST['tadultmedium'];
$tadultlarge =$_POST['tadultlarge'];
$tadultxl =$_POST['tadultxl'];
$tadult2xl =$_POST['tadult2xl'];
$tadult3xl =$_POST['tadult3xl'];


$link mysql_connect($hostname,$dbuser$pass);
$db_selected mysql_select_db('myelstonfamily'$link);
if (!
$db_selected) {
    die (
'Can\'t use foo : ' mysql_error());
}
 else

mysql_query ("INSERT INTO 2012 (username, adultfees, youthfees, childrenfees, tyouthsmall, tyouthmedium, tyouthlarge, tadultsmall, tadultmedium, tadultlarge, tadultxl, tadult2xl, tadult3xl) VALUES('$adultfees','$youthfees','$childrenfees','$tyouthsmall','$tyouthmedium','$tyouthlarge','$tadultsmall','$tadultmedium','$tadultlarge','$tadultxl','$tadult2xl','$tadult3xl')");
}
mysql_close($link);
?>




jj-dr

  • Senior Member
  • ****
  • Posts: 207
  • Karma: +3/-0
    • View Profile
Re: Data wont push
« Reply #1 on: February 02, 2012, 03:36:44 PM »
you should always post your error message, someone can help you.

I see a problem with your insert structure:

PHP Code: [Select]
 else

mysql_query ("INSERT INTO 2012 (username, adultfees, youthfees, childrenfees, tyouthsmall, tyouthmedium, tyouthlarge, tadultsmall, tadultmedium, tadultlarge, tadultxl, tadult2xl, tadult3xl) VALUES('$adultfees','$youthfees','$childrenfees','$tyouthsmall','$tyouthmedium','$tyouthlarge','$tadultsmall','$tadultmedium','$tadultlarge','$tadultxl','$tadult2xl','$tadult3xl')");
}
mysql_close($link);
?>


The correct structure is
PHP Code: [Select]
INSERT INTO 212 VALUES (value1value2value3,...) 

But a more comprehensive way would be something like this:

PHP Code: [Select]
$query mysql_query("INSERT INTO content SET id = null, title='$postTitle', author ='$postAuthor', body_text ='$postContent',  linklabel = '$postLinkLabel' ") or die (mysql_error());

This latter example is more human friendly to read. I think you main issue has to do with the use of parenthesis inside parenthesis. This example avoids that.
« Last Edit: February 02, 2012, 04:01:07 PM by jj-dr »

Smokey PHP

  • Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 529
  • Karma: +5/-0
    • View Profile
Re: Data wont push
« Reply #2 on: February 02, 2012, 04:21:21 PM »
The structure of your query is fine in terms of specifying the fields you are inserting into, you are simply missing the $username value. Add that and you should be fine, if not change your code to this, and post the result.

PHP Code: [Select]
$result mysql_query("INSERT INTO 2012 (username,adultfees,youthfees......");//etc
if($result === false) echo 'Mysql Error: '.mysql_error();