Jump to content

Insert MYSQL


princeofpersia

Recommended Posts

Hi guys

 

I have a registration form working fine, my database is as below:

 

userid

username

email

password

repeatpassword

 

 

I have added another column which is "name", users can update their profile once they have logged in so I have created updateprofile.php and when I login-->go to update profile and insert my name nothing adds to mysql name column

 

this is my code below:

 

<?php

 

include ("global.php");

 

 

//username session

$_SESSION['username']=='$username';

$username=$_SESSION['username'];

 

//welcome messaage

echo "Welcome, " .$_SESSION['username']."!<p>";

 

  if ($_POST['register'])

    {

    //get form data

    $name = addslashes(strip_tags($_POST['name']));

 

$update = mysql_query("INSERT INTO users (name) VALUES ('$_POST[name]') WHERE username='$username'");

   

}

 

?>

 

    <form action='updateprofile.php' method='POST'>

    Company Name:<br />

    <input type='text' name='name'><p />

 

    <input type='submit' name='register' value='Register'>

    </form>

 

 

can you please tell me where in this code is wrong? Im new in php so please excuse me if I have silly mistakes.

 

thanks in advance ;)

 

Link to comment
Share on other sites

....

//username session

$_SESSION['username']=='$username';

$username=$_SESSION['username'];

...

 

what???... I'm lost kind of lost with those 2 sentences...  ;)

 

echo your $username variable and check if the value will be consistent with your SELECT

 

and what Pikachu2000 suggested is also valid.

Link to comment
Share on other sites

there you go

________________________

 

 

<?php

session_start();

include ("global.php");

 

 

//username session

$_SESSION['username']=='$username';

$username=$_SESSION['username'];

 

 

//welcome messaage

echo "Welcome, " .$_SESSION['username']."!<p>";

 

  if ($_POST['register'])

    {

    //get form data

    $name = addslashes(strip_tags($_POST['name']));

 

 

 

 

 

$update = mysql_query("UPDATE  users  VALUES ('$_POST[name]') WHERE username='$username'");

   

 

 

 

 

 

 

}

 

 

?>

 

    <form action='updateprofile.php' method='POST'>

    Company Name:<br />

    <input type='text' name='name'><p />

 

    <input type='submit' name='register' value='Register'>

    </form>

 

Link to comment
Share on other sites

one more question, now we assume we add another column named telephonenumber and we use the same query to update. Now if user doesnt fill the name and only enteres the telephone number name field overrites the empty space. how i should avoid that?

 

SO on update we have two input text

 

name

telelphone

 

I have only inserted telephone, it added the telephone but now the name is empty in php myadmin

thanks

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.