I'm trying to add entries to my MySQL database using php and entry fields to add edit and change values inside of my MySQL database. for some reason it isn't erroring out but it isn't posting it either. help O.o
I'm trying to add entries to my MySQL database using php and entry fields to add edit and change values inside of my MySQL database. for some reason it isn't erroring out but it isn't posting it either. help O.o
Hello,
This is not the right section to post this request. Free Hosting forum is for support related to hosting account issues.
***Moved to Programming help***
Last edited by Zubair; 08-06-2011 at 03:34 PM.
█ Zubair Barkat | Level 2 Tech
█ 888-X10-9668 - zubair[@]x10hosting.com
█ x10Hosting - Giving Away Hosting Since 2004
If you post the code (use ****** for passwords, etc) it might be easier to suggest a solution. Please post the code between PHP or CODE tags.
Nothing is always absolutely so.
Just make sure you don't dump the entirety of your code. A code sample should be complete yet concise and representative of the actual code.
Also, no need to shout in the thread title or elsewhere. It conveys no useful information.
Last edited by misson; 08-06-2011 at 05:26 PM.
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
added.php
ASCII English text
<a href="index.php">Back to List</a>
<?php
/// In order to use this script freely
/// you must leave the following copyright
/// information in this file:
/// Copyright 2006 www.turningturnip.co.uk
/// All rights reserved.
include("connect.php");
$clan = trim($_POST['clan']);
$a = trim($_POST['a']);
$b = trim($_POST['b']);
$c = trim($_POST['c']);
$d = trim($_POST['d']);
$e = trim($_POST['e']);
$f = trim($_POST['f']);
$g = trim($_POST['g']);
$h = trim($_POST['h']);
$j = trim($_POST['j']);
$k = trim($_POST['k']);
$l = trim($_POST['l']);
$m = trim($_POST['m']);
$n = trim($_POST['n']);
$o = trim($_POST['o']);
$p = trim($_POST['p']);
$q = trim($_POST['q']);
$r = trim($_POST['r']);
$s = trim($_POST['s']);
$t = trim($_POST['t']);
$query = "INSERT INTO vita (id, clan, a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s, t)
VALUES ('', '$clan', '$a', '$b', '$c', '$d', '$e', '$f', '$g', '$h', '$j', '$k', '$l', '$m', '$n', '$o', '$p', '$q', '$r', '$s', '$t')";
$results = mysql_query($query);
if ($results)
{
echo "Details added.";
}
mysql_close();
?>
and here is my connect.php
<?php
/// For the following details,
/// please contact your server vendor
$hostname='localhost'; //// specify host, i.e. 'localhost'
$user='th3dj_admin'; //// specify username
$pass='******'; //// specify password
$dbase='th3dj_hud'; //// specify database name
$connection = mysql_connect("$hostname" , "$user" , "$pass")
or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");
Please use [php], [html] or [code] tags (as appropriate) to separate and format code.
The sample code is vulnerable to SQL injection, which is a very serious security risk. To fix this hole, switch from the outdated mysql extension to PDO and use prepared statements. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO". The site you save may just be your own.
Don't use die when outputting HTML.
Globals are bad. Your DB connection script should provide functions or (better yet) a class to manage the DB connection and segregate the credentials. You can use static variables and properties to store the connection so subsequent calls to the connect function don't have to recreate it. See "Display all that would be secret while Mysql is broken" and "[PHP] MySQL and PHP" for some illustrative examples.
When you say "it isn't erroring out but it isn't posting it either", do you mean you don't see "Details added." in the output? If $results is false, does the actual script fetch the database error (with the outdated mysql extension, you'd use mysql_error)? If not, get it an tell us what it is. A script won't output database errors on its own (unless you're using a DB extension that uses exceptions and don't catch the exception, but that's not so much due to the database error as it is the exception). Note that scripts should show database error messages only admins.
Are the single-character column names just for the sample, or is that what you use in your actual database?
Last edited by misson; 08-07-2011 at 02:33 PM.
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
pdo sounds like a much easier way to actually do what i need it to..... i think that might be able to get it all set up for me and everything. ill read thru it and find out. i might actually try to do the whole thing considering that mostly what i need it to do is read from the database and display the results so they can be parsed for a game that i play...