Jump to content

PHP & SQL wont insert into MYSQL at first?


Vini

Recommended Posts

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:

[code]You have successfully registered with:

Username:
Password:[/code]

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?
Link to comment
Share on other sites

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

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

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

[!--quoteo(post=350898:date=Mar 2 2006, 03:40 AM:name=Vini)--][div class=\'quotetop\']QUOTE(Vini @ Mar 2 2006, 03:40 AM) [snapback]350898[/snapback][/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?
Link to comment
Share on other sites

Register.php3

[code]<?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();
}
?>[/code]




Edit.php3

[code]<?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();
    }
}
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.