Gunny
Expert Member
A cold beer goes to the person who can give me an easy way to change an array key name. 
South Africa’s biggest forum. Discuss, discover, and connect with thousands of members.
<?php $array["newkey"] = $array["oldkey"];
<?php unset ($array ["elm"]) ?>
Gunny said:Now if you have a clever way of getting rid of the last comma after the key and value list theres a sixpack in the fridge.
Gunny said:Now if you have a clever way of getting rid of the last comma after the key and value list theres a sixpack in the fridge.
Gunny said:Now if you have a clever way of getting rid of the last comma after the key and value list theres a sixpack in the fridge.
foreach($_POST as $key => $value)
{
$val .= ("$key,");
$va2 .= ("$value,");
}
$val = substr($val,0,-1);
$va2 = substr($va2,0,-1);
echo("$val<br>$va2");
$query='insert into table (col) values ("string");'; (Notice the string is in ' ')
or
$query="insert into table (col) value (\"string\");";
Gunny said:Can one of you clever folks help me with this one.
To insert values into MySQL they need to be enclosed in these babies ""
e.g ("value1","value2",...
How do I make PHP do that ???
Tazz_Tux said:PHP is quite cleva here -
You can say the following:
Code:$query='insert into table (col) values ("string");'; (Notice the string is in ' ') or $query="insert into table (col) value (\"string\");";
Laterz !
$query="insert into table (col) value (\"$stringvalue\");";
$query='insert into table (col) value ("$stringvalue");';
$query='insert into table (col) value ("'.$stringvalue.'");';
Moederloos said:will actually insert $stringvalue into the table and not the value in the variable.Code:$query='insert into table (col) value ("$stringvalue");';
$val = "";
$va2 = "";
foreach($_POST as $key => $value)
{
$val .= ("$key,");
$va2 .= ("\"$value\",");
}
$val = substr($val,0,-1);
$va2 = substr($va2,0,-1);
//echo("$val<BR>$va2<BR>")
$g =("INSERT INTO stock ($val) VALUES ($va2)");
$result = mysql_query($g);
if($result == 0)
{
echo "<b>Error ".mysql_errno().": ".mysql_error().
"</b>";
}