Jump to content

Why is this script not updating database :S? please help


soupy127

Recommended Posts

I have an updatemember.php, and updatemember2.php. the first updatemember.php calls the info from the database using the session function and displays it into a form where the user can enter the details. Once the user is happy he clicks the  update button which updatemember2.php is susposed to update in the database but it is currently just saying record updated but doesnt change the values in the database :(? here are the scripts below. please help :)!

 

updatemember.php

<?php

session_start();

 

if (isset($_SESSION['username'])) {

 

//the username exists

echo "Welcome, ".$_SESSION['username']."!<br> <a href='logout.php'>Logout</a>";

 

 

}

 

else

die("Sorry but you must be logged in to view this Area");

 

?>

 

<?php

 

$con = mysql_connect("localhost", "root", "");

 

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("duffers", $con);

 

$result = mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'");

 

while($row = mysql_fetch_array($result))

  {

  $x1 = $row['username'];

  $x2 = $row['name'];

  $x3 = $row['contactnumber'];

  $x4 = $row['email'];

  $x5 = $row['handicap'];

  }

 

mysql_close($con);

 

?>

<form method="post" action="updatemember2.php">

 

Username: <input type="text" name="username" value="<?php echo $x1; ?>">

<br>

Name: <input type="text" name="name" value="<?php echo $x2; ?>">

<br>

Contact Number: <input type="text" name="contactnumber" value="<?php echo $x3; ?>">

<br>

Email: <input type="text" name="email" value="<?php echo $x4; ?>">

<br>

Handicap: <input type="text" name="handicap" value="<?php echo $x5; ?>">

<br>

<br><input type="submit" value="Update">

</form>

 

 

and updatemember2.php

 

 

<?php

session_start();

 

if (isset($_SESSION['username'])) {

 

//the username exists

echo "Welcome, ".$_SESSION['username']."!<br> <a href='logout.php'>Logout</a>";

 

 

}

 

else

die("Sorry but you must be logged in to view this Area");

 

?>

<?php

 

$con = mysql_connect("localhost", "root", "");

$username =$_POST['username'];

$name =$_POST['name'];

$contactnumber =$_POST['contactnumber'];

$email =$_POST['email'];

$handicap =$_POST['handicap'];

 

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("duffers", $con);

 

mysql_query("UPDATE users SET username = '$_POST[username]', name = '$_POST[name]', contactnumber = '$_POST[contactnumber]', email = '$_POST',handicap = '$_POST[handicap]'

WHERE username = '$_POST[username]'");

 

echo "Record updated!";

 

mysql_close($con);

 

 

?>

Thanks alot for your help i just got it working there :)! thanks again! oh just one more question while im logged on, how would i go about creating a dropdown list, that would be populated by the usernames from my users table, so that when the admin selects the username from the dropdown table it will display their results :)? and can it be linked with another another drop down men (i.e. name of course?) im not to sure how to use the join function :(!

Archived

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

×
×
  • 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.