Jump to content

strSQL (Insert Data)


sepoto

Recommended Posts

I am debugging some existing code in NetBeans. These are the lines I am working with:

if($failed == false)  {  	$pass_md5 = md5($password);	$sql = "INSERT into dsg_users(company, first_name, last_name, street_address1, street_address2, city, state, postal_code, phone_number, fax_number, email, website, facebook, twitter, password, user_type) values( '$company', '$first_name', '$last_name', '$street_address1', '$street_address2', '$city', '$state', '$postal_code', '$phone_number', '$fax_number', '$email', '$website', '$fb', '$twitter', '$pass_md5', 1);";	$result = $db->query($sql);	if(logIn($db, $email, $pass_md5)){		//We forward to edit_profile page.		ob_clean();		header("location:/edit_profile.php");	}	else{		echo "There was an error creating your account.";	}  }

What happens is "md5" executes properly and the next line after it "$sql" is also no problem. The problem seems to lie here.

$result = $db->query($sql);

No data is inserted into the database. So to troubleshoot the code I copy pasted the "$SQL" out of NetBeans directly and into MySQL workbench to see if the query would work manually and viola!

INSERT into dsg_users(company, first_name, last_name, street_address1, street_address2, city, state, postal_code, phone_number, fax_number, email, website, facebook, twitter, password, user_type) values( 'Sepich Enterprises', 'Eric', 'Sepich', '555 Ridge St.', '', 'Ventura', 'CA', '91320', '8054028072', '', 'myemail@email.com', '', '', '', '11205c64f7df3187e1ba5ca17faefcbe', 1);

For some reason I can not determine I can manually execute the query without fault but when the code executes the insert query fails. I do not know if it matters but NetBeans is telling me something about some watches being disabled. Perhaps that may help as far as obtaining some value into $result which seems to be consistently NULL.I figured perhaps someone may have an interest in this type of thing here. I don't mean to waste anyones time I know it is a bit of a long question. Thanks so much for looking.

Link to comment
Share on other sites

What is the $db object? Is that something like a mysqli object, or is that custom?
It is defined like this above at the top of the code.
$db = db_connect();

Link to comment
Share on other sites

OK.. what's the db_connect function?
OK. It looks like this.
function &db_connect() {if ($_SERVER['SERVER_NAME'] == 'tsg.someserver.net')	{		$myhost = "replace";	}else{		$myhost = "replace";	}  $connUser = "root";  $connPass = "oilwell123";  $dbname = "thesportsguyz";  $db = new mysqli($myhost, $connUser, $connPass, $dbname);  return $db;}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...