将这样的变量插入表中是否正确?因为我没有插入任何内容,警报信息也不会显示
我正在使用扩展程序在Joomla的文章中添加php代码
require_once JPATH_BASE . '/tools/config.php';
include JPATH_BASE . '/tools/subvterms.php';
if(isset($_POST['check'])){
echo " <style>
.termsContent { display: none;}
.service-content { display: inline; width: 100%}
</style> " ;
}
if (isset($_POST['send'])) {
$firstname = $_POST['firstname'];
$fathername = $_POST['fathername'];
$grandfathername = $_POST['grandfathername'];
$familyname = $_POST['familyname'];
$identity = $_POST['identity'];
$borndate = $_POST['borndate'];
$mobilenumber = $_POST['mobilenumber'];
$cityliving = $_POST['cityliving'];
$livingshare = $_POST['livingshare'];
$parentslive = $_POST['parentslive'];
$livingtype = $_POST['livingtype'];
$owndate = $_POST['owndate'];
$parentscity = $_POST['parentscity'];
$parentsnighborhood = $_POST['parentsnighborhood'];
$nearestmosque = $_POST['nearestmosque'];
$jobname = $_POST['jobname'];
$jobplace = $_POST['jobplace'];
$salary = $_POST['salary'];
$gotsub = $_POST['gotsub'];
$gotmarried = $_POST['gotmarried'];
$wifestatus = $_POST['wifestatus'];
$nekahdate = $_POST['nekahdate'];
$gowithwife = $_POST['gowithwife'];
$marriagedate = $_POST['marriagedate'];
$nomarriagedate = $_POST['nomarriagedate'];
$restofmoney = $_POST['restofmoney'];
$datetime = time();
$con->set_charset('utf8');
$stmt = mysqli_prepare($con,"INSERT INTO subventions (firstname,fathername,grandfathername,familyname,identity,borndate,mobilenumber,cityliving,livingshare,parentslive,livingtype,owndate,parentscity,parentsnighborhood,nearestmosque,jobname,jobplace,salary,gotsub,gotmarried,wifestatus,nekahdate,gowithwife,marriagedate,nomarriagedate,restofmoney,datetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$bind = mysqli_stmt_bind_param($stmt,"ssssssssssssssssssssssssssi",$firstname,$fathername,$grandfathername,$familyname,$identity,$borndate,$mobilenumber,$cityliving,$livingshare,$parentslive,$livingtype,$owndate,$parentscity,$parentsnighborhood,$nearestmosque,$jobname,$jobplace,$salary,$gotsub,$gotmarried,$wifestatus,$nekahdate,$gowithwife,$marriagedate,$nomarriagedate,$restofmoney,$datetime);
$exec = mysqli_stmt_execute($stmt);
if($exec == true){
echo '<script type="text/javascript"> alert("تم إرسال البيانات");
return false;
</script>';
} else {
'<script type="text/javascript"> alert("حدث خطأ عند إرسال البيانات");
return false; </script>';
}
mysqli_stmt_close($stmt);
}
配置文件
<?php
define("HOST","localhost");
define("USER", "root");
define("PASS", "root");
define("DB", "inserted");
$con = mysqli_connect(HOST,USER,PASS,DB) or die ("error");
?>
.............................................. < / p>
答案 0 :(得分:0)
Joomla很容易插入一排新表: 点击链接(使用对象) https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase
Here the solution
// Create and populate an object.
$row = new stdClass();
$row->firstname = $_POST['firstname'];
$row->fathername = $_POST['fathername'];
.
.
.
// Insert the object into the user profile table.
$result = JFactory::getDbo()->insertObject('#__subventions', $row);