PHP - MySQL

olliepop

Member
Messages
138
Reaction score
0
Points
16
Hi, i am very experienced with PHP and MySQL. I am not a newb or anything, but with this script i seriously do not know what's wrong!

Here is the entire page code, except for of course the mysql db name, username and password.

Click here for the CODE of the page

Please help me with this!

I haven't included the code here because it would just make the post very long.
 
Last edited:

Myokram

New Member
Messages
30
Reaction score
0
Points
0
Perhaps it would be easier if you just tell what's the problem with that script. Does it display an error message? What it says?
 

xmakina

New Member
Messages
264
Reaction score
0
Points
0
Might I recommend you make the same file with .php as well so we can see the code and the results?
 

dickey

New Member
Messages
128
Reaction score
0
Points
0
Basically if there be errors check syntax first.

then
Code:
  if($_POST['step']=="1") {
    $form="2";
  } elseif($_POST['step']=="2") {
    $form="2";
  }

is confusing or it might be wrong. or it might be part of your logic.

another point is maybe you should initialize the variable '$form' as some php installations tend to give out errors if using an improperly initialized variable.

but then again your problem might not be your code if you are having problems connecting mysql.... then maybe it is your php version in x10hosting where (i'm not sure but...) I think they disable mysql in the basic version. try to upgrade to intermediate version.

if not maybe give more details as to what the problem is?
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Code:
  if($_POST['step']=="1") {
    $form="2";
  } elseif($_POST['step']=="2") {
    $form="2";
  }

I suspect that this should be

Code:
  if($_POST['step']=="1") {
    $form="1";
  } elseif($_POST['step']=="2") {
    $form="2";
  }
 

olliepop

Member
Messages
138
Reaction score
0
Points
16
There are no errors, everything runs fine. The only problem is that when it comes to adding the information into the database the information isn't actually inserted.

I can't seem to find out whats wrong.. its so weird!

Ok, the .php file is http://www.olliepop.x10hosting.com/mmo/add_db.php
Edit:
Sorry for dub but the problem, i believe, is here:

PHP:
if($_POST['table']!=NULL || $_POST['table']!="") {
mysql_select_db("REMOVED_FOR_SECRUITY_ISSUES", $con);
mysql_query("INSERT INTO ".$_POST['table']." (".$_POST['c1'].", ".$_POST['c2'].", ".$_POST['c3'].", ".$_POST['c4'].", ".$_POST['c5'].", ".$_POST['c6'].", ".$_POST['c7'].", ".$_POST['c8'].", ".$_POST['c9'].", ".$_POST['c10'].") 
VALUES ('".$_POST['r1']."', '".$_POST['r2']."', '".$_POST['r3']."', '".$_POST['r4']."', '".$_POST['r5']."', '".$_POST['r6']."', '".$_POST['r7']."', '".$_POST['r8']."', '".$_POST['r9']."', '".$_POST['r10']."')");
$works="1";
echo "Inserted values into database successfully!";
}
:dunno:
 
Last edited:

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
I doubt it will do anything but might as well have a look.
Shouldn't
if($_POST['table']!=NULL || $_POST['table']!="") {
be
if($_POST['table']!=NULL && $_POST['table']!="") {

And this one
if($n!="" || $n!=NULL) {
does not seem necessary since after it you ask if it equals 1, 2, 3, etc. Otherwise you may want to consider replacing || with &&.

I doubt it will, but I hope that helps; I can't see anything else.
 

olliepop

Member
Messages
138
Reaction score
0
Points
16
Thanks! But unfortunately it didn't help..
I wonder if that, when you enter only a value to insert into a new row, but the table has more than columns than values you entered, it won't create..
For example:
There are two columns, id and name.
Then you enter only one value, 10, to insert into a NEW row.
Will is still create? even if name is null
 

natsuki

New Member
Messages
112
Reaction score
0
Points
0
i'm not quite sure if php automatically converts a null into sql NULL, if not then that could be a problem..
try
PHP:
mysql_query("INSERT INTO ".$_POST['table']." (".$_POST['c1'].", ".$_POST['c2'].", ".$_POST['c3'].", ".$_POST['c4'].", ".$_POST['c5'].", ".$_POST['c6'].", ".$_POST['c7'].", ".$_POST['c8'].", ".$_POST['c9'].", ".$_POST['c10'].") 
VALUES ('".$_POST['r1']."', '".$_POST['r2']."', '".$_POST['r3']."', '".$_POST['r4']."', '".$_POST['r5']."', '".$_POST['r6']."', '".$_POST['r7']."', '".$_POST['r8']."', '".$_POST['r9']."', '".$_POST['r10']."')");
if (mysql_errno($con))
{
    die('Query failed: ' . mysql_error($con));
}
$works="1";
echo "Inserted values into database successfully!";
}
to see what actually went wrong
 

xmakina

New Member
Messages
264
Reaction score
0
Points
0
PHP:
 if($_POST['table']!=NULL || $_POST['table']!="") {
mysql_select_db("REMOVED_FOR_SECRUITY_ISSUES", $con);
$result = mysql_query("INSERT INTO ".$_POST['table']." (".$_POST['c1'].", ".$_POST['c2'].", ".$_POST['c3'].", ".$_POST['c4'].", ".$_POST['c5'].", ".$_POST['c6'].", ".$_POST['c7'].", ".$_POST['c8'].", ".$_POST['c9'].", ".$_POST['c10'].") 
VALUES ('".$_POST['r1']."', '".$_POST['r2']."', '".$_POST['r3']."', '".$_POST['r4']."', '".$_POST['r5']."', '".$_POST['r6']."', '".$_POST['r7']."', '".$_POST['r8']."', '".$_POST['r9']."', '".$_POST['r10']."')");

if(!$result){
die("Oh god!");
}
$works="1";
echo "Inserted values into database successfully!";
}

This is how I catch SQL errors throughout my own site.
 

dickey

New Member
Messages
128
Reaction score
0
Points
0
first suggestion is to put your query in a string variable, then try to echo it, from there you can see if your query is what it should be.if not you can try to correct it.

I do this as sometimes doing this:
Code:
$result = mysql_query("INSERT INTO ".$_POST['table']." (".$_POST['c1'].", ".$_POST['c2'].", ".$_POST['c3'].", ".$_POST['c4'].", ".$_POST['c5'].", ".$_POST['c6'].", ".$_POST['c7'].", ".$_POST['c8'].", ".$_POST['c9'].", ".$_POST['c10'].") 
VALUES ('".$_POST['r1']."', '".$_POST['r2']."', '".$_POST['r3']."', '".$_POST['r4']."', '".$_POST['r5']."', '".$_POST['r6']."', '".$_POST['r7']."', '".$_POST['r8']."', '".$_POST['r9']."', '".$_POST['r10']."')");
can easily make you miss out on syntax.
 

olliepop

Member
Messages
138
Reaction score
0
Points
16
i'm not quite sure if php automatically converts a null into sql NULL, if not then that could be a problem..

You were absolutely right!

Connected to database server.
Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' , , , , , , , ) VALUES ('10', '', '', '', '', '', '', '', '', '')' at line 1

Does anybody know what i can do to rectify this problem?
Or should i just do it the old fashioned way?

PHP:
if($_POST['1']=="" || $_POST['1']==NULL) {
QUERY HERE
} elseif(...) {
...
}

Oh god that will painful.
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Instead of
Code:
if($_POST['1']=="" || $_POST['1']==NULL) { 
QUERY HERE 
} elseif(...) { 
... 
}
you could use something like this (highly simplified):
Code:
$bla = 1;
while ($bla <= $max_bla) {
  if($_POST[$bla]=="" || $_POST[$bla]==NULL) { 
    $bla1 = "something";
    $bla++;
  }
}
// Then create query using what you previously had
// but with the $bla# instead of POSTS.
To be honest I don't even know what the original problem actually was because I didn't understand how you're using it, but if nobody can solve your problem better, this will at least facilitate the fix you proposed.
 
Top