Jump to content

Single From to Insert and Update 2 tables


yandoo
Go to solution Solved by yandoo,

Recommended Posts

Hiya I'm trying to use a single form to insert a record into a table in my database but also update another record in a different table as well. Once this is done the user should be left on the same page. 

 

I keep getting an error "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1". 

 

Here's what I have so far: 

 

I'm not sure if this is even the correct way to perform this, if you could confirm that would be super? 

// Parse the form data and add inventory item to the system
if (isset($_POST['pid'])) {
	
	$pid = mysql_real_escape_string($_POST['pid']);
    $ip = mysql_real_escape_string($_POST['ip']);
	$rating = mysql_real_escape_string($_POST['rating']);
	
	// Add this product into the database now
	 
$res1 = mysql_query("INSERT INTO rating (media_id, ip) VALUES('$pid','$ip'")); 
$res2 = mysql_query("UPDATE media SET rating='$rating' WHERE media_id ='$pid'"); 
	header("location: books.php"); 
    exit();
}


<form action="books.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
 
<input type="hidden" name="pid" id="pid" value='.$id.' />
<input type="hidden" name="ip" id="ip" value='.$ipaddress.' />
<input type="hidden" name="rating" id="rating" value="'.$rating++.' "/>
<input type="submit" value="" name="button" id="button" class="button" /></form>

Thank you

 

 

Link to comment
Share on other sites

You should be checking the results of your queries after running each one to be sure it ran ok. YOu should also be checking that you have valid input. I think the message is telling you that you have an empty value and therefore your query is bad.

Link to comment
Share on other sites

Ok I've changed them to:

$res1 = "INSERT INTO rating (media_id, ip) VALUES($pid, $ip)";
$res1results = MySQL_query($res1);
if (!$res1results)
{
echo "Error occurred in my query - message is '".MySQL_error()."'";
exit();
}


 
$res2 = "UPDATE media SET rating='".$rating."' WHERE media_id ='".$pid."'"; 
$res2results = MySQL_query($res2);
if (!$res2results)
{
echo "Error occurred in my query - message is '".MySQL_error()."'";
exit();
} 

and get the error: Error occurred in my query - message is 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.227.158)' at line 1'. 

 

This error corresponds to the insert query. 

Link to comment
Share on other sites

Ok here's the full code incase it is something else in the code:

// Parse the form data and add inventory item to the system
if (isset($_POST['pid'])) {
	
	$pid = mysql_real_escape_string($_POST['pid']);
    $ip = mysql_real_escape_string($_POST['ip']);
	$rating = mysql_real_escape_string($_POST['rating']);
	
	echo $pid; echo '<br/>';
	echo $ip; echo '<br/>';
	echo $rating; echo '<br/>';
	
	// Add this product into the database now
	 
$res1 = mysql_query("INSERT INTO rating (media_id, ip) VALUES('".$pid."','".$ip."'")or die (mysql_error());

 
$res2 = mysql_query("UPDATE media SET rating='".$rating."' WHERE media_id ='".$pid."'")or die (mysql_error()); 

	header("location: books.php"); 
    exit();
}

$dynamicList = "";
$sql = mysql_query("SELECT * FROM media WHERE media_type = 'Book' ORDER BY media_title ASC");
$productCount = mysql_num_rows($sql); // count the output amount

//////////////////////////////////// Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////
$nr = $productCount; // Get total of Num rows from the database query
if (isset($_GET['pn'])) { // Get pn from URL vars if it is present
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new)
    //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated)
} else { // If the pn URL variable is not present force it to be value of page number 1
    $pn = 1;
} 
//This is where we set how many database items to show on each page 
$itemsPerPage = 1; 
// Get the value of the last page in the pagination result set
$lastPage = ceil($nr / $itemsPerPage);
// Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage
if ($pn < 1) { // If it is less than 1
    $pn = 1; // force if to be 1
} else if ($pn > $lastPage) { // if it is greater than $lastpage
    $pn = $lastPage; // force it to be $lastpage's value
} 
// This creates the numbers to click in between the next and back buttons
// This section is explained well in the video that accompanies this script
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a>  ';
} else if ($pn == $lastPage) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a>  ';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a>  ';
}
// This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; 


// Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax
// $sql2 is what we will use to fuel our while loop statement below
$sql2 = mysql_query("SELECT * FROM media WHERE media_type = 'Book' ORDER BY media_title ASC $limit"); 
//////////////////////////////// END Adam's Pagination Logic 

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////
$paginationDisplay = ""; // Initialize the pagination output variable
// This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastPage != "1"){
    // This shows the user what page they are on, and the total number of pages
    $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '   ';
    // If we are not on page 1 we can place the Back button
    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '   <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> ';
    } 
    // Lay in the clickable numbers display here between the Back and Next links
    $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
    // If we are not on the very last page we can place the Next button
    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '   <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> ';
    } 
}
///////////////////////////////////// END Adam's Pagination Display Setup /



$ipaddress = $_SERVER["REMOTE_ADDR"];



$sql4 = mysql_query("SELECT media.*, IF (ISNULL(rating.ip), 0, 1) AS HasRated
FROM media LEFT JOIN rating ON media.media_id = rating.media_id AND rating.ip = '".$ipaddress."'
WHERE media.media_type = 'Book' ORDER BY media_title ASC $limit");



if ($productCount > 0) {
	while($row = mysql_fetch_array($sql4)){ 
             $id = $row["media_id"];
			 $media_title = $row["media_title"];
			 $genre = $row["genre"];
			 $media_image = $row["media_image"];
			 $media_date = $row["media_date"];
			 $media_producer = $row["media_producer"];
			 $media_description = $row["media_description"];
			 $media_link = $row["media_link"];
			 $get_copy = $row["get_copy"];	 		 
			$media_id = $row["media_id"];
			$rating = $row['rating'];
			
			
						 
			if ($row['HasRated']== '0'){
			 
			 $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
        <tr>
		
		  <td width="83%" valign="top" colspan="2"><h2 class="PostTitle">' . $media_title . '</h2>
		   
		  <hr><br/>
		  </td></tr>
          <tr><td colspan="2" valign="top"><img style="border:#666 1px solid;" src="media/' . $media_image . '.jpg" alt="' . $media_title . '" border="1" class="alignLeft"/></a>
		 
		  <span class="MediaText"> <strong>Released:</strong> '. $media_date .' <br/>
		  	  <strong>Genre:</strong> '. $genre .' <br/>
		  	  <strong>Author:</strong> '. $media_producer .' <br/>
			  <strong>User Rated:</strong> '. $rating .' Votes <br/>
			  <strong>Description</strong><br/>'.$media_description.'</span>
		  </td></tr><tr><td colspan="2">
        
           
        </td></tr><tr><td width="13%">
		
		
		
            <form action="books.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">		   
        <input type="hidden" name="pid" id="pid" value='.$id.' />
		 <input type="hidden" name="ip" id="ip" value='.$ipaddress.' />
		 <input type="hidden" name="rating" id="rating" value="'.$rating++.' "/>
		 
		
		<span class="MediaText"><strong>Rate this Book</strong></span></td><td width="87%" align="left" valign="top">
		
		<input type="submit" value="" name="button" id="button" class="button" /></form>
		
		</td></tr><tr><td>
		<span class="MediaText"><strong>Get Your Copy:</strong></span></td><td> '.$get_copy.' </td>
		
      
        </tr><tr><td colspan="2"><br/><br/></td></tr>
      </table>';
	  
} else if ($row['HasRated']== '1'){ 

	 $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
        <tr>
		
		  <td width="83%" valign="top" colspan="2"><h2 class="PostTitle">' . $media_title . '</h2>
		   
		  <hr><br/>
		  </td></tr>
          <tr><td colspan="2" valign="top"><img style="border:#666 1px solid;" src="media/' . $media_image . '.jpg" alt="' . $media_title . '" border="1" class="alignLeft"/></a>
		 
		  <span class="MediaText"> <strong>Released:</strong> '. $media_date .' <br/>
		  	  <strong>Genre:</strong> '. $genre .' <br/>
		  	  <strong>Author:</strong> '. $media_producer .' <br/>
			  <strong>User Rated:</strong> '. $rating .' Votes <br/>
			  <strong>Description</strong><br/>'.$media_description.'</span>
		  </td></tr><tr><td colspan="2">
        
           
        </td></tr><tr><td width="13%">
		
		
		
            	 
		
		<span class="MediaText"><strong>Rate this Book</strong></span></td><td width="87%" align="left" valign="top">
		
		Already Rated
		
		</td></tr><tr><td>
		<span class="MediaText"><strong>Get Your Copy:</strong></span></td><td> '.$get_copy.' </td>
		
      
        </tr><tr><td colspan="2"><br/><br/></td></tr>
      </table>';
	  
	  

}}} else {
	$dynamicList = "We have no products listed in our store yet";
}
mysql_close();

Link to comment
Share on other sites

why did you remove the single-quotes from around the string data values (post #9)? that query is no longer what you had in post #1 in this thread and will fail every time since the string data is no longer being treated as strings, but as sql keywords and sql syntax.

 

edit: and the query in post #10 isn't the same as post #9. you need to post actual information if you want help with it.

Edited by mac_gyver
Link to comment
Share on other sites

I was just testing it momentarily and didn't put it back before I posted it here. Its back to: 

$res1 = mysql_query("INSERT INTO rating (media_id, ip) VALUES('$pid','$ip'")); 
$res2 = mysql_query("UPDATE media SET rating='$rating' WHERE media_id ='$pid'"); 

So just to confirm the full code with the single quotes back in is: 

<?php 
// Script Error Reporting
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
// Run a select query to get my letest 6 items
// Connect to the MySQL database  
include "storescripts/connect_to_mysql.php"; 

// Parse the form data and add inventory item to the system
if (isset($_POST['pid'])) {
	
	$pid = mysql_real_escape_string($_POST['pid']);
    $ip = mysql_real_escape_string($_POST['ip']);
	$rating = mysql_real_escape_string($_POST['rating']);
	
	echo $pid; echo '<br/>';
	echo $ip; echo '<br/>';
	echo $rating; echo '<br/>';
	
	// Add this product into the database now
	 
$res1 = mysql_query("INSERT INTO rating (media_id, ip) VALUES('$pid','$ip'")or die (mysql_error());

 
$res2 = mysql_query("UPDATE media SET rating='$rating' WHERE media_id ='$pid'")or die (mysql_error()); 

	header("location: books.php"); 
    exit();
}

$dynamicList = "";
$sql = mysql_query("SELECT * FROM media WHERE media_type = 'Book' ORDER BY media_title ASC");
$productCount = mysql_num_rows($sql); // count the output amount

//////////////////////////////////// Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////
$nr = $productCount; // Get total of Num rows from the database query
if (isset($_GET['pn'])) { // Get pn from URL vars if it is present
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new)
    //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated)
} else { // If the pn URL variable is not present force it to be value of page number 1
    $pn = 1;
} 
//This is where we set how many database items to show on each page 
$itemsPerPage = 1; 
// Get the value of the last page in the pagination result set
$lastPage = ceil($nr / $itemsPerPage);
// Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage
if ($pn < 1) { // If it is less than 1
    $pn = 1; // force if to be 1
} else if ($pn > $lastPage) { // if it is greater than $lastpage
    $pn = $lastPage; // force it to be $lastpage's value
} 
// This creates the numbers to click in between the next and back buttons
// This section is explained well in the video that accompanies this script
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a>  ';
} else if ($pn == $lastPage) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a>  ';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a>  ';
}
// This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; 


// Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax
// $sql2 is what we will use to fuel our while loop statement below
$sql2 = mysql_query("SELECT * FROM media WHERE media_type = 'Book' ORDER BY media_title ASC $limit"); 
//////////////////////////////// END Adam's Pagination Logic 

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////
$paginationDisplay = ""; // Initialize the pagination output variable
// This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastPage != "1"){
    // This shows the user what page they are on, and the total number of pages
    $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '   ';
    // If we are not on page 1 we can place the Back button
    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '   <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> ';
    } 
    // Lay in the clickable numbers display here between the Back and Next links
    $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
    // If we are not on the very last page we can place the Next button
    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '   <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> ';
    } 
}
///////////////////////////////////// END Adam's Pagination Display Setup /



$ipaddress = $_SERVER["REMOTE_ADDR"];



$sql4 = mysql_query("SELECT media.*, IF (ISNULL(rating.ip), 0, 1) AS HasRated
FROM media LEFT JOIN rating ON media.media_id = rating.media_id AND rating.ip = '".$ipaddress."'
WHERE media.media_type = 'Book' ORDER BY media_title ASC $limit");



if ($productCount > 0) {
	while($row = mysql_fetch_array($sql4)){ 
             $id = $row["media_id"];
			 $media_title = $row["media_title"];
			 $genre = $row["genre"];
			 $media_image = $row["media_image"];
			 $media_date = $row["media_date"];
			 $media_producer = $row["media_producer"];
			 $media_description = $row["media_description"];
			 $media_link = $row["media_link"];
			 $get_copy = $row["get_copy"];	 		 
			$media_id = $row["media_id"];
			$rating = $row['rating'];
			
			
						 
			if ($row['HasRated']== '0'){
			 
			 $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
        <tr>
		
		  <td width="83%" valign="top" colspan="2"><h2 class="PostTitle">' . $media_title . '</h2>
		   
		  <hr><br/>
		  </td></tr>
          <tr><td colspan="2" valign="top"><img style="border:#666 1px solid;" src="media/' . $media_image . '.jpg" alt="' . $media_title . '" border="1" class="alignLeft"/></a>
		 
		  <span class="MediaText"> <strong>Released:</strong> '. $media_date .' <br/>
		  	  <strong>Genre:</strong> '. $genre .' <br/>
		  	  <strong>Author:</strong> '. $media_producer .' <br/>
			  <strong>User Rated:</strong> '. $rating .' Votes <br/>
			  <strong>Description</strong><br/>'.$media_description.'</span>
		  </td></tr><tr><td colspan="2">
        
           
        </td></tr><tr><td width="13%">
		
		
		
            <form action="books.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">		   
        <input type="hidden" name="pid" id="pid" value='.$id.' />
		 <input type="hidden" name="ip" id="ip" value='.$ipaddress.' />
		 <input type="hidden" name="rating" id="rating" value="'.$rating++.' "/>
		 
		
		<span class="MediaText"><strong>Rate this Book</strong></span></td><td width="87%" align="left" valign="top">
		
		<input type="submit" value="" name="button" id="button" class="button" /></form>
		
		</td></tr><tr><td>
		<span class="MediaText"><strong>Get Your Copy:</strong></span></td><td> '.$get_copy.' </td>
		
      
        </tr><tr><td colspan="2"><br/><br/></td></tr>
      </table>';
	  
} else if ($row['HasRated']== '1'){ 

	 $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
        <tr>
		
		  <td width="83%" valign="top" colspan="2"><h2 class="PostTitle">' . $media_title . '</h2>
		   
		  <hr><br/>
		  </td></tr>
          <tr><td colspan="2" valign="top"><img style="border:#666 1px solid;" src="media/' . $media_image . '.jpg" alt="' . $media_title . '" border="1" class="alignLeft"/></a>
		 
		  <span class="MediaText"> <strong>Released:</strong> '. $media_date .' <br/>
		  	  <strong>Genre:</strong> '. $genre .' <br/>
		  	  <strong>Author:</strong> '. $media_producer .' <br/>
			  <strong>User Rated:</strong> '. $rating .' Votes <br/>
			  <strong>Description</strong><br/>'.$media_description.'</span>
		  </td></tr><tr><td colspan="2">
        
           
        </td></tr><tr><td width="13%">
		
		
		
            	 
		
		<span class="MediaText"><strong>Rate this Book</strong></span></td><td width="87%" align="left" valign="top">
		
		Already Rated
		
		</td></tr><tr><td>
		<span class="MediaText"><strong>Get Your Copy:</strong></span></td><td> '.$get_copy.' </td>
		
      
        </tr><tr><td colspan="2"><br/><br/></td></tr>
      </table>';
	  
	  

}}} else {
	$dynamicList = "We have no products listed in our store yet";
}
mysql_close();

Edited by yandoo
Link to comment
Share on other sites

Ok so I've added or die (mysql_error()); to every other query to see if any other errors come about but it still only comes up with the error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

 

The only other page or script that runs with this page is the include, which is just the connection to the database and works fine.

Edited by yandoo
Link to comment
Share on other sites

are you even reading what is being stated? the error you are listing is coming from someplace you already had a mysql_error() statement.

 

mindlessly adding more error checking logic (which you should have already had in your code every place you are running a query) won't help find the problem because wherever this is occurring at already had a mysql_error() statement on it.

 

if the code you have been posting is everything on the page, then the problem is in your include file.

Link to comment
Share on other sites

  • Solution

I fixed it, on closer inspection it was the INSERT query. 

 

I changed it from:

$res1 = mysql_query("INSERT INTO rating (media_id, ip) VALUES('$pid','$ip'")or die (mysql_error());

To:

$res1 = "INSERT INTO rating (media_id, ip) VALUES('$pid', '$ip')"; 
$result = mysql_query($res1);

Thank you for all your replies and sorry if I seemed noobie. 

 

Thanks again 

Link to comment
Share on other sites

your first code didn't show any mysql_error() logic. next you stated you added mysql_error() logic to the two queries and you didn't get any errors. then you posted code in post #9 that formed the query in a php variable, fixing your original sql syntax problem, but broke the quoting around the string values. then you thew that code away (ignoring what ginerjm posted about echoing the query so that you could see what might be wrong with it) and reverted back to the original sql syntax for posts #10 and #12.

 

your original INSERT query syntax is malformed, but because the sql syntax is buried within the php syntax to run the query, it's not easy to see. use the code in post #9, but with the single-quotes around the string data values.

 

edit: basically says what you discovered. you need to always form your queries in php variables (separates the sql syntax from the php syntax, lets you echo/log the actual query, and makes it easier to switch database libraries) and always check for query errors, always.

Edited by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.