Page 1 of 1

My SQL

Posted: Sat Jul 30, 2011 8:57 am
by YoussefSiblini
Hi,
I am having some thing weird happening in my code, when I add <input type="file" name="file" id="file" /> inside my from the $sql = mysql_query("INSERT INTO exchanges (firstname, lastname, producttittle, productdescription, ExchangeWithTittle, ExchangeWithDescription, shippingfirstname, shippinglastname, address1, address2, city, country, postalcode, phonenumber, email, dateadded) VALUES ('$first_name','$last_name','$product_title','$product_description','$exchange_with_title','$exchange_with_description','$shipping_first_name','$shipping_last_name','$address1','$address2','$city','$country','$post_code','$phone_number','$email',now())"); stop working.

Here is the full code:

Code: Select all

<form action="addexchange2.php" method="POST" enctype='multipart/form-data'>
<div style="margin-bottom:40px; margin-top:30px"><b>About You and your Product:</b></div>
<div id="Fixed_Div"><span id="form_Span">First Name:</span> <input id="addexchange_FN" class="addexchange_text_box" type="text" name="firstname"></div>
<div id="Fixed_Div"><span id="form_Span">Last Name:</span> <input id="addexchange_LN" class="addexchange_text_box" type="text" name="lastname"></div>
<div id="Fixed_Div"><span id="form_Span">Product Title:</span> <input id="addexchange_PT" class="addexchange_text_box" type="text" name="producttittle" ></div>
<div id="Fixed_Div"><span id="form_Span">Product Description:</span> <textarea id="addexchange_PD" class="addexchange_text_area" name="productdescription"></textarea></div>
[b]<input type="file" name="file" id="file" />[/b]

<div style="margin-bottom:40px; margin-top:30px"><b>Please add the information about what product you expecting:</b></div>
<div id="Fixed_Div"><span id="form_Span">Exchange With Title:</span> <input id="addexchange_EWT" class="addexchange_text_box" type="text" name="ExchangeWithTittle"></div>
<div id="Fixed_Div"><span id="form_Span">Exchange with Description:</span> <textarea id="addexchange_EWD" class="addexchange_text_area" name="ExchangeWithDescription"></textarea></div>

<div style="margin-bottom:40px; margin-top:30px"><b>Your shipping details</b></div>
<div id="Fixed_Div"><span id="form_Span">First Name:</span> <input id="addexchange_SFN" class="addexchange_text_box" type="text" name="shippingfirstname"></div>
<div id="Fixed_Div"><span id="form_Span">Last Name:</span> <input id="addexchange_SLN" class="addexchange_text_box" type="text" name="shippinglastname"></div>
<div id="Fixed_Div"><span id="form_Span">Address Line 1:</span> <input id="addexchange_A1" class="addexchange_text_box" type="text" name="address1"></div>
<div id="Fixed_Div"><span id="form_Span">Address Line 2:</span> <input class="addexchange_text_box" type="text" name="address2" ></div>
<div id="Fixed_Div"><span id="form_Span">City:</span> <input id="addexchange_City" class="addexchange_text_box" type="text" name="city" ></div>
<div id="Fixed_Div"><span id="form_Span">Country:</span> <input id="addexchange_CTRY" class="addexchange_text_box" type="text" name="country" ></div>
<div id="Fixed_Div"><span id="form_Span">Post Code:</span> <input id="addexchange_PCODE" class="addexchange_text_box" type="text" name="postalcode" ></div>
<div id="Fixed_Div"><span id="form_Span">Phone Number:</span> <input id="addexchange_PNR" class="addexchange_text_box" type="text" name="phonenumber" ></div>
<div id="Fixed_Div"><span id="form_Span">Email:</span> <input id="addexchange_EMAIL" class="addexchange_text_box" type="text" name="email" ></div>

<span id="form_Span"></span> <input type="submit" id="Main_Search_Button" onclick="MM_validateForm('addexchange_FN','','R','addexchange_LN','','R','addexchange_PT','','R','addexchange_EWT','',
'R','addexchange_EWD','','R','addexchange_SFN','','R','addexchange_SLN','','R','addexchange_A1','','R','addexchange_City','',
'R','addexchange_CTRY','','R','addexchange_PCODE','','R','addexchange_PNR','','RisNum','addexchange_EMAIL','','RisEmail',
'addexchange_PD','','R');return document.MM_returnValue" value="Add Exchange">

</form>
addexchange2.php

Code: Select all

<?php

mysql_connect("localhost", "root", "");
mysql_select_db("exchanges");

$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$product_title = $_POST['producttittle'];
$product_description = $_POST['productdescription'];
$exchange_with_title = $_POST['ExchangeWithTittle'];
$exchange_with_description = $_POST['ExchangeWithDescription'];
$shipping_first_name = $_POST['shippingfirstname'];
$shipping_last_name = $_POST['shippinglastname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$country = $_POST['country'];
$post_code = $_POST['postalcode'];
$phone_number = $_POST['phonenumber'];
$email = $_POST['email'];

	// See if that product name is an identical match to another product in the system
	$check = mysql_query("SELECT id FROM exchanges WHERE email='$email' LIMIT 1");
	$productMatch = mysql_num_rows($check); // count the output amount
    if ($productMatch > 0) {
		echo '
		<div style="margin-top:100px; margin-bottom:10px"><strong>Sorry that email is already registered if you own that email then <a href="register/login.php">login</a>, or <a href="addexchange.php">try again</a></strong></div>
		<div style="margin-bottom:100px">If you forgot your password, please go to the <a href="register/login.php">login</a> page and click the forgot password link.</div>';
		
	}else{

$sql = mysql_query("INSERT INTO exchanges (firstname, lastname, producttittle, productdescription, ExchangeWithTittle, ExchangeWithDescription, shippingfirstname, shippinglastname, address1, address2, city, country, postalcode, phonenumber, email, dateadded) VALUES ('$first_name','$last_name','$product_title','$product_description','$exchange_with_title','$exchange_with_description','$shipping_first_name','$shipping_last_name','$address1','$address2','$city','$country','$post_code','$phone_number','$email',now())");

$pid = mysql_insert_id();

          if ($sql){ echo '<h3 style="margin-top:100px">Thank you ' . $first_name . ', Your exchange has been added successfuly, usually it does not take a long time tell you get your exchange, Goof luck</h3>
	<div style="margin-bottom:10px;">You can <a href="exchanges.php">view your exchange</a> if you want.</div>
	<div style="margin-bottom:10px;">You will get notified as soon as you get an exchange so please keep checking your emails and be sure that you added the right email.</div>
	<div style="margin-bottom:100px;">If you experiencing any problems please take a look at our FAQ page or contact us, usually we get back to you in a maximum time limit of 24 hours.</div>
	';}
	      else{echo 'Sorry Some thing went wrong, please let us know so we can sort it out for you';};


	}
	
	
?>
Youssef

Re: My SQL

Posted: Sat Jul 30, 2011 10:43 am
by social_experiment

Code: Select all

$sql = mysql_query("INSERT INTO exchanges (firstname, lastname, producttittle, productdescription, ExchangeWithTittle, ExchangeWithDescription, shippingfirstname, shippinglastname, address1, address2, city, country, postalcode, phonenumber, email, dateadded) VALUES ('$first_name','$last_name','$product_title','$product_description','$exchange_with_title','$exchange_with_description','$shipping_first_name','$shipping_last_name','$address1','$address2','$city','$country','$post_code','$phone_number','$email',now())") or die(mysql_error());
Using a function like mysql_error() is a lot more effective when looking for errors as opposed to custom error messages that only indicate that something went wrong but gives 0 information about the error.

Re: My SQL

Posted: Sat Jul 30, 2011 3:17 pm
by YoussefSiblini
Hi,
Thank you for your reply,
I just fixed it, Actually it was only easyphp bitching around, I restarted it and it is working fine now.
I am going to use mysql_error() function more from now, you are right, it make the life easier.


Youssef