Hi,
I am working on extracting data from a form which updates a database table called 'race_admin'. I have assigned the data from the POST function to an array variable called $arr. I have then assigned the respective column names in my database table to another array variable called $carr.
I have then tried to combine the two using the 'foreach' function with 'and' to update the records in the DB table. As it will not work I've managed to debug the script which shows that the script does not like the 'and'.
I would welcome suggestions on how to get this to work or to achieve it using another method please.
Many thanks. 😕
My code:
<?php
$race_d = $_POST['race_date'];
$open = $_POST['open_date'];
$close = $_POST['close_d'];
$fee = $_POST['fee'];
$record = $_POST['record'];
$fin_time = $_POST['finish_time'];
$news = $_POST['news'];
$start = $_POST['start_details'];
$presentation = $_POST['presentation_details'];
$arr = array($race_d,$open,$close,$fee,$record,$fin_time,$news,$start,$presentation);
#foreach($arr as $result)
#{echo("<br /> $result");}
#connect to MySQL
$conn=@mysql_connect( "localhost", "jock", "bladerunner" )
or die( "Err:Conn" );
#select the specified database
$rs = @mysql_select_db( "cheviot2000", $conn )
or die( "Err:Db" );
#Assign column names to variable
$carr = array('race_date','open_date','close_date','entry_fee','cur_record','news','start_details','present_details','app_add','app_form','record_time');
echo("past stage");
#foreach($carr as $value)
#{echo("<br /> $value");}
foreach($carr as $value) and ($arr as $data)
{
mysql_query("update race_admin set $value = '$data' where id = 1", $conn ) or die("Query failed");
}
#close connection to mysql
mysql_close();
echo("Complete");
?>