Jump to content


Photo

what is wrong with this script pls tell me


  • Please log in to reply
16 replies to this topic

#1 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 06 March 2006 - 09:34 PM

<html>
<head>
</head>
<body>
<?php
$username=$_POST['username'];
$status=$_POST['status'];
if(!$status || !$username) echo "enter data";
if(get_magic_quotes_gpc()) {
$username=addslashes($username);
$status=addslashes($status);
}

@ $db=new mysqli('host','championships','passwd','championships');
if(mysqli_connect_errno()) { echo "could not connect"; }
$query="insert into register values ('".$username."','".$username."','".$status."')";
$result=$db->query($query);
if($result) { echo "success !"; }
$db->close();
?>
</body>
</html>


that is the script.i get $username and $status from an external html script,that is not the problem.the problem is here.let`s consider the connection to the databse is done good,,what can be the problem?i get no errors,just a blank page when the script runs and no information is added 2 the database.
the database name is championships and the table name is register.
HELP GUYS:( PLEASE
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#2 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 06 March 2006 - 09:42 PM

[!--quoteo(post=352231:date=Mar 6 2006, 04:34 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 04:34 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$query="insert into register values ('".$username."','".$username."','".$status."')";

that is the script.i get $username and $status from an external html script,that is not the problem.the problem is here.let`s consider the connection to the databse is done good,,what can be the problem?i get no errors,just a blank page when the script runs and no information is added 2 the database.
the database name is championships and the table name is register.
HELP GUYS:( PLEASE
[/quote]

Well, your logic says not to print anything if there's a problem.. :)

Try adding a print statement and take a look at the query.. Maybe there's a query problem?
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#3 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 06 March 2006 - 09:42 PM

You have put dbl quotations in unecessary places try:

<html>
<head>
</head>
<body>
<?php
$username=$_POST['username'];
$status=$_POST['status'];
if(!$status || !$username) echo "enter data";
if(get_magic_quotes_gpc()) {
$username=addslashes($username);
$status=addslashes($status);
}

@ $db=new mysqli('host','championships','passwd','championships');
if(mysqli_connect_errno()) { echo "could not connect"; }
$query="insert into register values ('$username','$username','$status')";
$result=$db->query($query);
if($result) { echo "success !"; }
$db->close();
?>
</body>
</html>

Also did you know you are entering the username into the db twice? I dont know if you have two rows or if this is a mistake.

#4 Gaia

Gaia
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationCanada

Posted 06 March 2006 - 09:44 PM

Also try adding in mysql_error();

if ($result) {

   echo 'Success';

} else {

    die(mysql_error());

}


#5 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 06 March 2006 - 09:48 PM

i know i`m entering it 2 times...and the values from the html for $username and $status are coming good...something else is the problem:(
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#6 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 06 March 2006 - 09:48 PM

There is no need for that code he has already put that in:

@ $db=new mysqli('host','championships','passwd','championships');
if(mysqli_connect_errno()) { echo "could not connect"; }
$query="insert into register values ('".$username."','".$username."','".$status."')";
$result=$db->query($query);
if($result) { echo "success !"; }


#7 Gaia

Gaia
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationCanada

Posted 06 March 2006 - 09:50 PM

He just has it so that when the database does not connect it will display an error, not when the query is ran..unless i'm missing something.

#8 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 06 March 2006 - 09:53 PM

Did You try removing the double qoutations so yr sql now looks like:

$query="insert into register values ('$username','$username','$status')";

Ah yes so he has, my mistake Gaia

#9 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 06 March 2006 - 10:01 PM

i`ve added
if ($result) {

echo 'Success';

} else {

die(mysql_error());

}
still i don`t get anything,no success nor nothing.if I echo anything after
@ $db=new mysqli(host','championships','passwd','championships');
it dosen`t appear,if I echoed anywhere before that statement it works.something is here I think:(
guys tell me the exact way to make another connection:(
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#10 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 06 March 2006 - 10:04 PM

[!--quoteo(post=352257:date=Mar 6 2006, 05:01 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 05:01 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
still i don`t get anything,no success nor nothing.if I echo anything after
@ $db=new mysqli(host','championships','passwd','championships');
it dosen`t appear,if I echoed anywhere before that statement it works.something is here I think:(
guys tell me the exact way to make another connection:(
[/quote]

Check your error log... I'm betting that @ symbol has something to do with it.. (Why is it there?)
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#11 Gaia

Gaia
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationCanada

Posted 06 March 2006 - 10:04 PM

It could also be something wrong with your $db->query class, unless you've successfully ran queries with this script before.

#12 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 06 March 2006 - 10:09 PM

I removed the @ and i run the script and i get this error :
Fatal error: Cannot instantiate non-existent class: mysqli in /home/content/n/o/l/nolimit3/html/register.php on line 16
on line 16 is $db=new mysqli('host,'championships','passwd','championships');
it stucks here.if i echoed anything after it still dosen`t show.
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#13 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 06 March 2006 - 10:13 PM

are you running php5? do you have mysqli enabled? Here is an alternative way of connecting to the db:

//Create short variable names
$host = 'host';
$db_username = 'username';
$db_password = 'password;
$database = 'database';

//Create connection
$connection = mysql_pconnect("$host","$db_username","$db_password")
          or die ("Couldn't connect to server.");

//Select database
$db = mysql_select_db("$database", $connection)
      or die("Couldn't select database.");


#14 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 06 March 2006 - 10:15 PM

[!--quoteo(post=352267:date=Mar 6 2006, 05:09 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 05:09 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I removed the @ and i run the script and i get this error :
Fatal error: Cannot instantiate non-existent class: mysqli in /home/content/n/o/l/nolimit3/html/register.php on line 16
on line 16 is $db=new mysqli('host,'championships','passwd','championships');
it stucks here.if i echoed anything after it still dosen`t show.
[/quote]

Do you have PHP 5 ? Sounds like whatever version you do have doesn't support mysqli() ...
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#15 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 06 March 2006 - 10:19 PM

yes it`s 5 :(
how can i bypass mysqli() ?
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#16 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 06 March 2006 - 10:22 PM

You could either enable mysqli() in your php.ini (it is disabled by default) by removing the colon in front if it. or try connecting using the method i posted earlier.

#17 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 06 March 2006 - 10:24 PM

[!--quoteo(post=352284:date=Mar 6 2006, 05:22 PM:name=php_b34st)--][div class=\'quotetop\']QUOTE(php_b34st @ Mar 6 2006, 05:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You could either enable mysqli() in your php.ini (it is disabled by default) by removing the colon in front if it. or try connecting using the method i posted earlier.
[/quote]

Make sure you restart apache after editing php.ini... (assuming you're using apache)
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users