Jump to content

Archived

This topic is now archived and is closed to further replies.

alarik149

what is wrong with this script pls tell me

Recommended Posts

<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

Share this post


Link to post
Share on other sites
[!--quoteo(post=352231:date=Mar 6 2006, 04:34 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 04:34 PM) [snapback]352231[/snapback][/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?

Share this post


Link to post
Share on other sites
You have put dbl quotations in unecessary places try:

[code]<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>[/code]

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.

Share this post


Link to post
Share on other sites
Also try adding in mysql_error();

[code]
if ($result) {

   echo 'Success';

} else {

    die(mysql_error());

}
[/code]

Share this post


Link to post
Share on other sites
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:(

Share this post


Link to post
Share on other sites
There is no need for that code he has already put that in:

[code]@ $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 !"; }[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Did You try removing the double qoutations so yr sql now looks like:

[code]$query="insert into register values ('$username','$username','$status')";[/code]

Ah yes so he has, my mistake Gaia

Share this post


Link to post
Share on other sites
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:(

Share this post


Link to post
Share on other sites
[!--quoteo(post=352257:date=Mar 6 2006, 05:01 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 05:01 PM) [snapback]352257[/snapback][/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?)

Share this post


Link to post
Share on other sites
It could also be something wrong with your $db->query class, unless you've successfully ran queries with this script before.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
are you running php5? do you have mysqli enabled? Here is an alternative way of connecting to the db:

[code]//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.");[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=352267:date=Mar 6 2006, 05:09 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 05:09 PM) [snapback]352267[/snapback][/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() ...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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) [snapback]352284[/snapback][/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)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.