Please help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

Please help!

Post by apple »

Which query is correct?

Code: Select all

$query = "UPDATE names SET prefix_id = $prefix, fname = $fn, mname = $mn, lname = $ln, nname = $nn, email = $e, url = $u, hadd = $hadd, hcity = $hcity, hzcode = $hzcode, hbansa = $hbansa, htel = $htel, bday = $bday, bplace = $bpla WHERE id = $value";
OR

Code: Select all

$query = "UPDATE names SET prefix_id='$prefix', fname='$fn', mname='$mn', lname='$ln', nname='$nn', email='$e', url='$u', hadd='$hadd', hcity='$hcity', hzcode='$hzcode', hbansa='$hbansa', htel='$htel', bday='$bday', bplace='$bpla' WHERE id='$value'";
Thanks :D
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

it depends. Both are correct in the way you have written them, but it depends on what information is contained within the variables!

Mark
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

Thank You

Post by apple »

I am just confuse which is correct way of UPDATE the MySql... Does It means that I can use both of them?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

I would go for the second one, but without knowing what information you are inserting it is pretty difficult!

Try it and see what happens

Mark
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

This is WHAT I've done

Post by apple »

Actually I want to UPDATE the profile of my clients this what I have done?

Code: Select all

<?php

// Set the page title and include the HTML header.
$pahina = 'Update Your Profile!';
include ('header.inc');

// Set the page title and include the HTML header.
require_once ("config.inc"); // Connect to the database.
require_once ("connect.php"); // Connect to the database.

if (isset($_GET["id"]))
{
   $value = $_GET["id"];
   // Make the query.
   $query = "SELECT * FROM names WHERE id='$value'";      
   $result = @mysql_query ($query); // Run the query.
   $row = mysql_num_rows ($result); // How many users are there?

   //Fetch   
   while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
   
   $admin = $row[1];
   $prefix = $row[2];
   $fn = $row[3];
   $mn = $row[4];
   $ln = $row[5];
   $nn = $row[6];
   $e = $row[7];
   $u = $row[8];
   $hadd = $row[12];
   $hcity = $row[13];
   $hzcode = $row[14];
   $hbansa = $row[15];
   $htel = $row[16];
   $bday = $row[18];
   $bpla = $row[19];
   
   }
} else {
   echo "The value of ID was not detected.<br/>";
}

if (isset($_POST['submit'])) { // Handle the form.

$message = NULL; // Create an empty new variable.

// Check for fname.
   if (empty($_POST['fname'])) {
      $fn = FALSE;
      $message .= '<p>You forgot to enter the First Name!</p>';
   } else {
      $fn = $_POST['fname'];
   }
//Last Name
   if (empty($_POST['lname'])) {
      $ln = FALSE;
      $message .= '<p>You forgot to enter the Last Name!</p>';
   } else {
      $ln = $_POST['lname'];
   }
   //Email
   if (!eregi ("^[[]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) {
      $e = FALSE;
      $message .= '<p>You forgot to enter your email address!</p>';
   } else {
      $e = $_POST['email'];
   }
   //URL
   if (!eregi ("^((http|https|ftp)://)?([[]-])+(\.)([[]]){2,4}([[]/+=%&_.~?-]*)$", stripslashes(trim($_POST['url'])))) {
      $url = FALSE;
      $message .= '<p>Please enter valid url address!</p>';
   } else {
      $url = $_POST['url'];
   }
   
if ($fn && $ln && $e) { // If everything's OK.
// Make the query.
$query = "UPDATE names SET prefix_id='$prefix', fname='$fn', mname='$mn', lname='$ln', nname='$nn', email='$e', url='$u', hadd='$hadd', hcity='$hcity', hzcode='$hzcode', hbansa='$hbansa', htel='$htel', bday='$bday', bplace='$bpla' WHERE id='$value'";
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) { //Record pulled into the DATABASE
            
            // Send an answer, if desired.
            echo '<p><b>You have Completed Your Profile!</b></p>';
            echo '<br><a href="logout.php">Logout</a></br></p>';
            exit(); // Quit the script.
         } else { // If it did not run OK.
            $message = '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>';
         }
      
      mysql_close(); // Close the database connection.

   } else {
      $message .= '<p>Please try again.</p>';      
   }

} // End of the main Submit conditional.

// Print the message if there is one.
if (isset($message)) {
   echo '<font color="red">', $message, '</font>';
}

?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><form action="<?php echo $_SERVER['PHP_SELF']."?id=$value"; ?>" method="post">
        <table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td colspan="2">Personal Profile</td>
          </tr>
          <tr>
            <td>Prefix</td>
            <td><?php echo '<select prefix_id="$prefix">';   
     // Display the type_id:
   $query_result = mysql_query("SELECT * FROM prefix ORDER BY id");
    while ($row = mysql_fetch_array($query_result, MYSQL_NUM)) {
echo "<option value="$row[0]">$row[1]</option>\n";
   };
echo '</select></td></tr>';
   // Tidy up (not required):
   mysql_free_result($query_result);
   mysql_close();?></td>
          </tr>
          <tr>
            <td width="200">First Name</td>
            <td width="82%"><input name="fname" type="text" value="<?php if (isset($_POST['fname']))
                                                         echo trim($_POST['fname']);
                                                      else
                                                         echo trim($fn); ?>" size="50"></td>
          </tr>
          <tr>
            <td width="200">Middle Name</td>
            <td><input name="mname" type="text" value="<?php if (isset($_POST['mname']))
                                             echo trim($_POST['mname']);
                                                      else
                                                         echo trim($mn); ?>" size="50"></td>
          </tr>
          <tr>
            <td width="200">Last Name</td>
            <td><input name="lname" type="text" value="<?php if (isset($_POST['lname']))
                                                         echo trim($_POST['lname']);
                                                      else
                                                         echo trim($ln); ?>" size="50"></td>
          </tr>
          <tr>
            <td>Nick Name</td>
            <td><input name="nn" type="text" id="nname" value="<?php if (isset($_POST['nname']))
                                                         echo trim($_POST['nname']);
                                                      else
                                                         echo trim($nn); ?>" size="50"></td>
          </tr>
          <tr>
            <td width="200">Email Address</td>
            <td><input name="email" type="text" value="<?php if (isset($_POST['email']))
                                                         echo trim($_POST['email']);
                                                      else
                                                         echo trim($e); ?>" size="50"></td>
          </tr>
          <tr>
            <td width="200">Home Address</td>
            <td><input name="hadd" type="text" value="<?php if (isset($_POST['hadd']))
                                                         echo trim($_POST['hadd']);
                                                      else
                                                         echo trim($hadd); ?>" size="50"></td>
          </tr>
          <tr>
            <td>City</td>
            <td><input name="hcity" type="text" value="<?php if (isset($_POST['hcity']))
                                                         echo trim($_POST['hcity']);
                                                      else
                                                         echo trim($hcity); ?>" size="50"></td>
          </tr>
          <tr>
            <td>Zip Code</td>
            <td><input name="hzcode" type="text" value="<?php if (isset($_POST['hzcode']))
                                                         echo trim($_POST['hzcode']);
                                                      else
                                                         echo trim($hzcode); ?>" size="50"></td>
          </tr>
          <tr>
            <td>Country</td>
            <td><input name="hbansa" type="text" value="<?php if (isset($_POST['hbansa']))
                                                         echo trim($_POST['hbansa']);
                                                      else
                                                         echo trim($hbansa); ?>" size="50"></td>
          </tr>
          <tr>
            <td>Telephone Number</td>
            <td><input name="htel" type="text" value="<?php if (isset($_POST['htel']))
                                                         echo trim($_POST['htel']);
                                                      else
                                                         echo trim($htel); ?>" size="50"></td>
          </tr>
          <tr>
            <td>Birthday</td>
            <td><input name="bday" type="text" value="<?php if (isset($_POST['bday']))
                                                         echo trim($_POST['bday']);
                                                      else
                                                         echo trim($bday); ?>" size="50"></td>
          </tr>
          <tr>
            <td>Birth Place</td>
            <td><input name="bplace" type="text" value="<?php if (isset($_POST['bplace']))
                                                         echo trim($_POST['bplace']);
                                                      else
                                                         echo trim($bpla); ?>" size="50"></td>
          </tr>
          <tr>
            <td colspan="2"><div align="center">
                <input type="submit" name="Submit" value="Update the Personal Profile">
              </div></td>
          </tr>
        </table>
      </form></td>
  </tr>
</table>
<!-- End of Form -->
<?php
include ('footer.inc'); // Include the HTML footer.
?>



I think something is wrong 'coz I can't able to submit the page properly. Thank for your time...
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

what happens when you submit the page?

Error messages?

Mark
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

Theres no error messages

Post by apple »

But the database did'nt change at all...
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Change this........
[quote="Original Poster"]

Code: Select all

$result = @mysql_query ($query);
to this

Code: Select all

$result = mysql_query ($query) or die (mysql_error());
now what does it say when you try and insert the info?
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

Does'nt Change A Bit

Post by apple »

This does'nt work...

Code: Select all

<?php$result = mysql_query ($query) or die (mysql_error());//malcolmboston

?>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

malcolmboston wrote:Change this........
Original Poster wrote:

Code: Select all

$result = @mysql_query ($query);
to this

Code: Select all

$result = mysql_query ($query) or die (mysql_error());
now what does it say when you try and insert the info?
is it really that hard to understand

replace what you had in your code with what i've told you,
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

Sorry malcolmboston

Post by apple »

I already change the

Code: Select all

<?php


$result = @mysql_query ($query); // Run the query.

?>
to this

Code: Select all

<?php

$result = mysql_query ($query) or die (mysql_error());//malcolmboston

?>
Still does'nt have changes in the PROFILE UPDATE
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

so your getting no error messages?

is the data being updated or not?
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

No Updates Made

Post by apple »

Thier is no ERROR MESSAGES and UPDATES (changes) in the Profile.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

can you echo out the query you are trying to execute.

Code: Select all

echo $query;
Post back what it returns!

Mark
Last edited by JayBird on Mon May 17, 2004 5:58 am, edited 1 time in total.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ok print out your query to make sure it looks ok

Code: Select all

print $query;
Post Reply