php&mysql question

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

Post Reply
bobemf
Forum Newbie
Posts: 7
Joined: Wed May 26, 2004 12:58 pm

php&mysql question

Post by bobemf »

the values [$name2] come from a form on the previous page.

Code: Select all

<body bgcolor="#F3F3F3">
<font color="#808080" size="2"><?
    $conn = @mysql_connect("localhost", "lh", "edit")
		or die("Could not connect to MySQL Database.");
	
	$rs = @mysql_select_db("profiles",$conn)
		or die("Could not select MySQL database");

		$sql ="REPLACE INTO profile (real_name, aboutme, email, age) values ("$real_name2","$aboutme2","$email2","$age2") WHERE `user`='$autheduser'";
		$rs = @mysql_query($sql,$conn)
			or die("Could not execute SQL query");
echo 'If there are no errors above ... your profile update was successful.';	
?>
Im getting

Code: Select all

Could not execute SQL query
so it must be something with replace into or something? im not sure.
thanks for the help!
bobemf
Forum Newbie
Posts: 7
Joined: Wed May 26, 2004 12:58 pm

Post by bobemf »

Heres the previous page, JUST in case.

Code: Select all

<body bgcolor="#F3F3F3">
<?php
$autheduser = $_COOKIE['account'];
if($autheduser != null) {
$acct = $_COOKIE['account'];
	$conn=@mysql_connect("localhost", "lh", "")
		or die("Error: Connection - Please contact site administrator if this happens again, thank you!");
	
	$rs = @mysql_select_db("profiles",$conn)
		or die("Error: Db - Please contact site administrator if this happens again, thank you!");
	
	$sql = "SELECT * FROM profiles WHERE `user`='$autheduser'";
	
	$rs = @mysql_query($sql,$conn)
		or die("Error: Query - Please contact site administrator if this happens again, thank you!");
	
	while( $row = mysql_fetch_array($rs) )
	{
$user = $row['user'];
$aboutme = $row['aboutme'];
$icon = $row['icon'];
$email = $row['email'];
$realname = $row['real_name'];
$age = $row['age'];
}
?>
<font color="#808080" size="2">
<?
$form="<form action="creating.php" method="post">
Editing profile for:<br>
$autheduser<br><br>
Real Name<br><textarea name="real_name2" type="text">$realname</textarea><br>
Age<br><textarea name="age2" type="text">$age</textarea><br>
Your Email<br><textarea name="email2" type="text">$email</textarea><br>
About You<br>
<textarea name="aboutme2" cols="50" rows="10">$aboutme</textarea><br>
<input name="Submit" type="Submit" value="Submit">
</form>";
?>
<? } else { echo("<font color="#808080" size="2">You are not logged in."); }
echo $form
?>
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

Code: Select all

$sql ="UPDATE profile  set real_name='$real_name2', aboutme='$aboutme2', email= '$email2', age$age2 WHERE `user`='$autheduser'";
bobemf
Forum Newbie
Posts: 7
Joined: Wed May 26, 2004 12:58 pm

Post by bobemf »

nope.
could not execute query.
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

Code: Select all

$sql ="UPDATE profile  set real_name='$real_name2', aboutme='$aboutme2', email= '$email2', age=$age2 WHERE `user`='$autheduser'";
Missed the equal sign in the age section
bobemf
Forum Newbie
Posts: 7
Joined: Wed May 26, 2004 12:58 pm

Post by bobemf »

this is what i have

Code: Select all

<body bgcolor="#F3F3F3">
<font color="#808080" size="2"><?
    $conn = @mysql_connect("localhost", "lh", "")
		or die("Could not connect to MySQL Database.");
	
	$rs = @mysql_select_db("profiles",$conn)
		or die("Could not select MySQL database");

		$sql ="UPDATE profile  set real_name='$real_name2', aboutme='$aboutme2', email= '$email2', age=$age2 WHERE `user`='$autheduser'";
		$rs = @mysql_query($sql,$conn)
			or die("Could not execute SQL query");
echo 'If there are no errors above ... your profile update was successful.';	
?>
Still didnt work :((
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

You are using the same variable for the recordset $rs and the database selection $rs...shoudn't matter though....

remove the @ symbol to see what the real error is
bobemf
Forum Newbie
Posts: 7
Joined: Wed May 26, 2004 12:58 pm

Post by bobemf »

remove the @ symbol where?

Code: Select all

$rs = @mysql_query($sql,$conn)
<-- there?
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

everywhere
bobemf
Forum Newbie
Posts: 7
Joined: Wed May 26, 2004 12:58 pm

Post by bobemf »

ok i removed the @ everywhere..
and i still didnt get any error besides my die message Could not execute query.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

switch that to die(mysql_error()), and please report back what it kicks out.
bobemf
Forum Newbie
Posts: 7
Joined: Wed May 26, 2004 12:58 pm

Post by bobemf »

I got it working now!! Thanks for your help guys!
Post Reply