PDA

View Full Version : MySQL update/insert question


Incantius
7-15-03, 06:08 PM
I have been trying to get a simple questionnaire page built. My problem is that no matter what I use (prepare/execute, or in-line execution) the entire script works *except* the actual SQL update/insert. Here is the code as it stands now:

function WriteRecord(mainx,statsx,lookingforx,new2EQx,rolex )
{

<?php
$db = mysql_connect("mysql02.powweb.com", "Incantius", "xxxxxxxx");


mysql_select_db("siv_forum",$db);
$sql = "SELECT * FROM questionnaire WHERE main=mainx";
$result = mysql_query($sql);
if ($myrow = mysql_fetch_array($result)) {
$sql = "update questionnaire set main=mainx, stats=statsx, lookingfor=lookingforx, new2EQ=new2EQx, role=rolex where main=mainx";

} else {

$sql = "insert into questionnaire values(mainx,statsx,lookingforx,new2EQx,rolex)";
}

$result = mysql_query($sql);
?>


anyway thanks in advance for any & all assistance!!!

HalfaBee
7-15-03, 06:48 PM
Try putting

$result = mysql_query($sql) or die( mysql_error()." $sql" );

Then you can see what the error is.

if mainx is a string put it in quotes. 'mainx'

HalfaBee

Incantius
7-15-03, 09:50 PM
ok i changed the statement but now the form itself doesn't display. mainx is a variable containing data retrieved from the form. Is there anything specific i have to do in order to see the error?

Incantius
7-15-03, 10:01 PM
ok i figured out how to see the error generated. it looks like I'll need to use the prepare/execute method. is there a quick way to explain that to me?