Jump to content

Beginners bad luck


akano

Recommended Posts

I've got a little problem with my query. This is my database:

 

TABLE: Members

Columns:

id

username

password

name

age

email

 

I already got a working form that fills in id,username and password but when I now have constructed a script to fill in the rest of the columns I can't get it working. I my INSERT statement to put the rest of the data together with a specified user.

 

I thought it would look something like this:

 

INSERT INTO members (name,age,email) VALUES ('test',23,'test') where username='username';

 

or:

 

INSERT INTO members (name,age,email) WHERE username='username' VALUES ('test',23,'test');

 

Anyone know what I'm doing wrong?  ???

 

Link to comment
Share on other sites

Thanks a lot Mchl it worked like a charm :)

I just need help with one more thing and I don't feel like taking up space in another subforum although this question is more a php problem.

 

I try to use this query:

 

mysql_query("UPDATE members SET name='$name', age=$age, email='$email', WHERE username='akano'")or die(mysql_error());

 

but it doesn't work but works well in sql..is there something I've missed?

 

Thanks for the fast help btw!

Link to comment
Share on other sites

well I removed the (,) but it still doesn't work. I tried to remove the variables and insert some values instead. It still won't update. And no I don't get any errors, the page just comes up blank and when I check the database nothing has happend. In the command prompt the UPDATE command works perfectly but not in the script. Kinda wierd :/

Link to comment
Share on other sites

Then you have an error somewhere before you try to execute the sql statement.  Can we see your code? 

 

Also put this at the top of your page:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

 

Link to comment
Share on other sites

Yeah sure :) here is the form:

<html>
<body>
<form action="mataindata.php" method="post">
<table border ="0">
<tr><td>Your Name:</td><td> 
<input type="text" name="name" maxlength="40">
</td></tr>
<tr><td>E-mail:</td><td>
<input type="text" name="email" maxlength="40">
</td></tr>
<tr><td>Age:</td><td>
<input type="text" name="age" maxlength="40">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" value="Submit">
</td></tr>
</table>
</form>
<a href=lol.php>Hem</a>
</body>
</html> 

 

And here is the php code:

<?
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$name=$_POST['name']; 
$email=$_POST['email']; 
$age=$_POST['age'];
mysql_connect("localhost", "root", "password") or die(mysql_error()); 
mysql_select_db("projekt") or die(mysql_error()); 
mysql_query("UPDATE members SET name='$name', age=$age, email='$email' WHERE username='akano'")or die(mysql_error());
echo "Your information has been successfully added to the database."; 
?>

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.