Jump to content

error in my SQL syntax, help pls!


nevsi79

Recommended Posts

I inserted some data in mySQL table as follows:

 

$add_claim_details_sql = "INSERT INTO claim_details (ins_ref_no) VALUES ('$your_ref_no')";
$add_claim_details_res = mysql_query($add_claim_details_sql) or die ("Could not edit item details:" . mysql_error());

so far so good - it works, great stuff, but ... ???

 

I would like to give some feedback to the user, ie, I want to supply the user who's submitted the form with a ref. no.

 

The ref. no is the id from claim_details. (the id is set to be a primary key auto-increment).

 

so I was hoping to achieve this by writing the following script:

 

$query = "SELECT id FROM claim_details WHERE id=".$_GET['id'];
$result = mysql_query($query)or die("Could not get your ref. no.:" . mysql_error());
echo $result;

 

Obviously it does not work as I get the following error:

 

Could not get your ref. no.: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

 

I do not how to identify the id - which will be the reference number unique to the just submitted form.

 

I hope my question makes sense and someone will help.

 

Thanks!

 

 

Link to comment
Share on other sites

It didn't work guys as I don't get the ref. no (i.e. the id unique to the just submitted data), instead I get:

Resource id #4

 

Here is all my code:

$add_claim_details_sql = "INSERT INTO claim_details (ins_ref_no) VALUES ('$your_ref_no')";
$add_claim_details_res = mysql_query($add_claim_details_sql) or die ("Could not edit item details:" . mysql_error());
echo $add_claim_details_res;
echo "</br>";
echo "thank you, your form has been submitted and the your data was stored in our db";
echo "</br>";
$query = "SELECT id FROM claim_details WHERE id='".mysql_real_escape_string($_GET['id'])."'";
$result = mysql_query($query)or die("Could not get your ref. no.:" . mysql_error());
echo "your ref no is: $result";

 

When I run it, I get the following every time:

 

1

thank you, your form has been submitted and the your data was stored in our db

your ref no is:Resource id #4

 

Where 1 is what I have put in the form for ins_ref_no.

 

However the resource id is not the desired output, it should have been 34 (or whatever is- which is  id corresponding to the    data that have been inserted with the $add_claim_details_sql.

 

 

Link to comment
Share on other sites

thank you thorpe,

 

:-[ - as I said I am new to PHP :-[

 

so I added the following 2 lines to my script:

 

$row = mysql_fetch_array($result);
echo $row;

 

but it did not return the id, it returned nothing!

 

What am I doing wrong?

 

 

Link to comment
Share on other sites

thank you thorpe,

 

Embarrassed - as I said I am new to PHP Embarrassed

 

so I added the following 2 lines to my script:

 

Code:

 

$row = mysql_fetch_array($result);

echo $row;

 

 

but it did not return the id, it returned nothing!

 

What am I doing wrong?

 

Link to comment
Share on other sites

sorry I do not understand your question  :-[

 

This is all my code:

 

session_start();
include('conn.php');//Connection to databse
//Random Number

$rand = rand(1000, 2000);
$_SESSION['guid'] = $rand;
$guid = $_SESSION['guid'];
echo "SESSION ID is <b>".$guid."</b><br/><br/>";
$your_ref_no = htmlspecialchars($_POST['tfa_YourRefNo']);
//check to see if the form has been submitted
if(isset($_POST['tfa_submitAction'])){


//add to claim_details table

$add_claim_details_sql = "INSERT INTO claim_details (ins_ref_no) VALUES ('$your_ref_no')";
$add_claim_details_res = mysql_query($add_claim_details_sql) or die ("Could not edit item details:" . mysql_error());
echo $add_claim_details_res;
echo "</br>";
echo "thank you, your form has been submitted and the your data was stored in our db";
echo "</br>";
$query = "SELECT id FROM claim_details WHERE id='".mysql_real_escape_string($_GET['id'])."'";
$result = mysql_query($query)or die("Could not get your ref. no.:" . mysql_error());
//$row = mysql_fetch_array($result);
$num_rows = mysql_num_rows($result);
echo $num_rows;

 

My form is in another file called: testform.html

The testform.html has an action that equals the url to the above php page and the submit button of the testform.html has a name=''tfa_submitAction''.

 

 

 

 

Link to comment
Share on other sites

This is the form, but so far I have only output <h3>Claim Details</h3>.

Hopefully you will not be confused with the rest of it.

 

<!-- FORM: HEAD SECTION -->
<link href="http://app.formassembly.com/wForms/3.0/css/black/wforms.css" rel="stylesheet" type="text/css"></link>
<link href="http://app.formassembly.com/wForms/3.0/css/wforms-jsonly.css" rel="alternate stylesheet" title="This stylesheet activated by javascript" type="text/css"></link>
<link href="http://app.formassembly.com/wForms/3.0/css/wforms-layout.css" rel="stylesheet" type="text/css"></link>
<link href="file:///nevenaaleksieva/Desktop/testform.css" rel="stylesheet" type="text/css" />
<!--[if IE 7]>
<link href="http://app.formassembly.com/wForms/3.0/css/wforms-layout-ie7.css" rel="stylesheet" type="text/css"></link>
<![endif]-->
<script type="text/javascript" src="http://app.formassembly.com/wForms/3.0/js/wforms.js"></script>
<script type="text/javascript" src="http://app.formassembly.com/wForms/3.0/js/wforms_custom_validation.js"></script>
<script type="text/javascript" src="http://app.formassembly.com/js/populate_form.js"></script>

<!-- FORM: BODY SECTION -->
<div class="wForm">
<div class="codesection" id="code-"></div>
<form method="post" action="http://www.geeks-fix.co.uk/testform/output.php" id="id2489978" class="labelsAbove hintsTooltip" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10485760"><div class="wfPage " id="wfPgIndex-1">
<h3>Claim Details:</h3>
<div class="oneField">
<label for="tfa_YourRefNo" class="preField">Your Ref. No:<span class="reqMark">*</span></label>
<input type="text" id="tfa_YourRefNo" name="tfa_YourRefNo" value="" size="40" class="required"><br>
          <span class="errMsg" id="tfa_YourRefNo-E"></span>
</div>
</div>
<div class="wfPage " id="wfPgIndex-2">
<h3>Policy Holder Info</h3>
<fieldset id="tfa_FullName" class="">
<legend>Full Name</legend>
<div class="oneField">
<label for="tfa_Title" class="preField">Title</label>
          <input type="text" id="tfa_Title" name="tfa_Title" value="" size="8" class=""><br>
          <span class="errMsg" id="tfa_Title-E"></span>
</div>
<div class="oneField">
<label for="tfa_FirstName" class="preField">First Name</label>
          <input type="text" id="tfa_FirstName" name="tfa_FirstName" value="" size="50" class=""><br>
          <span class="errMsg" id="tfa_FirstName-E"></span>
</div>
<div class="oneField">
<label for="tfa_Initials" class="preField">Initials</label>
          <input type="text" id="tfa_Initials" name="tfa_Initials" value="" size="" class=""><br>
          <span class="errMsg" id="Initials-E"></span>
</div>
<div class="oneField">
<label for="tfa_FamilyName" class="preField">Family Name<span class="reqMark">*</span></label>
          <input type="text" id="tfa_FamilyName" name="tfa_FamilyName" value="" size="50" class="required">
          	<div class="field-hint-inactive" id="tfa_FamilyName-H">
          	<span>if there is more than one person on the policy, 
                    please separate the family names with comma.</span>
                    </div>
<br><span class="errMsg" id="tfa_FamilyName-E"></span>
</div>
</fieldset>
<fieldset id="tfa_Address" class="">
<legend>Address</legend>
<div class="oneField">
<label for="tfa_StreetAddress" class="preField">Street Address<span class="reqMark">*</span></label>
          <input type="text" id="tfa_StreetAddress" name="tfa_StreetAddress" value="" size="50" class="required"><br>			          <span class="errMsg" id="tfa_StreetAddress-E"></span>
</div>
<div class="oneField">
<label for="tfa_Addresscontinued" class="preField">Address continued</label>
          <input type="text" id="tfa_Addresscontinued" name="tfa_Addresscontinued" value="" size="50" class=""><br>			          <span class="errMsg" id="tfa_Addresscontinued-E"></span>
</div>
<div class="oneField">
<label for="tfa_City" class="preField">City</label>
          <input type="text" id="tfa_City" name="tfa_City" value="" size="" class=""><br>
          <span class="errMsg" id="tfa_City1-E"></span>
</div>
<div class="oneField">
<label for="tfa_Postcode" class="preField">Postcode<span class="reqMark">*</span></label>
          <input type="text" id="tfa_Postcode" name="tfa_Postcode" value="" size="8" class="required">
          <br><span class="errMsg" id="tfa_Postcode-E"></span>
</div>
</fieldset>
<fieldset id="tfa_Telephone" class="required">
<legend>Telephone:</legend>
<div class="oneField">
<label for="tfa_Home" class="preField">Home:</label>
          <input type="text" id="tfa_Home" name="tfa_Home" value="" size="40" class="validate-integer">
          <br><span class="errMsg" id="tfa_Home-E"></span>
</div>
<div class="oneField">
<label for="tfa_Mobile" class="preField">Mobile:</label>
          <input type="text" id="tfa_Mobile" name="tfa_Mobile" value="" size="40" class="validate-integer">
          <br><span class="errMsg" id="tfa_Mobile-E"></span>
</div>
<div class="oneField">
<label for="tfa_Work" class="preField">Work:</label>
          <input type="text" id="tfa_Work" name="tfa_Work" value="" size="40" class="validate-integer"><br>
          <span class="errMsg" id="tfa_Work-E"></span>
</div>
</fieldset>
<div class="oneField">
<label for="tfa_emailaddress" class="preField">email address</label>
<input type="text" id="tfa_emailaddress" name="tfa_emailaddress" value="" size="40" class="validate-email">		          <br>
<span class="errMsg" id="tfa_emailaddress-E"></span>
</div>
</div>
<div class="wfPage " id="wfPgIndex-3">
<h3>Item Claimed Details:</h3>
<fieldset id="tfa_Item" class="repeat">
<legend>Item </legend>
<div class="oneField">
<label for="tfa_ItemName" class="preField">Item Name<span class="reqMark">*</span></label>
          <input type="text" id="tfa_ItemName" name="tfa_ItemName" value="" size="40" class="required"><br>
          <span class="errMsg" id="tfa_ItemName-E"></span>
</div>
<div class="oneField">
<label for="tfa_ItemMake" class="preField">Item Make</label>
          <input type="text" id="tfa_ItemMake" name="tfa_ItemMake" value="" size="40" class="">
          <br><span class="errMsg" id="tfa_ItemMake-E"></span>
</div>
<div class="oneField">
<label for="tfa_ItemDetails" class="preField">Item Details</label>	
          <input type="text" id="tfa_ItemDetails" name="tfa_ItemDetails" value="" size="40" class=""><br>	
          <span class="errMsg" id="tfa_ItemDetails-E"></span>
</div>
<div class="oneField">
<label for="tfa_ItemPrice" class="preField">Item Price</label>
          <input type="text" id="tfa_ItemPrice" name="tfa_ItemPrice" value="" size="40" class=""><br>
          <span class="errMsg" id="tfa_ItemPrice-E"></span>
</div>
<span class="duplicateSpan"><a id="tfa_Item-wfDL" class="duplicateLink" href="#">add another item</a>				          </span>
</fieldset>
<div class="oneField">
<label for="tfa_Attachadditional" class="preField">Attach additional info</label>
          <input type="file" id="tfa_Attachadditional" name="tfa_Attachadditional" value="" size="40" class=""><br>		          <span class="errMsg" id="tfa_Attachadditional-E"></span>
</div>
</div>

<div class="actions">
<input type="submit" class="primaryAction" id="submit-" name="tfa_submitAction" value="SUBMIT">
<input type="button" class="secondaryAction" onclick="history.go(-1)" value="CANCEL">
<input type="hidden" value="12461" name="tfa_dbFormId" id="tfa_dbFormId">
<input type="hidden" value="" name="tfa_dbResponseId" id="tfa_dbResponseId">
<input type="hidden" value="f7d9626afc92956c65cb904d2a6abcb7" name="tfa_dbControl" id="tfa_dbControl">
</div>
</form>
</div>

 

 

 

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.