php quick urgent fix

I have a script that loads a table, puts all fields and values of a defined row in an associative array, applies an array of changes then writes the data back to the DB as a new record.

It works great except it doesn't handle null values well. It inserts them back in as empty or 0 instead of null.

I need someone to fix it tonight.

Here's the code:

// This is where I define the table on which to copy records, the record ID to copy from, and the fields to change

$whereStmt = ' SiteUserID="43"';

$replaceArray = array( "SiteUserID" => $conn->Insert_ID() );

copyRecord($whereStmt, $replaceArray, "sitesettings" );

function copyRecord($whereStmt,$replaceArray,$tableName){

$link = mysql_connect(EW_CONN_HOST,EW_CONN_USER, EW_CONN_PASS);

mysql_select_db(EW_CONN_DB, $link);

$sql ="select * from $tableName where ".$whereStmt;

$result = mysql_query($sql) or die('Query failed: ' . mysql_error());

if ($result) {

// the next row should have the at symbol in front of mysql but I can't put it because of scriptlance rules.

if ( mysql_num_rows($result) > 0) {

$row = mysql_fetch_assoc($result); // get the (1st) row as an associative array

foreach ($row as $key => $value) {

$slashedrow[$key] = addslashes($row[$key]); }

// Run down the passed list of fields we want to modify in the record.

// Replace any existing value with the new value.

// Only fields in the passed array '$namesAndValues' will be affected

foreach ($replaceArray as $theName => $theValue) {

$slashedrow [$theName] = addslashes($theValue);}

// Rebuild the field list and the value list for the insert

$fieldList = implode(",", array_keys($slashedrow) );

$valueList = implode("','", $slashedrow);

// Run the query

// echo ("Trying to insert into $tableName ( $fieldList ) values ('$valueList')");

$link = mysql_connect(EW_CONN_HOST,EW_CONN_USER, EW_CONN_PASS);

mysql_select_db(EW_CONN_DB, $link);

$sql ="insert into $tableName ( $fieldList ) values ('$valueList')";

$result = mysql_query($sql) or die('Query failed: ' . mysql_error());




This code should work with any database where the table has a UserID field as the key. I will not provide a connection to the actual database as it is not needed.

Corrected code shoud be delivered within 24 hours of being awarded the project.

Only bid if your ready to get $5 for this fix ...

and also in pmb post the message that

'am ready for $5'

so, that i know you really read the project

Taidot: PHP

Näytä lisää: work with scriptlance, we will fix it, we trying to function, the fix it, sql query to get list of database, quick 24, php script null, php and mysql connection, i will fix it, foreach in php and mysql, fix it at, php symbol, scriptlance down, urgent mysql, urgent hours, php db, null, need a quick mysql script, fix mysql query, fix database, php data table, php connection, field php, php connection select, mysql change connection

Tietoa työnantajasta:
( 82 arvostelua ) karachi, Pakistan

Projektin tunnus: #405769