/    Sign up×
Community /Pin to ProfileBookmark

PHP/Mysql Insert problem

Hi,
can anyone please tell me what is wrong with this code:
$insertGoTo = “/Index5.php?recordid=<?php echo $row_test[‘id’]; ?>”
thanks

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 23.2009 — It looks like you are trying to embed PHP within PHP (i.e., you're already inside a <?php...?> set of tags when you try to open another around the echo)?
Copy linkTweet thisAlerts:
@OctoberWindJan 23.2009 — First off, why are you nesting a <?php ?> tagset inside an existing <?php ?> tagset?

This should set the $insertGoTo variable:
[code=php]$insertGoTo = "/Index5.php?recordid=" . $row_test['id']; [/code]

However, this isn't a valid MySQL INSERT statement, just a varchar string (/Index5.php?recordid=" . $row_test['id']) set to a variable ($insertGoTo).
Copy linkTweet thisAlerts:
@krlsoftauthorJan 23.2009 — HI,

thanks for reply.


Actually what I am trying to do is open a page after I have inserted the mysql record with the record already loaded. I tried your suggestion and got the following error now:

[I][B]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1[/B][/I]
Copy linkTweet thisAlerts:
@NogDogJan 23.2009 — I suspect we will need to see more of the code and/or explanation so that we have some idea of what is going on, since the code you posted does not in and of itself do any database querying.
Copy linkTweet thisAlerts:
@krlsoftauthorJan 23.2009 — okay here it is:

<?php require_once('Connections/test.php'); ?>

<?php

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 bkmess (Title) VALUES (&#37;s)",


GetSQLValueString($_POST['textfield'], "text"));

mysql_select_db($database_test, $test);

$Result1 = mysql_query($insertSQL, $test) or die(mysql_error());

[B][COLOR="Red"]$insertGoTo= $insertGoTo = "/Index5.php?recordid=" .$row_test_results['id']; [/COLOR][/B]

if (isset($_SERVER['QUERY_STRING'])) {

$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

$insertGoTo .= $_
SERVER['QUERY_STRING'];

}

header(sprintf("Location: %s", $insertGoTo));

}

$colname_test_results = "1";

if (isset($_GET['recordid'])) {

$colname_test_results = (get_magic_quotes_gpc()) ? $_
GET['recordid'] : addslashes($_GET['recordid']);

}

mysql_select_db($database_test, $test);

$query_test_results = sprintf("SELECT * FROM bkmess WHERE id = '%s' ORDER BY id DESC", $colname_test_results);

$test_results = mysql_query($query_test_results, $test) or die(mysql_error());

$row_test_results = mysql_fetch_assoc($test_results);

$totalRows_test_results = mysql_num_rows($test_results);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Untitled Document</title>

<style type="text/css">

<!--

.style1 {font-family: "Agency FB"}

-->

</style>

</head>

<body>

<form action="<?php echo $editFormAction; ?>" method="POST" name="Insertform" id="Insertform">

<p>&nbsp;</p>

<h3 align="center">

<span class="style1">Title</span>:

<input name="textfield" type="text" size="70">


<input type="submit" name="Submit" value="Submit">

</h3>

<p>&nbsp;</p>

<input type="hidden" name="MM_insert" value="form1">

</form>

</body>

</html>

<?php

mysql_free_result($test_results);

?>
×

Success!

Help @krlsoft spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...