PHP + mySQL insert into problems

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

murder2

New Member
Impact
1
Hi. I am writing a simple (or at least I thought so) form to register data which then adds this data to a table in my database.
The basic form looks like this:
Code:
<FORM name="Gig" method="post" action="addrowgig.php">
  DATE <select name="day">
    <option value="01">1<option value="02">2<option value="03">3<option value="04">4<option value="05">5
    <option value="06">6<option value="07">7<option value="08">8<option value="09">9<option value="10">10
    <option value="11">11<option value="12">12<option value="13">13<option value="14">14<option value="15">15
    <option value="16">16<option value="17">17<option value="18">18<option value="19">19<option value="20">20
    <option value="21">21<option value="22">22<option value="23">23<option value="24">24<option value="25">25
    <option value="26">26<option value="27">27<option value="28">28<option value="29">29<option value="30">30
    <option value="31">31</option></select>
  <select name="month">
    <option value="01">Jan<option value="02">Feb<option value="03">March
    <option value="04">April<option value="05">May<option value="06">June
    <option value="07">July<option value="08">August<option value="09">September
    <option value="10">October<option value="11">November<option value="01">December</option></select>
  <select name="year">
    <option value="2005">2005<option value="2006">2006</option></select>
  VENUE <input type="text" name="venue" size="10">
  LOCATION <input type="text" name="location" size="30">
  INFO <textarea name="info" cols="23" rows="5"></textarea>
  <input type="submit" value="Send">
</FORM>

addrowgig.php:
Code:
<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'username', 'password')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('secondshadow_ne') or die('Could not select database');

@extract($_POST);
$day = stripslashes($day);
$month = stripslashes($month);
$year = stripslashes($year);
$venue = stripslashes($venue);
$location = stripslashes($location);
$info = stripslashes($info);
$price = stripslashes($price);

$query = "INSERT INTO `web_gigs` (`gigDate`, `gigVenue`, `gigLocation`, `gigInfo`)
        VALUES ('$year-$month-$day', '$venue', '$location', '$info')";
mysql_query($query) or die('Query failed: ' . mysql_error());

mysql_close($link);
?>

What's funny is that I don't even get the echo-statement "Connected successfully" (and I know that the username/pw is correct, double-checked). It seems to be something else causing this. The row is not added either.

Another question I have, is the
Code:
VALUES ('$year-$month-$day')
Does this produce the correct mysql format for DATE "yyyy-mm-dd", og do I have to solve this different ?

Any thanks much appreciated!
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
fixed it.. don't know what actually did it, but removed the
Code:
name="Gigs"
from the form itself, and added
Code:
$result = mysql_query...
horray! :)
 
0
Close
hey sorry i just have a question for you..i m learning php too so can you tell me what this means

@extract($_POST);
$day = stripslashes($day);
$month = stripslashes($month);
$year = stripslashes($year);
................
 
0
Close
Extracts the data sent by the form:
Code:
@extract($_POST);
defines the variable day, from the extracted data:
Code:
$day = stripslashes($day);
defines the variable month, from the extracted data:
Code:
$month = stripslashes($month);
defines the variable year, from the extracted data:
Code:
$year = stripslashes($year);
and so on...

the names inside the stripslashes() is the same as the names from the inputs in the form:
Code:
<select name="day">
 
0
Close
Okay i know that but whats the 'stripslases' for
cant you just do it like this
$year = $_post['year']
...
 
0
Close
1
Close
Okay i got it now :D
Thanks..REP points added
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back