Jump to content


Photo

PHP & SQL wont insert into MYSQL at first?


  • Please log in to reply
8 replies to this topic

#1 Vini

Vini
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 01 March 2006 - 03:13 PM

Im testing new codes/scripts. and ive had this problem before, but it just started working without intervention i think... but why is it that when i try and write to a DB in mysql does it never work - first time up.

ive walked through [a href=\"http://www.thescripts.com/serversidescripting/php/tutorials/developaphpuserpersonalizationsystem/index.html\" target=\"_blank\"]this[/a] and tried to register, and it says:

You have successfully registered with:

Username: 
Password:

after username you would expect it to Echo the username ive registered, and password the same. but nothing, and it hasnt written to the DB...

this has puzzled me before, but i ignored it... but its back again.. why?

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 01 March 2006 - 03:57 PM

sounds like you have an error in 1 of your querys.. after each query use this OR die('$result'.mysql_error());

so if you have
$result=mysql_query($query);

change it to
$result=mysql_query($query) OR die('$result'.mysql_error());

Just use this as diagnosis so change die('$result'.mysql_error()); to die('$result2'.mysql_error()); for the second set or results and so on then yopu will know at which query the error is..
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Vini

Vini
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 01 March 2006 - 04:28 PM

Hi mate,

Not quite sure where i'd put 'OR die('$result'.mysql_error());' in my 3 php sctips?

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 01 March 2006 - 04:39 PM

just paste the scripts here then and we will have a look thru them for you mate :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 Vini

Vini
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 01 March 2006 - 05:00 PM

[!--quoteo(post=350673:date=Mar 1 2006, 11:39 AM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Mar 1 2006, 11:39 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
just paste the scripts here then and we will have a look thru them for you mate :)
[/quote]

they can be grabbed all together in a rar -> [a href=\"http://www.vini.co.uk/testing/testing.rar\" target=\"_blank\"]here[/a]

or viewed as textualisation files (.txt :D) -> [a href=\"http://www.vini.co.uk/testing\" target=\"_blank\"]here[/a]

#6 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 01 March 2006 - 05:17 PM

I can't view .rar files from work and all your txt files are being parsed at serve rjust like HTML files.. :s copy all you PHP files and call them the filename.phps
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#7 Vini

Vini
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 02 March 2006 - 08:40 AM

[!--quoteo(post=350688:date=Mar 1 2006, 12:17 PM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Mar 1 2006, 12:17 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I can't view .rar files from work and all your txt files are being parsed at serve rjust like HTML files.. :s copy all you PHP files and call them the filename.phps
[/quote]

done :)

#8 Vini

Vini
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 02 March 2006 - 02:13 PM

[!--quoteo(post=350898:date=Mar 2 2006, 03:40 AM:name=Vini)--][div class=\'quotetop\']QUOTE(Vini @ Mar 2 2006, 03:40 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
done :)
[/quote]
ive enabled 'register_globals' and the script works, but i dont want to run with globals on, how would i change the script to work, with globals off?

#9 Vini

Vini
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 02 March 2006 - 02:40 PM

Register.php3

<?php
function showheader ($title) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> <?php echo $title ?> </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<?php
}

function showfooter () {
?>
</CENTER>
</BODY>
</HTML>
<?php
}

mysql_connect("localhost", "root", "");
mysql_select_db("users");

if ($Password == $Password2) {
    $user = mysql_query("SELECT * FROM personalize WHERE (Name='$Name')");
    if (mysql_num_rows($user) > 0) {
        showheader("User Name Taken !");
        ?>
        We are sorry to inform you that the User Name <B><?php echo $Name ?></B> Is already Taken.
        <?php
        showfooter();
    }


    else {

        $user = mysql_query("INSERT INTO personalize VALUES ('$Name','$Password','$News1','$News2','$Weather')");
        setcookie("site_user", $Name, time() + 31536000, "/");
        setcookie("site_pass", $Password, time() + 31536000, "/");
        showheader("Registration Success!");
        ?>
        You have registered.<BR>
        User Name: <?php echo $Name ?>
        <BR>
        Password: <?php echo $Password ?>
        <?php
        showfooter();
    }
}
else {
    showheader("Registration Error!");
    ?>
    Your Two Passwords Did Not Match
    <?php
    showfooter();
}
?>




Edit.php3

<?php
function showheader ($title) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> <?php echo $title ?> </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<?php
}

function showfooter () {
?>
</CENTER>
</BODY>
</HTML>
<?php
}

mysql_connect("localhost", "root", "");
mysql_select_db("users");

if ($action == "edit_two") {

    $user = mysql_query("UPDATE personalize SET Password='$Password',News1='$News1',News2='$News2',Weather='$Weather' WHERE (Name='$Name')");

    setcookie("site_user", $Name, time() + 31536000, "/");
    setcookie("site_pass", $Password, time() + 31536000, "/");

    showheader("Edit Success!");
?>


    You Have Edited Your Profile.<BR>
    User Name: <?php echo $Name ?>
    <BR>
    Password: <?php echo $Password ?>



<?php
    showfooter();
}

else {

$query = mysql_query("SELECT * FROM personalize WHERE(Name='$Name' AND Password='$Password')");

    if (mysql_num_rows($query) != 1) {
        showheader("That User/Pass Combination was Incorrect");
        echo "The $Name / $Password Combination is incorrect<P>Please Try Again.";
        showfooter();
        exit;
    }

    else {
        $info = mysql_fetch_array($query);
        showheader("Edit ".$info['Name']."'s Profile");

?>


<FORM METHOD=POST ACTION="<?php echo $PHP_SELF ?>">

<INPUT TYPE="hidden" NAME="Name" VALUE="<?php echo $info['Name'] ?>">
<INPUT TYPE="hidden" NAME="action" VALUE="edit_two">

<TABLE>
<TR>
    <TD COLSPAN=2><CENTER>Please Select Your Registration Options</CENTER></TD>
</TR>
<TR>
    <TD>Your UserName</TD>
    <TD><?php echo $info['Name'] ?></TD>
</TR>

<TR>
    <TD>Choose Your Password</TD>
    <TD><INPUT TYPE="password" NAME="Password" size="10" VALUE="<?php echo $info['Password'] ?>"></TD>
</TR>

<TR>
    <TD>News Source 1</TD>
    <TD><SELECT NAME="News1">
            <OPTION VALUE="32bitsonline.php3"<?php if ($info['News1'] == "32bitsonline.php3") { echo " SELECTED"; } ?>>32bitsonline</OPTION>
            <OPTION VALUE="freshmeat.php3"<?php if ($info['News1'] == "freshmeat.php3") { echo " SELECTED"; } ?>>Fresh Meat</OPTION>
            <OPTION VALUE="slashdot.php3"<?php if ($info['News1'] == "slashdot.php3") { echo " SELECTED"; } ?>>Slashdot</OPTION>
            <OPTION VALUE="hotwired.php3"<?php if ($info['News1'] == "hotwired.php3") { echo " SELECTED"; } ?>>WebMonkey</OPTION>
            </SELECT>
    </TD>
</TR>

<TR>
    <TD>News Source 2</TD>
    <TD><SELECT NAME="News2">
            <OPTION VALUE="32bitsonline.php3"<?php if ($info['News2'] == "32bitsonline.php3") { echo " SELECTED"; } ?>>32bitsonline</OPTION>
            <OPTION VALUE="freshmeat.php3"<?php if ($info['News2'] == "freshmeat.php3") { echo " SELECTED"; } ?>>Fresh Meat</OPTION>
            <OPTION VALUE="slashdot.php3"<?php if ($info['News2'] == "slashdot.php3") { echo " SELECTED"; } ?>>Slashdot</OPTION>
            <OPTION VALUE="hotwired.php3"<?php if ($info['News2'] == "hotwired.php3") { echo " SELECTED"; } ?>>WebMonkey</OPTION>
            </SELECT>
    </TD>
</TR>
<TR>
    <TD>Weather Source</TD>
    <TD><SELECT NAME="Weather">
            <OPTION VALUE="USNY0996"<?php if ($info['Weather'] == "USNY0996") { echo " SELECTED"; } ?>>New York</OPTION>
            <OPTION VALUE="USCA0987"<?php if ($info['Weather'] == "USCA0987") { echo " SELECTED"; } ?>>San Francisco</OPTION>
            <OPTION VALUE="CAXX0504"<?php if ($info['Weather'] == "CAXX0504") { echo " SELECTED"; } ?>>Toronto</OPTION>
            </SELECT>
    </TD>
</TR>
<TR><TD COLSPAN=2><CENTER><INPUT TYPE="submit" Value="Edit Profile!"></CENTER></TD></TR>
</TABLE>
</FORM>


<?php
    showfooter();
    }
}
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users