MySQL and php problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KarSec
Forum Newbie
Posts: 4
Joined: Mon Apr 05, 2004 11:23 pm

MySQL and php problem

Post by KarSec »

Hello, I really need help, I was all day trying to figure it out about a php code not working and, now that I finaly know where is the error, I have no idea why is happening!!, please help.

well I am using an mysql_query($mysql_sentence) to insert a value on a table, the thing worked, but when I saw in phpmyadmin, there were to columns instead of one, the first one with the value I wanted and the second one empty. aftyer serching where the error was, it wasn't at all in the php code, it was on the <style> code before I even started all the php code. here I post all that is making the error, becouse when I take thisaout of my code everything works just fine. I have no idea what has this to do with the php or mysql code, but somehow is messing the thing up.

<!--

BODY
{
scrollbar-base-color: 386898;
scrollbar-arrow-color: FFFFFF;
FONT-FAMILY: Verdana, Arial, Helvetica;
font-size: 12px;
background-color: #204080;
background-image: url("");
}
A:link
{
TEXT-DECORATION: none;
color: 00ff00;
}
A:visited { TEXT-DECORATION: none; color: 00ff00 }
A:active { TEXT-DECORATION: none; color: 00ff00 }
A:hover { TEXT-DECORATION: none; color: red}


.texto
{
color: #444444;
font-family: Verdana, Arial, Helvetica;
font-size: 12px;
}

.tabla_boton
{
background-color: #386898;
color: #ffffff;
border-bottom: #223F5A 1px outset;
border-left: #528BC0 1px outset;
border-right: #223F5A 1px outset;
border-top: #528BC0 1px outset;
font-family: verdana, tahoma, arial;
font-size: 12px;
height: 20px;
font-weight: bold;
cursor: pointer;
}
//-->


I will aprecciate any help
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

Post by bluenote »

May it helps if you post the whole script so that i can see the PHP/DBstuff and its interaction with your css commands.

Greez,
- bluenote
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please don't cross-post - I have deleted the second instance of this topic.

Mac
KarSec
Forum Newbie
Posts: 4
Joined: Mon Apr 05, 2004 11:23 pm

Post by KarSec »

Hi me again,

to bluenote or anyone willing to help please go to this site,

http://akarelov.myserver.org/~medievo/web/

and you will se a copy of all the code in .txt format.

the program start with juego1.php (that in that site is called juego1.txt)

well, hope you help me I will thank for any help!!
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

Post by bluenote »

Hi KarSec,

i have visited the page, but instead of seeing the textfile i got a login screen. Please post the script which has not worked in combination with your style sheets here.

Normally, style sheets can only mess up the browser output but not disturb the PHP scripting action. If you got two db entries by one insert action, and one of them is empty, it sounds more like that the insert query is somehow executed twice - the second time without the vars from your form or whatever.

Have you got any redirect - feutures in your script or can anyone hit the back button?

To control if the insert query works really without errors, you could add

Code: Select all

<?php

= mysql_query($uquery) or die(mysql_error());
?>
to your script.

Greez,
- bluenote
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

Post by bluenote »

Hi,

i worked out how to get yout files...

If i am right, this one is the form which sends the vars to the insert query (registrarse.txt):

Code: Select all

<?php
<form method="POST" action="registrarse2.php">

Nickname: <input type="text"     name="nick"><br>

Password: <input type="password" name="pass"><br>

          <input type="submit"   value="REGISTRAR">

</form>
?>
And this one IS the insert query (registrarse2.txt):

Code: Select all

<?php
$nick = $_POST['nick'];
$pass = $_POST['pass'];

//asigna y las agrega a mysql

mysql_connect($SERVIDOR, $USER_ADMIN, $PASS_ADMIN);

// Abrimos la Base de datos de usuarios

mysql_select_db($BD_USUARIOS);

echo $BD_USUARIOS;
// le damos el nick y el pass
$sr = "INSERT INTO usuarios ( nickname , password ) VALUES ('$nick', '$pass')";

// Subimos los valores a la Base de datos "usuarios"

mysql_query("INSERT INTO usuarios ( nickname , password ) VALUES ('$nick', '$pass')");
?>
Assuming that your db connection (Host, Username, Pass etc.) is working, what is insert_query 1 and what is insert_query 2?

Just try and replace the whole thing

Code: Select all

<?php
$sr = "INSERT INTO usuarios ( nickname , password ) VALUES ('$nick', '$pass')";

// Subimos los valores a la Base de datos "usuarios"

mysql_query("INSERT INTO usuarios ( nickname , password ) VALUES ('$nick', '$pass')");
?>
with this:

Code: Select all

<?php
$query = "INSERT into usuarios (nickname, password)";
																																													
$query = $query."VALUES('$nick', '$pass')";
																																													
$erg = mysql_query($query) or die(mysql_error());
?>
Should work.

Greez,
- bluenote
KarSec
Forum Newbie
Posts: 4
Joined: Mon Apr 05, 2004 11:23 pm

Post by KarSec »

Hi, fist of all thank for helping me so much.

this code:

Code: Select all

<?php

$sr = "INSERT INTO usuarios ( nickname , password ) VALUES ('$nick', '$pass')";

// Subimos los valores a la Base de datos "usuarios"

mysql_query("INSERT INTO usuarios ( nickname , password ) VALUES ('$nick', '$pass')");

?>
whas actually a mistake, at first it was like this:

Code: Select all

<?php

$sr = "INSERT INTO usuarios ( nickname , password ) VALUES ('$nick', '$pass')";

// Subimos los valores a la Base de datos "usuarios"

mysql_query($sr);

?>
but then I changed it to see if it would work with the code before, well it didn't with both, your code is actually similar to this one, and it didn't worked either. i really have no idea what is wrong.

try to work the program by yourself and you will see that the code actually works, but some how it makes it 2 times instead of one, and the second value on the table will be empty!.

thanks a lot.

PD: why couldn't you enter to the site at first??
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

Post by bluenote »

Hi,

I did not check your code by running it, I just saw the query lines ... does the table 'usuarios' only consist of those two fields?

If so, i can fire it up to let your scripts run and tell you what's wrong. If not, please post the table structure.

Greez,
- bluenote
KarSec
Forum Newbie
Posts: 4
Joined: Mon Apr 05, 2004 11:23 pm

Post by KarSec »

yes it does.

farewell, and good luck
KarSec
Post Reply