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
https://forums.phpfreaks.com/topic/141796-beginners-bad-luck/
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
https://forums.phpfreaks.com/topic/141796-beginners-bad-luck/#findComment-742422
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
https://forums.phpfreaks.com/topic/141796-beginners-bad-luck/#findComment-742430
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
https://forums.phpfreaks.com/topic/141796-beginners-bad-luck/#findComment-742442
Share on other sites

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.