gpt4 book ai didi

PHP 和 MySQL,一种用于插入到 1 个表的 PHP 表单,同时具有来自 2 个不同表的 2 个外键

转载 作者:行者123 更新时间:2023-11-30 01:31:37 25 4
gpt4 key购买 nike

我是 PHP 新手,正在使用 DreamWeaver。

但是,我正在寻找有人帮助我完成这件事。

我在 MYSQL 中有 3 个表

锦标赛

  • idChampionships,
  • 姓名
  • 详细信息

用户

  • idUsers
  • 用户名
  • 密码

参与者

  • idparticipants
  • idChampionships
  • 名字
  • 姓氏
  • 出生日期
  • 全国排名
  • 照片
  • 电话号码
  • 电子邮件地址
  • IdUsers

我想做的是在锦标赛,用户中获取2个现有ID,并在提交表单时将它们插入到参与者表中,以识别他正在参加哪个锦标赛以及该用户是谁。以避免重复。

看来我有一个解析错误,我无法弄清楚,这在最后一行中指出。

请帮忙!

这是代码

<?php require_once('Connections/ACBSEntrySystem.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO participants (idparticipants, idChampionships, FirstName, LastName, DateOfBirth, NationalRanking, Photo, PhoneNumber, EmailAddress, IdUsers) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['idparticipants'], "int"),
GetSQLValueString($_POST['idChampionships'], "int"),
GetSQLValueString($_POST['FirstName'], "text"),
GetSQLValueString($_POST['LastName'], "text"),
GetSQLValueString($_POST['DateOfBirth'], "date"),
GetSQLValueString($_POST['NationalRanking'], "int"),
GetSQLValueString($_POST['Photo'], "text"),
GetSQLValueString($_POST['PhoneNumber'], "double"),
GetSQLValueString($_POST['EmailAddress'], "text"),
GetSQLValueString($_POST['idUsers'], "int"));

mysql_select_db($database_ACBSEntrySystem, $ACBSEntrySystem);
$Result1 = mysql_query($insertSQL, $ACBSEntrySystem) or die(mysql_error());
}

mysql_select_db($database_ACBSEntrySystem, $ACBSEntrySystem);
$query_AvailableChampionships = "SELECT idChampionships, Name FROM Championships ORDER BY Name ASC";
$AvailableChampionships = mysql_query($query_AvailableChampionships, $ACBSEntrySystem) or die(mysql_error());
$row_AvailableChampionships = mysql_fetch_assoc($AvailableChampionships);
$totalRows_AvailableChampionships = mysql_num_rows($AvailableChampionships);



mysql_select_db($database_ACBSEntrySystem, $ACBSEntrySystem);
$query_ActiveUser = "SELECT idUsers FROM Users";
$ActiveUser = mysql_query($query_ActiveUser, $ACBSEntrySystem) or die(mysql_error());
$row_ActiveUser = mysql_fetch_assoc($ActiveUser);
$totalRows_ActiveUser = mysql_num_rows($ActiveUser);

mysql_select_db($database_ACBSEntrySystem, $ACBSEntrySystem);
$query_InsertingARecord = "SELECT * FROM participants";
$InsertingARecord = mysql_query($query_InsertingARecord, $ACBSEntrySystem) or die(mysql_error());
$row_InsertingARecord = mysql_fetch_assoc($InsertingARecord);
$totalRows_InsertingARecord = mysql_num_rows($InsertingARecord);
?>

表单从这里开始,在 HTML 正文中

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">IdChampionships:</td>
<td><select name="idChampionships">
<?php
do {
?>
<option value="<?php echo $row_AvailableChampionships['idChampionships']?>" ><?php echo $row_AvailableChampionships['Name']?></option>
<?php
} while ($row_AvailableChampionships = mysql_fetch_assoc($AvailableChampionships));
?>
</select></td>
<tr>
<tr valign="baseline">
<td nowrap align="right">FirstName:</td>
<td><input type="text" name="FirstName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">LastName:</td>
<td><input type="text" name="LastName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">DateOfBirth:</td>
<td><input type="text" name="DateOfBirth" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">NationalRanking:</td>
<td><input type="text" name="NationalRanking" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Photo:</td>
<td><input type="text" name="Photo" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">PhoneNumber:</td>
<td><input type="text" name="PhoneNumber" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">EmailAddress:</td>
<td><input type="text" name="EmailAddress" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>

用户循环从此处开始以回显 idUser

<input type="hidden" name="idparticipants" value="">
<input type="hidden" name="IdUsers" value="<?php do {echo $row_ActiveUser['idUsers'];while ($row_ActiveUser = mysql_fetch_assoc($ActiveUser));?>">
<input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
</div>
</div>
</div>
</section>

<!--==============================footer================================-->
<?php include("../include/footer.php");?>
</div>
</div>
</body>

</html>
<?php
mysql_free_result($AvailableChampionships);

mysql_free_result($ActiveUser);

mysql_free_result($InsertingARecord);
?>

出现错误是

解析错误:语法错误,/Applications/XAMPP/xamppfiles/htdocs/entryform.php 第 191 行出现意外的 $end

最佳答案

您的 do-while 循环缺少右大括号。

`value="<?php do {echo $row_ActiveUser['idUsers'];while ($row_ActiveUser = mysql_fetch_assoc($ActiveUser));?>">`

应该是

value="<?php
do {
echo $row_ActiveUser['idUsers'];
} while ($row_ActiveUser = mysql_fetch_assoc($ActiveUser));
?>">

关于PHP 和 MySQL,一种用于插入到 1 个表的 PHP 表单,同时具有来自 2 个不同表的 2 个外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17385830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com