Jump to content

Recommended Posts

Ok i know thers probably errors witht he code below, I've tried for hours literally add single quotes where some sites tell me to add them , taking them away caus they do nothing.

I keep cycling through errors.

 

Basically Im using a php user system from source forge and modifying it.  I just want to test updating sql from a submit button.  So say when button is clicked the new value either as a actual value or an addition like below can be passed to the database and then the value returned as a print or echo.

 

if ocassionaly managed to get the value to update (i checked the sql database) but it doest work at showing the updated value and now its completely broke.

 

Can anyone who understands what im trying to do either look over what ive got and correct or write a simple version of what I should be doing.  Thanks.

 

<?php
//Do not allow the page to be called directly.
if(basename($_SERVER['PHP_SELF']) == "index.inc.php") {
header("Location: index.php");
exit;
}
//If the user is logged in, show this content.
global $valid_user;

if(session_is_registered("valid_user")) {
?>

This is an example text replace of user system
Current Land:
<form>
<form name="script" form action="index.php" method="post">
<b>Increase Landmass</b>
<input type="submit" value="submit">
</form>

<?php
if($_POST["submit"]) {
$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "UPDATE user SET landmass = landmass + 1 where username=$valid_user;
$result = @mysql_query($sql, $connection);
echo $result;
}
?>
                        <table align="center" cellpadding="4" cellspacing="0" width="95%">
                            <tr>
                                <td>

<?php include("./templates/$template/global.inc.php"); ?>

                                </td>
                            </tr>
                        </table>
<?php
}
else
//If the user isn't logged in, show this content.
{
?>
                        <table align="center" cellpadding="4" cellspacing="0" width="95%">
                            <tr>
                                <td>
                                    <p>Welcome to <b><?php echo $sitename ?></b>!
                                    You are welcome to <a href="register.php">register</a>
                                    and enjoy all of the benefits of being a
                                    member here.</p>
                                    <p>Thanks for stopping by!</p>
                                    <?php include("./templates/$template/global.inc.php"); ?>
                                </td>
                            </tr>
                        </table>
<?php
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/63321-php-form-and-update-sql/
Share on other sites

I didn't even look at your code... and won't now. Your second comment is uncalled for. This is a good place to come for info, but you also need to bear in mind that people are donating there time. This isn't a support service you pay for and are guarenteed 15 minute response time it's a free community forum. In the future show up with a different attitude and you just might get some help.

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.